mirror of
https://github.com/usememos/memos.git
synced 2024-11-16 19:56:11 +08:00
9c18960f47
* skeleton of postgres skeleton * Adding Postgres specific db schema sql * user test passed * memo store test passed * tag is working * update user setting test done * activity test done * idp test passed * inbox test done * memo_organizer, UNTESTED * memo relation test passed * webhook test passed * system setting test passed * passed storage test * pass resource test * migration_history done * fix memo_relation_test * fixing server memo_relation test * passes memo relation server test * paess memo test * final manual testing done * final fixes * final fixes cleanup * sync schema * lint * lint * lint * lint * lint
32 lines
779 B
Go
32 lines
779 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/postgres"
|
|
"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)
|
|
case "postgres":
|
|
driver, err = postgres.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
|
|
}
|