mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 18:21:43 +03:00
30 lines
674 B
Go
30 lines
674 B
Go
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
|
|
|
|
switch profile.Driver {
|
|
case "sqlite":
|
|
driver, err = sqlite.NewDB(profile)
|
|
case "mysql":
|
|
driver, err = mysql.NewDB(profile)
|
|
default:
|
|
return nil, errors.New("unknown db driver")
|
|
}
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to create db driver")
|
|
}
|
|
return driver, nil
|
|
}
|