memos/store/db/db.go

30 lines
674 B
Go
Raw Normal View History

2023-10-05 18:11:29 +03:00
package db
import (
"github.com/pkg/errors"
"github.com/usememos/memos/server/profile"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store/db/mysql"
"github.com/usememos/memos/store/db/sqlite"
)
// NewDBDriver creates new db driver based on profile.
func NewDBDriver(profile *profile.Profile) (store.Driver, error) {
var driver store.Driver
var err error
2023-10-05 18:19:52 +03:00
2023-10-05 19:34:06 +03:00
switch profile.Driver {
case "sqlite":
2023-10-05 18:11:29 +03:00
driver, err = sqlite.NewDB(profile)
2023-10-05 19:34:06 +03:00
case "mysql":
driver, err = mysql.NewDB(profile)
default:
return nil, errors.New("unknown db driver")
2023-10-05 18:11:29 +03:00
}
if err != nil {
return nil, errors.Wrap(err, "failed to create db driver")
}
return driver, nil
}