Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: update package name
Stevena6ee61e96d74
diff --git a/cmd/memos.go b/cmd/memos.goindex c14386aef..a0b60cead 100644--- a/cmd/memos.go+++ b/cmd/memos.go@@ -16,8 +16,7 @@ import ("github.com/usememos/memos/server"_profile "github.com/usememos/memos/server/profile""github.com/usememos/memos/store"- "github.com/usememos/memos/store/mysql"- "github.com/usememos/memos/store/sqlite"+ "github.com/usememos/memos/store/db")const (@@ -45,31 +44,19 @@ var (Short: `An open-source, self-hosted memo hub with knowledge management and social networking.`,Run: func(_cmd *cobra.Command, _args []string) {ctx, cancel := context.WithCancel(context.Background())-- var err error- var driver store.Driver- switch profile.Driver {- case "sqlite":- driver, err = sqlite.NewDriver(profile)- case "mysql":- driver, err = mysql.NewDriver(profile)- default:- cancel()- log.Error("unknown db driver", zap.String("driver", profile.Driver))- return- }+ dbDriver, err := db.NewDBDriver(profile)if err != nil {cancel()log.Error("failed to create db driver", zap.Error(err))return}- if err := driver.Migrate(ctx); err != nil {+ if err := dbDriver.Migrate(ctx); err != nil {cancel()log.Error("failed to migrate db", zap.Error(err))return}- store := store.New(driver, profile)+ store := store.New(dbDriver, profile)s, err := server.NewServer(ctx, profile, store)if err != nil {cancel()diff --git a/cmd/mvrss.go b/cmd/mvrss.goindex b82eec5cf..402b42cb0 100644--- a/cmd/mvrss.go+++ b/cmd/mvrss.go@@ -9,7 +9,7 @@ import ("github.com/spf13/cobra""github.com/usememos/memos/store"- "github.com/usememos/memos/store/sqlite"+ "github.com/usememos/memos/store/db/sqlite")var (@@ -39,7 +39,7 @@ var (return}- driver, err := sqlite.NewDriver(profile)+ driver, err := sqlite.NewDB(profile)if err != nil {fmt.Printf("failed to create db driver, error: %+v\n", err)returndiff --git a/cmd/setup.go b/cmd/setup.goindex 3f32be787..fda4572d8 100644--- a/cmd/setup.go+++ b/cmd/setup.go@@ -11,7 +11,7 @@ import ("github.com/usememos/memos/common/util""github.com/usememos/memos/store"- "github.com/usememos/memos/store/sqlite"+ "github.com/usememos/memos/store/db/sqlite")var (@@ -36,7 +36,7 @@ var (return}- driver, err := sqlite.NewDriver(profile)+ driver, err := sqlite.NewDB(profile)if err != nil {fmt.Printf("failed to create db driver, error: %+v\n", err)returndiff --git a/store/db/db.go b/store/db/db.gonew file mode 100644index 000000000..bd6362735--- /dev/null+++ b/store/db/db.go@@ -0,0 +1,28 @@+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+}diff --git a/store/mysql/activity.go b/store/db/mysql/activity.gosimilarity index 83%rename from store/mysql/activity.gorename to store/db/mysql/activity.goindex 013de47f6..a02177ea0 100644--- a/store/mysql/activity.go+++ b/store/db/mysql/activity.go@@ -8,7 +8,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateActivity(ctx context.Context, create *store.Activity) (*store.Activity, error) {+func (d *DB) CreateActivity(ctx context.Context, create *store.Activity) (*store.Activity, error) {stmt := `INSERT INTO activity (creator_id,@@ -36,7 +36,7 @@ func (d *Driver) CreateActivity(ctx context.Context, create *store.Activity) (*sreturn d.FindActivity(ctx, id)}-func (d *Driver) FindActivity(ctx context.Context, id int64) (*store.Activity, error) {+func (d *DB) FindActivity(ctx context.Context, id int64) (*store.Activity, error) {var activity store.Activitystmt := `SELECTdiff --git a/store/mysql/idp.go b/store/db/mysql/idp.gosimilarity index 85%rename from store/mysql/idp.gorename to store/db/mysql/idp.goindex 1b8506daf..ee4dface5 100644--- a/store/mysql/idp.go+++ b/store/db/mysql/idp.go@@ -10,7 +10,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateIdentityProvider(ctx context.Context, create *store.IdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) CreateIdentityProvider(ctx context.Context, create *store.IdentityProvider) (*store.IdentityProvider, error) {var configBytes []byteif create.Type == store.IdentityProviderOAuth2Type {bytes, err := json.Marshal(create.Config.OAuth2Config)@@ -52,7 +52,7 @@ func (d *Driver) CreateIdentityProvider(ctx context.Context, create *store.Identreturn create, nil}-func (d *Driver) ListIdentityProviders(ctx context.Context, find *store.FindIdentityProvider) ([]*store.IdentityProvider, error) {+func (d *DB) ListIdentityProviders(ctx context.Context, find *store.FindIdentityProvider) ([]*store.IdentityProvider, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {where, args = append(where, "id = ?"), append(args, *v)@@ -109,7 +109,7 @@ func (d *Driver) ListIdentityProviders(ctx context.Context, find *store.FindIdenreturn identityProviders, nil}-func (d *Driver) GetIdentityProvider(ctx context.Context, find *store.FindIdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) GetIdentityProvider(ctx context.Context, find *store.FindIdentityProvider) (*store.IdentityProvider, error) {list, err := d.ListIdentityProviders(ctx, find)if err != nil {return nil, err@@ -122,7 +122,7 @@ func (d *Driver) GetIdentityProvider(ctx context.Context, find *store.FindIdentireturn identityProvider, nil}-func (d *Driver) UpdateIdentityProvider(ctx context.Context, update *store.UpdateIdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) UpdateIdentityProvider(ctx context.Context, update *store.UpdateIdentityProvider) (*store.IdentityProvider, error) {set, args := []string{}, []any{}if v := update.Name; v != nil {set, args = append(set, "name = ?"), append(args, *v)@@ -167,7 +167,7 @@ func (d *Driver) UpdateIdentityProvider(ctx context.Context, update *store.Updatreturn identityProvider, nil}-func (d *Driver) DeleteIdentityProvider(ctx context.Context, delete *store.DeleteIdentityProvider) error {+func (d *DB) DeleteIdentityProvider(ctx context.Context, delete *store.DeleteIdentityProvider) error {where, args := []string{"id = ?"}, []any{delete.ID}stmt := `DELETE FROM idp WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)diff --git a/store/mysql/memo.go b/store/db/mysql/memo.gosimilarity index 93%rename from store/mysql/memo.gorename to store/db/mysql/memo.goindex 06df3cb54..fa93c61f1 100644--- a/store/mysql/memo.go+++ b/store/db/mysql/memo.go@@ -12,7 +12,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, error) {+func (d *DB) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, error) {stmt := `INSERT INTO memo (creator_id,@@ -47,7 +47,7 @@ func (d *Driver) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memreturn memo, nil}-func (d *Driver) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo, error) {+func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -200,7 +200,7 @@ func (d *Driver) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.return list, nil}-func (d *Driver) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memo, error) {+func (d *DB) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memo, error) {list, err := d.ListMemos(ctx, find)if err != nil {return nil, err@@ -213,7 +213,7 @@ func (d *Driver) GetMemo(ctx context.Context, find *store.FindMemo) (*store.Memoreturn memo, nil}-func (d *Driver) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {+func (d *DB) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {set, args := []string{}, []any{}if v := update.CreatedTs; v != nil {set, args = append(set, "created_ts = FROM_UNIXTIME(?)"), append(args, *v)@@ -243,7 +243,7 @@ func (d *Driver) UpdateMemo(ctx context.Context, update *store.UpdateMemo) errorreturn nil}-func (d *Driver) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {+func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {where, args := []string{"id = ?"}, []any{delete.ID}stmt := `DELETE FROM memo WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)@@ -261,7 +261,7 @@ func (d *Driver) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) errorreturn nil}-func (d *Driver) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {+func (d *DB) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {args := make([]any, 0, len(memoIDs))list := make([]string, 0, len(memoIDs))for _, memoID := range memoIDs {diff --git a/store/mysql/memo_organizer.go b/store/db/mysql/memo_organizer.gosimilarity index 84%rename from store/mysql/memo_organizer.gorename to store/db/mysql/memo_organizer.goindex e3a765fe4..600b68285 100644--- a/store/mysql/memo_organizer.go+++ b/store/db/mysql/memo_organizer.go@@ -9,7 +9,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrganizer) (*store.MemoOrganizer, error) {+func (d *DB) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrganizer) (*store.MemoOrganizer, error) {stmt := `INSERT INTO memo_organizer (memo_id,@@ -26,7 +26,7 @@ func (d *Driver) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrgareturn upsert, nil}-func (d *Driver) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganizer) (*store.MemoOrganizer, error) {+func (d *DB) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganizer) (*store.MemoOrganizer, error) {where, args := []string{}, []any{}if find.MemoID != 0 {where = append(where, "memo_id = ?")@@ -65,7 +65,7 @@ func (d *Driver) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganreturn memoOrganizer, nil}-func (d *Driver) DeleteMemoOrganizer(ctx context.Context, delete *store.DeleteMemoOrganizer) error {+func (d *DB) DeleteMemoOrganizer(ctx context.Context, delete *store.DeleteMemoOrganizer) error {where, args := []string{}, []any{}if v := delete.MemoID; v != nil {where, args = append(where, "memo_id = ?"), append(args, *v)diff --git a/store/mysql/memo_relation.go b/store/db/mysql/memo_relation.gosimilarity index 87%rename from store/mysql/memo_relation.gorename to store/db/mysql/memo_relation.goindex 906616bca..861a95041 100644--- a/store/mysql/memo_relation.go+++ b/store/db/mysql/memo_relation.go@@ -8,7 +8,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation) (*store.MemoRelation, error) {+func (d *DB) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation) (*store.MemoRelation, error) {stmt := `INSERT INTO memo_relation (memo_id,@@ -39,7 +39,7 @@ func (d *Driver) UpsertMemoRelation(ctx context.Context, create *store.MemoRelatreturn &memoRelation, nil}-func (d *Driver) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation) ([]*store.MemoRelation, error) {+func (d *DB) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation) ([]*store.MemoRelation, error) {where, args := []string{"TRUE"}, []any{}if find.MemoID != nil {where, args = append(where, "memo_id = ?"), append(args, find.MemoID)@@ -83,7 +83,7 @@ func (d *Driver) ListMemoRelations(ctx context.Context, find *store.FindMemoRelareturn list, nil}-func (d *Driver) DeleteMemoRelation(ctx context.Context, delete *store.DeleteMemoRelation) error {+func (d *DB) DeleteMemoRelation(ctx context.Context, delete *store.DeleteMemoRelation) error {where, args := []string{"TRUE"}, []any{}if delete.MemoID != nil {where, args = append(where, "memo_id = ?"), append(args, delete.MemoID)diff --git a/store/mysql/migration/prod/LATEST__SCHEMA.sql b/store/db/mysql/migration/dev/LATEST__SCHEMA.sqlsimilarity index 98%rename from store/mysql/migration/prod/LATEST__SCHEMA.sqlrename to store/db/mysql/migration/dev/LATEST__SCHEMA.sqlindex c5bcd208e..0dd00e8df 100644--- a/store/mysql/migration/prod/LATEST__SCHEMA.sql+++ b/store/db/mysql/migration/dev/LATEST__SCHEMA.sql@@ -85,7 +85,7 @@ CREATE TABLE `resource` (`external_link` TEXT NOT NULL,`type` VARCHAR(255) NOT NULL DEFAULT '',`size` INT NOT NULL DEFAULT '0',- `INTernal_path` VARCHAR(255) NOT NULL DEFAULT '',+ `internal_path` VARCHAR(255) NOT NULL DEFAULT '',`memo_id` INT DEFAULT NULL);diff --git a/store/mysql/migration/dev/LATEST__SCHEMA.sql b/store/db/mysql/migration/prod/LATEST__SCHEMA.sqlsimilarity index 98%rename from store/mysql/migration/dev/LATEST__SCHEMA.sqlrename to store/db/mysql/migration/prod/LATEST__SCHEMA.sqlindex c5bcd208e..0dd00e8df 100644--- a/store/mysql/migration/dev/LATEST__SCHEMA.sql+++ b/store/db/mysql/migration/prod/LATEST__SCHEMA.sql@@ -85,7 +85,7 @@ CREATE TABLE `resource` (`external_link` TEXT NOT NULL,`type` VARCHAR(255) NOT NULL DEFAULT '',`size` INT NOT NULL DEFAULT '0',- `INTernal_path` VARCHAR(255) NOT NULL DEFAULT '',+ `internal_path` VARCHAR(255) NOT NULL DEFAULT '',`memo_id` INT DEFAULT NULL);diff --git a/store/mysql/migration_history.go b/store/db/mysql/migration_history.gosimilarity index 86%rename from store/mysql/migration_history.gorename to store/db/mysql/migration_history.goindex c9211845d..26bab86cc 100644--- a/store/mysql/migration_history.go+++ b/store/db/mysql/migration_history.go@@ -18,7 +18,7 @@ type MigrationHistoryFind struct {Version *string}-func (d *Driver) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {+func (d *DB) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Version; v != nil {@@ -57,7 +57,7 @@ func (d *Driver) FindMigrationHistoryList(ctx context.Context, find *MigrationHireturn list, nil}-func (d *Driver) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {+func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {stmt := `INSERT INTO migration_history (version) VALUES (?)ON DUPLICATE KEY UPDATE version = ?diff --git a/store/mysql/migrator.go b/store/db/mysql/migrator.gosimilarity index 93%rename from store/mysql/migrator.gorename to store/db/mysql/migrator.goindex 6524c6214..f947ea981 100644--- a/store/mysql/migrator.go+++ b/store/db/mysql/migrator.go@@ -21,7 +21,7 @@ const (//go:embed migrationvar migrationFS embed.FS-func (d *Driver) Migrate(ctx context.Context) error {+func (d *DB) Migrate(ctx context.Context) error {if d.profile.IsDev() {return d.nonProdMigrate(ctx)}@@ -29,7 +29,7 @@ func (d *Driver) Migrate(ctx context.Context) error {return d.prodMigrate(ctx)}-func (d *Driver) nonProdMigrate(ctx context.Context) error {+func (d *DB) nonProdMigrate(ctx context.Context) error {buf, err := migrationFS.ReadFile("migration/dev/" + latestSchemaFileName)if err != nil {return errors.Errorf("failed to read latest schema file: %s", err)@@ -49,7 +49,7 @@ func (d *Driver) nonProdMigrate(ctx context.Context) error {return nil}-func (d *Driver) prodMigrate(ctx context.Context) error {+func (d *DB) prodMigrate(ctx context.Context) error {currentVersion := version.GetCurrentVersion(d.profile.Mode)migrationHistoryList, err := d.FindMigrationHistoryList(ctx, &MigrationHistoryFind{})// If there is no migration history, we should apply the latest schema.@@ -95,7 +95,7 @@ func (d *Driver) prodMigrate(ctx context.Context) error {return nil}-func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersion string) error {+func (d *DB) applyMigrationForMinorVersion(ctx context.Context, minorVersion string) error {filenames, err := fs.Glob(migrationFS, fmt.Sprintf("migration/prod/%s/*.sql", minorVersion))if err != nil {return errors.Wrap(err, "failed to read ddl files")@@ -130,7 +130,7 @@ func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersion//go:embed seedvar seedFS embed.FS-func (d *Driver) seed(ctx context.Context) error {+func (d *DB) seed(ctx context.Context) error {filenames, err := fs.Glob(seedFS, "seed/*.sql")if err != nil {return errors.Wrap(err, "failed to read seed files")diff --git a/store/mysql/mysql.go b/store/db/mysql/mysql.gosimilarity index 79%rename from store/mysql/mysql.gorename to store/db/mysql/mysql.goindex e9791bd07..f4d015ad8 100644--- a/store/mysql/mysql.go+++ b/store/db/mysql/mysql.go@@ -11,12 +11,12 @@ import ("github.com/usememos/memos/store")-type Driver struct {+type DB struct {db *sql.DBprofile *profile.Profile}-func NewDriver(profile *profile.Profile) (store.Driver, error) {+func NewDB(profile *profile.Profile) (store.Driver, error) {// Open MySQL connection with parameter.// multiStatements=true is required for migration.// See more in: https://github.com/go-sql-driver/mysql#multistatements@@ -25,15 +25,15 @@ func NewDriver(profile *profile.Profile) (store.Driver, error) {return nil, errors.Wrapf(err, "failed to open db: %s", profile.DSN)}- driver := Driver{db: db, profile: profile}+ driver := DB{db: db, profile: profile}return &driver, nil}-func (d *Driver) GetDB() *sql.DB {+func (d *DB) GetDB() *sql.DB {return d.db}-func (d *Driver) Vacuum(ctx context.Context) error {+func (d *DB) Vacuum(ctx context.Context) error {tx, err := d.db.BeginTx(ctx, nil)if err != nil {return err@@ -63,10 +63,10 @@ func (d *Driver) Vacuum(ctx context.Context) error {return tx.Commit()}-func (*Driver) BackupTo(context.Context, string) error {+func (*DB) BackupTo(context.Context, string) error {return errors.New("Please use mysqldump to backup")}-func (d *Driver) Close() error {+func (d *DB) Close() error {return d.db.Close()}diff --git a/store/mysql/resource.go b/store/db/mysql/resource.gosimilarity index 84%rename from store/mysql/resource.gorename to store/db/mysql/resource.goindex cc21f41b9..4a1fc2246 100644--- a/store/mysql/resource.go+++ b/store/db/mysql/resource.go@@ -11,19 +11,8 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateResource(ctx context.Context, create *store.Resource) (*store.Resource, error) {- stmt := `- INSERT INTO resource (- filename,- resource.blob,- external_link,- type,- size,- creator_id,- internal_path- )- VALUES (?, ?, ?, ?, ?, ?, ?)- `+func (d *DB) CreateResource(ctx context.Context, create *store.Resource) (*store.Resource, error) {+ stmt := "INSERT INTO resource (`filename`, `blob`, `external_link`, `type`, `size`, `creator_id`, `internal_path`) VALUES (?, ?, ?, ?, ?, ?, ?)"result, err := d.db.ExecContext(ctx,stmt,@@ -56,7 +45,7 @@ func (d *Driver) CreateResource(ctx context.Context, create *store.Resource) (*sreturn list[0], nil}-func (d *Driver) ListResources(ctx context.Context, find *store.FindResource) ([]*store.Resource, error) {+func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*store.Resource, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -77,7 +66,7 @@ func (d *Driver) ListResources(ctx context.Context, find *store.FindResource) ([fields := []string{"id", "filename", "external_link", "type", "size", "creator_id", "UNIX_TIMESTAMP(created_ts)", "UNIX_TIMESTAMP(updated_ts)", "internal_path", "memo_id"}if find.GetBlob {- fields = append(fields, "resource.blob")+ fields = append(fields, "blob")}query := fmt.Sprintf(`@@ -136,7 +125,7 @@ func (d *Driver) ListResources(ctx context.Context, find *store.FindResource) ([return list, nil}-func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResource) (*store.Resource, error) {+func (d *DB) UpdateResource(ctx context.Context, update *store.UpdateResource) (*store.Resource, error) {set, args := []string{}, []any{}if v := update.UpdatedTs; v != nil {@@ -151,11 +140,8 @@ func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResourcif v := update.MemoID; v != nil {set, args = append(set, "memo_id = ?"), append(args, *v)}- if update.UnbindMemo {- set = append(set, "memo_id = NULL")- }if v := update.Blob; v != nil {- set, args = append(set, "resource.blob = ?"), append(args, v)+ set, args = append(set, "blob = ?"), append(args, v)}args = append(args, update.ID)@@ -179,7 +165,7 @@ func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResourcreturn list[0], nil}-func (d *Driver) DeleteResource(ctx context.Context, delete *store.DeleteResource) error {+func (d *DB) DeleteResource(ctx context.Context, delete *store.DeleteResource) error {stmt := `DELETE FROM resource WHERE id = ?`result, err := d.db.ExecContext(ctx, stmt, delete.ID)if err != nil {diff --git a/store/mysql/seed/10000__reset.sql b/store/db/mysql/seed/10000__reset.sqlsimilarity index 100%rename from store/mysql/seed/10000__reset.sqlrename to store/db/mysql/seed/10000__reset.sqldiff --git a/store/mysql/seed/10001__user.sql b/store/db/mysql/seed/10001__user.sqlsimilarity index 100%rename from store/mysql/seed/10001__user.sqlrename to store/db/mysql/seed/10001__user.sqldiff --git a/store/mysql/seed/10002__memo.sql b/store/db/mysql/seed/10002__memo.sqlsimilarity index 100%rename from store/mysql/seed/10002__memo.sqlrename to store/db/mysql/seed/10002__memo.sqldiff --git a/store/mysql/seed/10003__memo_organizer.sql b/store/db/mysql/seed/10003__memo_organizer.sqlsimilarity index 100%rename from store/mysql/seed/10003__memo_organizer.sqlrename to store/db/mysql/seed/10003__memo_organizer.sqldiff --git a/store/mysql/seed/10004__tag.sql b/store/db/mysql/seed/10004__tag.sqlsimilarity index 100%rename from store/mysql/seed/10004__tag.sqlrename to store/db/mysql/seed/10004__tag.sqldiff --git a/store/mysql/storage.go b/store/db/mysql/storage.gosimilarity index 81%rename from store/mysql/storage.gorename to store/db/mysql/storage.goindex 3d47943b7..16246d2b0 100644--- a/store/mysql/storage.go+++ b/store/db/mysql/storage.go@@ -7,7 +7,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {+func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {stmt := `INSERT INTO storage (name,@@ -30,7 +30,7 @@ func (d *Driver) CreateStorage(ctx context.Context, create *store.Storage) (*storeturn create, nil}-func (d *Driver) ListStorages(ctx context.Context, find *store.FindStorage) ([]*store.Storage, error) {+func (d *DB) ListStorages(ctx context.Context, find *store.FindStorage) ([]*store.Storage, error) {where, args := []string{"1 = 1"}, []any{}if find.ID != nil {where, args = append(where, "id = ?"), append(args, *find.ID)@@ -73,7 +73,7 @@ func (d *Driver) ListStorages(ctx context.Context, find *store.FindStorage) ([]*return list, nil}-func (d *Driver) GetStorage(ctx context.Context, find *store.FindStorage) (*store.Storage, error) {+func (d *DB) GetStorage(ctx context.Context, find *store.FindStorage) (*store.Storage, error) {list, err := d.ListStorages(ctx, find)if err != nil {return nil, err@@ -85,7 +85,7 @@ func (d *Driver) GetStorage(ctx context.Context, find *store.FindStorage) (*storreturn list[0], nil}-func (d *Driver) UpdateStorage(ctx context.Context, update *store.UpdateStorage) (*store.Storage, error) {+func (d *DB) UpdateStorage(ctx context.Context, update *store.UpdateStorage) (*store.Storage, error) {set, args := []string{}, []any{}if update.Name != nil {set = append(set, "name = ?")@@ -121,7 +121,7 @@ func (d *Driver) UpdateStorage(ctx context.Context, update *store.UpdateStorage)return storage, nil}-func (d *Driver) DeleteStorage(ctx context.Context, delete *store.DeleteStorage) error {+func (d *DB) DeleteStorage(ctx context.Context, delete *store.DeleteStorage) error {stmt := `DELETE FROM storageWHERE id = ?diff --git a/store/mysql/system_setting.go b/store/db/mysql/system_setting.gosimilarity index 83%rename from store/mysql/system_setting.gorename to store/db/mysql/system_setting.goindex 6f683ce32..6492c9cd1 100644--- a/store/mysql/system_setting.go+++ b/store/db/mysql/system_setting.go@@ -7,7 +7,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSetting) (*store.SystemSetting, error) {+func (d *DB) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSetting) (*store.SystemSetting, error) {stmt := `INSERT INTO system_setting (name, value, description@@ -31,7 +31,7 @@ func (d *Driver) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSereturn upsert, nil}-func (d *Driver) ListSystemSettings(ctx context.Context, find *store.FindSystemSetting) ([]*store.SystemSetting, error) {+func (d *DB) ListSystemSettings(ctx context.Context, find *store.FindSystemSetting) ([]*store.SystemSetting, error) {where, args := []string{"1 = 1"}, []any{}if find.Name != "" {where, args = append(where, "name = ?"), append(args, find.Name)diff --git a/store/mysql/tag.go b/store/db/mysql/tag.gosimilarity index 85%rename from store/mysql/tag.gorename to store/db/mysql/tag.goindex 7ca95c041..ce9096c61 100644--- a/store/mysql/tag.go+++ b/store/db/mysql/tag.go@@ -8,7 +8,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, error) {+func (d *DB) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, error) {stmt := `INSERT INTO tag (name, creator_id)VALUES (?, ?)@@ -21,7 +21,7 @@ func (d *Driver) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag,return upsert, nil}-func (d *Driver) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) {+func (d *DB) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) {where, args := []string{"creator_id = ?"}, []any{find.CreatorID}query := `SELECT@@ -57,7 +57,7 @@ func (d *Driver) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tareturn list, nil}-func (d *Driver) DeleteTag(ctx context.Context, delete *store.DeleteTag) error {+func (d *DB) DeleteTag(ctx context.Context, delete *store.DeleteTag) error {where, args := []string{"name = ?", "creator_id = ?"}, []any{delete.Name, delete.CreatorID}stmt := `DELETE FROM tag WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)diff --git a/store/mysql/user.go b/store/db/mysql/user.gosimilarity index 91%rename from store/mysql/user.gorename to store/db/mysql/user.goindex b5e2277d5..e63478e77 100644--- a/store/mysql/user.go+++ b/store/db/mysql/user.go@@ -9,7 +9,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateUser(ctx context.Context, create *store.User) (*store.User, error) {+func (d *DB) CreateUser(ctx context.Context, create *store.User) (*store.User, error) {stmt := `INSERT INTO user (username,@@ -50,7 +50,7 @@ func (d *Driver) CreateUser(ctx context.Context, create *store.User) (*store.Usereturn list[0], nil}-func (d *Driver) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.User, error) {+func (d *DB) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.User, error) {set, args := []string{}, []any{}if v := update.UpdatedTs; v != nil {set, args = append(set, "updated_ts = ?"), append(args, *v)@@ -117,7 +117,7 @@ func (d *Driver) UpdateUser(ctx context.Context, update *store.UpdateUser) (*storeturn user, nil}-func (d *Driver) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User, error) {+func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -185,7 +185,7 @@ func (d *Driver) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.return list, nil}-func (d *Driver) DeleteUser(ctx context.Context, delete *store.DeleteUser) error {+func (d *DB) DeleteUser(ctx context.Context, delete *store.DeleteUser) error {result, err := d.db.ExecContext(ctx, `DELETE FROM user WHERE id = ?`, delete.ID)diff --git a/store/mysql/user_setting.go b/store/db/mysql/user_setting.gosimilarity index 85%rename from store/mysql/user_setting.gorename to store/db/mysql/user_setting.goindex 7de503f40..203673cdb 100644--- a/store/mysql/user_setting.go+++ b/store/db/mysql/user_setting.go@@ -12,12 +12,8 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertUserSetting(ctx context.Context, upsert *store.UserSetting) (*store.UserSetting, error) {- stmt := `- INSERT INTO user_setting (user_id,user_setting.key,value)- VALUES (?, ?, ?)- ON DUPLICATE KEY UPDATE value = ?- `+func (d *DB) UpsertUserSetting(ctx context.Context, upsert *store.UserSetting) (*store.UserSetting, error) {+ stmt := "INSERT INTO user_setting (`user_id`, `key`, `value`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?"if _, err := d.db.ExecContext(ctx, stmt, upsert.UserID, upsert.Key, upsert.Value, upsert.Value); err != nil {return nil, err}@@ -25,7 +21,7 @@ func (d *Driver) UpsertUserSetting(ctx context.Context, upsert *store.UserSettinreturn upsert, nil}-func (d *Driver) ListUserSettings(ctx context.Context, find *store.FindUserSetting) ([]*store.UserSetting, error) {+func (d *DB) ListUserSettings(ctx context.Context, find *store.FindUserSetting) ([]*store.UserSetting, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Key; v != "" {@@ -68,7 +64,7 @@ func (d *Driver) ListUserSettings(ctx context.Context, find *store.FindUserSettireturn userSettingList, nil}-func (d *Driver) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) {+func (d *DB) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) {stmt := `INSERT INTO user_setting (user_id, user_setting.key, value)VALUES (?, ?, ?)@@ -92,7 +88,7 @@ func (d *Driver) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSereturn upsert, nil}-func (d *Driver) ListUserSettingsV1(ctx context.Context, find *store.FindUserSettingV1) ([]*storepb.UserSetting, error) {+func (d *DB) ListUserSettingsV1(ctx context.Context, find *store.FindUserSettingV1) ([]*storepb.UserSetting, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Key; v != storepb.UserSettingKey_USER_SETTING_KEY_UNSPECIFIED {diff --git a/store/sqlite/activity.go b/store/db/sqlite/activity.gosimilarity index 80%rename from store/sqlite/activity.gorename to store/db/sqlite/activity.goindex 977927390..7f0306812 100644--- a/store/sqlite/activity.go+++ b/store/db/sqlite/activity.go@@ -6,7 +6,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateActivity(ctx context.Context, create *store.Activity) (*store.Activity, error) {+func (d *DB) CreateActivity(ctx context.Context, create *store.Activity) (*store.Activity, error) {stmt := `INSERT INTO activity (creator_id,diff --git a/store/sqlite/idp.go b/store/db/sqlite/idp.gosimilarity index 87%rename from store/sqlite/idp.gorename to store/db/sqlite/idp.goindex 31d487682..8d67d1127 100644--- a/store/sqlite/idp.go+++ b/store/db/sqlite/idp.go@@ -11,7 +11,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateIdentityProvider(ctx context.Context, create *store.IdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) CreateIdentityProvider(ctx context.Context, create *store.IdentityProvider) (*store.IdentityProvider, error) {var configBytes []byteif create.Type == store.IdentityProviderOAuth2Type {bytes, err := json.Marshal(create.Config.OAuth2Config)@@ -50,7 +50,7 @@ func (d *Driver) CreateIdentityProvider(ctx context.Context, create *store.Identreturn identityProvider, nil}-func (d *Driver) ListIdentityProviders(ctx context.Context, find *store.FindIdentityProvider) ([]*store.IdentityProvider, error) {+func (d *DB) ListIdentityProviders(ctx context.Context, find *store.FindIdentityProvider) ([]*store.IdentityProvider, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)@@ -107,7 +107,7 @@ func (d *Driver) ListIdentityProviders(ctx context.Context, find *store.FindIdenreturn identityProviders, nil}-func (d *Driver) GetIdentityProvider(ctx context.Context, find *store.FindIdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) GetIdentityProvider(ctx context.Context, find *store.FindIdentityProvider) (*store.IdentityProvider, error) {list, err := d.ListIdentityProviders(ctx, find)if err != nil {return nil, err@@ -120,7 +120,7 @@ func (d *Driver) GetIdentityProvider(ctx context.Context, find *store.FindIdentireturn identityProvider, nil}-func (d *Driver) UpdateIdentityProvider(ctx context.Context, update *store.UpdateIdentityProvider) (*store.IdentityProvider, error) {+func (d *DB) UpdateIdentityProvider(ctx context.Context, update *store.UpdateIdentityProvider) (*store.IdentityProvider, error) {set, args := []string{}, []any{}if v := update.Name; v != nil {set, args = append(set, "name = ?"), append(args, *v)@@ -176,7 +176,7 @@ func (d *Driver) UpdateIdentityProvider(ctx context.Context, update *store.Updatreturn &identityProvider, nil}-func (d *Driver) DeleteIdentityProvider(ctx context.Context, delete *store.DeleteIdentityProvider) error {+func (d *DB) DeleteIdentityProvider(ctx context.Context, delete *store.DeleteIdentityProvider) error {where, args := []string{"id = ?"}, []any{delete.ID}stmt := `DELETE FROM idp WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)diff --git a/store/sqlite/memo.go b/store/db/sqlite/memo.gosimilarity index 93%rename from store/sqlite/memo.gorename to store/db/sqlite/memo.goindex 788d8b93f..a864a22cf 100644--- a/store/sqlite/memo.go+++ b/store/db/sqlite/memo.go@@ -13,7 +13,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, error) {+func (d *DB) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, error) {if create.CreatedTs == 0 {create.CreatedTs = time.Now().Unix()}@@ -47,7 +47,7 @@ func (d *Driver) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memreturn create, nil}-func (d *Driver) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo, error) {+func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -200,7 +200,7 @@ func (d *Driver) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.return list, nil}-func (d *Driver) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {+func (d *DB) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {set, args := []string{}, []any{}if v := update.CreatedTs; v != nil {set, args = append(set, "created_ts = ?"), append(args, *v)@@ -230,7 +230,7 @@ func (d *Driver) UpdateMemo(ctx context.Context, update *store.UpdateMemo) errorreturn nil}-func (d *Driver) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {+func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {where, args := []string{"id = ?"}, []any{delete.ID}stmt := `DELETE FROM memo WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)@@ -248,7 +248,7 @@ func (d *Driver) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) errorreturn nil}-func (d *Driver) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {+func (d *DB) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {args := make([]any, 0, len(memoIDs))list := make([]string, 0, len(memoIDs))for _, memoID := range memoIDs {diff --git a/store/sqlite/memo_organizer.go b/store/db/sqlite/memo_organizer.gosimilarity index 84%rename from store/sqlite/memo_organizer.gorename to store/db/sqlite/memo_organizer.goindex 245e88a59..7aa2bc7b0 100644--- a/store/sqlite/memo_organizer.go+++ b/store/db/sqlite/memo_organizer.go@@ -9,7 +9,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrganizer) (*store.MemoOrganizer, error) {+func (d *DB) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrganizer) (*store.MemoOrganizer, error) {stmt := `INSERT INTO memo_organizer (memo_id,@@ -28,7 +28,7 @@ func (d *Driver) UpsertMemoOrganizer(ctx context.Context, upsert *store.MemoOrgareturn upsert, nil}-func (d *Driver) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganizer) (*store.MemoOrganizer, error) {+func (d *DB) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganizer) (*store.MemoOrganizer, error) {where, args := []string{}, []any{}if find.MemoID != 0 {where = append(where, "memo_id = ?")@@ -67,7 +67,7 @@ func (d *Driver) GetMemoOrganizer(ctx context.Context, find *store.FindMemoOrganreturn memoOrganizer, nil}-func (d *Driver) DeleteMemoOrganizer(ctx context.Context, delete *store.DeleteMemoOrganizer) error {+func (d *DB) DeleteMemoOrganizer(ctx context.Context, delete *store.DeleteMemoOrganizer) error {where, args := []string{}, []any{}if v := delete.MemoID; v != nil {where, args = append(where, "memo_id = ?"), append(args, *v)diff --git a/store/sqlite/memo_relation.go b/store/db/sqlite/memo_relation.gosimilarity index 88%rename from store/sqlite/memo_relation.gorename to store/db/sqlite/memo_relation.goindex c0fcdd2e2..50bf25ca3 100644--- a/store/sqlite/memo_relation.go+++ b/store/db/sqlite/memo_relation.go@@ -8,7 +8,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation) (*store.MemoRelation, error) {+func (d *DB) UpsertMemoRelation(ctx context.Context, create *store.MemoRelation) (*store.MemoRelation, error) {stmt := `INSERT INTO memo_relation (memo_id,@@ -38,7 +38,7 @@ func (d *Driver) UpsertMemoRelation(ctx context.Context, create *store.MemoRelatreturn memoRelation, nil}-func (d *Driver) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation) ([]*store.MemoRelation, error) {+func (d *DB) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation) ([]*store.MemoRelation, error) {where, args := []string{"TRUE"}, []any{}if find.MemoID != nil {where, args = append(where, "memo_id = ?"), append(args, find.MemoID)@@ -82,7 +82,7 @@ func (d *Driver) ListMemoRelations(ctx context.Context, find *store.FindMemoRelareturn list, nil}-func (d *Driver) DeleteMemoRelation(ctx context.Context, delete *store.DeleteMemoRelation) error {+func (d *DB) DeleteMemoRelation(ctx context.Context, delete *store.DeleteMemoRelation) error {where, args := []string{"TRUE"}, []any{}if delete.MemoID != nil {where, args = append(where, "memo_id = ?"), append(args, delete.MemoID)diff --git a/store/sqlite/migration/dev/LATEST__SCHEMA.sql b/store/db/sqlite/migration/dev/LATEST__SCHEMA.sqlsimilarity index 100%rename from store/sqlite/migration/dev/LATEST__SCHEMA.sqlrename to store/db/sqlite/migration/dev/LATEST__SCHEMA.sqldiff --git a/store/sqlite/migration/prod/0.10/00__activity.sql b/store/db/sqlite/migration/prod/0.10/00__activity.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.10/00__activity.sqlrename to store/db/sqlite/migration/prod/0.10/00__activity.sqldiff --git a/store/sqlite/migration/prod/0.11/00__user_avatar.sql b/store/db/sqlite/migration/prod/0.11/00__user_avatar.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.11/00__user_avatar.sqlrename to store/db/sqlite/migration/prod/0.11/00__user_avatar.sqldiff --git a/store/sqlite/migration/prod/0.11/01__idp.sql b/store/db/sqlite/migration/prod/0.11/01__idp.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.11/01__idp.sqlrename to store/db/sqlite/migration/prod/0.11/01__idp.sqldiff --git a/store/sqlite/migration/prod/0.11/02__storage.sql b/store/db/sqlite/migration/prod/0.11/02__storage.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.11/02__storage.sqlrename to store/db/sqlite/migration/prod/0.11/02__storage.sqldiff --git a/store/sqlite/migration/prod/0.12/00__user_setting.sql b/store/db/sqlite/migration/prod/0.12/00__user_setting.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.12/00__user_setting.sqlrename to store/db/sqlite/migration/prod/0.12/00__user_setting.sqldiff --git a/store/sqlite/migration/prod/0.12/01__system_setting.sql b/store/db/sqlite/migration/prod/0.12/01__system_setting.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.12/01__system_setting.sqlrename to store/db/sqlite/migration/prod/0.12/01__system_setting.sqldiff --git a/store/sqlite/migration/prod/0.12/03__resource_internal_path.sql b/store/db/sqlite/migration/prod/0.12/03__resource_internal_path.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.12/03__resource_internal_path.sqlrename to store/db/sqlite/migration/prod/0.12/03__resource_internal_path.sqldiff --git a/store/sqlite/migration/prod/0.12/04__resource_public_id.sql b/store/db/sqlite/migration/prod/0.12/04__resource_public_id.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.12/04__resource_public_id.sqlrename to store/db/sqlite/migration/prod/0.12/04__resource_public_id.sqldiff --git a/store/sqlite/migration/prod/0.13/00__memo_relation.sql b/store/db/sqlite/migration/prod/0.13/00__memo_relation.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.13/00__memo_relation.sqlrename to store/db/sqlite/migration/prod/0.13/00__memo_relation.sqldiff --git a/store/sqlite/migration/prod/0.13/01__remove_memo_organizer_id.sql b/store/db/sqlite/migration/prod/0.13/01__remove_memo_organizer_id.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.13/01__remove_memo_organizer_id.sqlrename to store/db/sqlite/migration/prod/0.13/01__remove_memo_organizer_id.sqldiff --git a/store/sqlite/migration/prod/0.14/00__drop_resource_public_id.sql b/store/db/sqlite/migration/prod/0.14/00__drop_resource_public_id.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.14/00__drop_resource_public_id.sqlrename to store/db/sqlite/migration/prod/0.14/00__drop_resource_public_id.sqldiff --git a/store/sqlite/migration/prod/0.14/01__create_indexes.sql b/store/db/sqlite/migration/prod/0.14/01__create_indexes.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.14/01__create_indexes.sqlrename to store/db/sqlite/migration/prod/0.14/01__create_indexes.sqldiff --git a/store/sqlite/migration/prod/0.15/00__drop_user_open_id.sql b/store/db/sqlite/migration/prod/0.15/00__drop_user_open_id.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.15/00__drop_user_open_id.sqlrename to store/db/sqlite/migration/prod/0.15/00__drop_user_open_id.sqldiff --git a/store/sqlite/migration/prod/0.16/00__add_memo_id_to_resource.sql b/store/db/sqlite/migration/prod/0.16/00__add_memo_id_to_resource.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.16/00__add_memo_id_to_resource.sqlrename to store/db/sqlite/migration/prod/0.16/00__add_memo_id_to_resource.sqldiff --git a/store/sqlite/migration/prod/0.16/01__drop_shortcut_table.sql b/store/db/sqlite/migration/prod/0.16/01__drop_shortcut_table.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.16/01__drop_shortcut_table.sqlrename to store/db/sqlite/migration/prod/0.16/01__drop_shortcut_table.sqldiff --git a/store/sqlite/migration/prod/0.2/00__user_role.sql b/store/db/sqlite/migration/prod/0.2/00__user_role.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.2/00__user_role.sqlrename to store/db/sqlite/migration/prod/0.2/00__user_role.sqldiff --git a/store/sqlite/migration/prod/0.2/01__memo_visibility.sql b/store/db/sqlite/migration/prod/0.2/01__memo_visibility.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.2/01__memo_visibility.sqlrename to store/db/sqlite/migration/prod/0.2/01__memo_visibility.sqldiff --git a/store/sqlite/migration/prod/0.3/00__memo_visibility_protected.sql b/store/db/sqlite/migration/prod/0.3/00__memo_visibility_protected.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.3/00__memo_visibility_protected.sqlrename to store/db/sqlite/migration/prod/0.3/00__memo_visibility_protected.sqldiff --git a/store/sqlite/migration/prod/0.4/00__user_setting.sql b/store/db/sqlite/migration/prod/0.4/00__user_setting.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.4/00__user_setting.sqlrename to store/db/sqlite/migration/prod/0.4/00__user_setting.sqldiff --git a/store/sqlite/migration/prod/0.5/00__regenerate_foreign_keys.sql b/store/db/sqlite/migration/prod/0.5/00__regenerate_foreign_keys.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.5/00__regenerate_foreign_keys.sqlrename to store/db/sqlite/migration/prod/0.5/00__regenerate_foreign_keys.sqldiff --git a/store/sqlite/migration/prod/0.5/01__memo_resource.sql b/store/db/sqlite/migration/prod/0.5/01__memo_resource.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.5/01__memo_resource.sqlrename to store/db/sqlite/migration/prod/0.5/01__memo_resource.sqldiff --git a/store/sqlite/migration/prod/0.5/02__system_setting.sql b/store/db/sqlite/migration/prod/0.5/02__system_setting.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.5/02__system_setting.sqlrename to store/db/sqlite/migration/prod/0.5/02__system_setting.sqldiff --git a/store/sqlite/migration/prod/0.5/03__resource_extermal_link.sql b/store/db/sqlite/migration/prod/0.5/03__resource_extermal_link.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.5/03__resource_extermal_link.sqlrename to store/db/sqlite/migration/prod/0.5/03__resource_extermal_link.sqldiff --git a/store/sqlite/migration/prod/0.6/00__recreate_triggers.sql b/store/db/sqlite/migration/prod/0.6/00__recreate_triggers.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.6/00__recreate_triggers.sqlrename to store/db/sqlite/migration/prod/0.6/00__recreate_triggers.sqldiff --git a/store/sqlite/migration/prod/0.7/00__remove_fk.sql b/store/db/sqlite/migration/prod/0.7/00__remove_fk.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.7/00__remove_fk.sqlrename to store/db/sqlite/migration/prod/0.7/00__remove_fk.sqldiff --git a/store/sqlite/migration/prod/0.7/01__remove_triggers.sql b/store/db/sqlite/migration/prod/0.7/01__remove_triggers.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.7/01__remove_triggers.sqlrename to store/db/sqlite/migration/prod/0.7/01__remove_triggers.sqldiff --git a/store/sqlite/migration/prod/0.8/00__migration_history.sql b/store/db/sqlite/migration/prod/0.8/00__migration_history.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.8/00__migration_history.sqlrename to store/db/sqlite/migration/prod/0.8/00__migration_history.sqldiff --git a/store/sqlite/migration/prod/0.8/01__user_username.sql b/store/db/sqlite/migration/prod/0.8/01__user_username.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.8/01__user_username.sqlrename to store/db/sqlite/migration/prod/0.8/01__user_username.sqldiff --git a/store/sqlite/migration/prod/0.9/00__tag.sql b/store/db/sqlite/migration/prod/0.9/00__tag.sqlsimilarity index 100%rename from store/sqlite/migration/prod/0.9/00__tag.sqlrename to store/db/sqlite/migration/prod/0.9/00__tag.sqldiff --git a/store/sqlite/migration_history.go b/store/db/sqlite/migration_history.gosimilarity index 85%rename from store/sqlite/migration_history.gorename to store/db/sqlite/migration_history.goindex 2de2725d6..0c5224e7b 100644--- a/store/sqlite/migration_history.go+++ b/store/db/sqlite/migration_history.go@@ -18,7 +18,7 @@ type MigrationHistoryFind struct {Version *string}-func (d *Driver) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {+func (d *DB) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*MigrationHistory, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Version; v != nil {@@ -60,7 +60,7 @@ func (d *Driver) FindMigrationHistoryList(ctx context.Context, find *MigrationHireturn list, nil}-func (d *Driver) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {+func (d *DB) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHistoryUpsert) (*MigrationHistory, error) {stmt := `INSERT INTO migration_history (versiondiff --git a/store/sqlite/migrator.go b/store/db/sqlite/migrator.gosimilarity index 95%rename from store/sqlite/migrator.gorename to store/db/sqlite/migrator.goindex cd15ec570..c6b95f884 100644--- a/store/sqlite/migrator.go+++ b/store/db/sqlite/migrator.go@@ -22,7 +22,7 @@ var migrationFS embed.FSvar seedFS embed.FS// Migrate applies the latest schema to the database.-func (d *Driver) Migrate(ctx context.Context) error {+func (d *DB) Migrate(ctx context.Context) error {if d.profile.Mode == "prod" {_, err := os.Stat(d.profile.DSN)if err != nil {@@ -112,7 +112,7 @@ const (latestSchemaFileName = "LATEST__SCHEMA.sql")-func (d *Driver) applyLatestSchema(ctx context.Context) error {+func (d *DB) applyLatestSchema(ctx context.Context) error {schemaMode := "dev"if d.profile.Mode == "prod" {schemaMode = "prod"@@ -129,7 +129,7 @@ func (d *Driver) applyLatestSchema(ctx context.Context) error {return nil}-func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersion string) error {+func (d *DB) applyMigrationForMinorVersion(ctx context.Context, minorVersion string) error {filenames, err := fs.Glob(migrationFS, fmt.Sprintf("%s/%s/*.sql", "migration/prod", minorVersion))if err != nil {return errors.Wrap(err, "failed to read ddl files")@@ -162,7 +162,7 @@ func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersionreturn nil}-func (d *Driver) seed(ctx context.Context) error {+func (d *DB) seed(ctx context.Context) error {filenames, err := fs.Glob(seedFS, fmt.Sprintf("%s/*.sql", "seed"))if err != nil {return errors.Wrap(err, "failed to read seed files")@@ -185,7 +185,7 @@ func (d *Driver) seed(ctx context.Context) error {}// execute runs a single SQL statement within a transaction.-func (d *Driver) execute(ctx context.Context, stmt string) error {+func (d *DB) execute(ctx context.Context, stmt string) error {tx, err := d.db.Begin()if err != nil {return errdiff --git a/store/sqlite/resource.go b/store/db/sqlite/resource.gosimilarity index 89%rename from store/sqlite/resource.gorename to store/db/sqlite/resource.goindex 9095e3446..b922dca80 100644--- a/store/sqlite/resource.go+++ b/store/db/sqlite/resource.go@@ -9,7 +9,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateResource(ctx context.Context, create *store.Resource) (*store.Resource, error) {+func (d *DB) CreateResource(ctx context.Context, create *store.Resource) (*store.Resource, error) {stmt := `INSERT INTO resource (filename,@@ -40,7 +40,7 @@ func (d *Driver) CreateResource(ctx context.Context, create *store.Resource) (*sreturn create, nil}-func (d *Driver) ListResources(ctx context.Context, find *store.FindResource) ([]*store.Resource, error) {+func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*store.Resource, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -120,7 +120,7 @@ func (d *Driver) ListResources(ctx context.Context, find *store.FindResource) ([return list, nil}-func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResource) (*store.Resource, error) {+func (d *DB) UpdateResource(ctx context.Context, update *store.UpdateResource) (*store.Resource, error) {set, args := []string{}, []any{}if v := update.UpdatedTs; v != nil {@@ -135,9 +135,6 @@ func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResourcif v := update.MemoID; v != nil {set, args = append(set, "memo_id = ?"), append(args, *v)}- if update.UnbindMemo {- set = append(set, "memo_id = NULL")- }if v := update.Blob; v != nil {set, args = append(set, "blob = ?"), append(args, v)}@@ -168,7 +165,7 @@ func (d *Driver) UpdateResource(ctx context.Context, update *store.UpdateResourcreturn &resource, nil}-func (d *Driver) DeleteResource(ctx context.Context, delete *store.DeleteResource) error {+func (d *DB) DeleteResource(ctx context.Context, delete *store.DeleteResource) error {stmt := `DELETE FROM resourceWHERE id = ?diff --git a/store/sqlite/seed/10000__reset.sql b/store/db/sqlite/seed/10000__reset.sqlsimilarity index 100%rename from store/sqlite/seed/10000__reset.sqlrename to store/db/sqlite/seed/10000__reset.sqldiff --git a/store/sqlite/seed/10001__user.sql b/store/db/sqlite/seed/10001__user.sqlsimilarity index 100%rename from store/sqlite/seed/10001__user.sqlrename to store/db/sqlite/seed/10001__user.sqldiff --git a/store/sqlite/seed/10002__memo.sql b/store/db/sqlite/seed/10002__memo.sqlsimilarity index 100%rename from store/sqlite/seed/10002__memo.sqlrename to store/db/sqlite/seed/10002__memo.sqldiff --git a/store/sqlite/seed/10003__memo_organizer.sql b/store/db/sqlite/seed/10003__memo_organizer.sqlsimilarity index 100%rename from store/sqlite/seed/10003__memo_organizer.sqlrename to store/db/sqlite/seed/10003__memo_organizer.sqldiff --git a/store/sqlite/seed/10004__tag.sql b/store/db/sqlite/seed/10004__tag.sqlsimilarity index 100%rename from store/sqlite/seed/10004__tag.sqlrename to store/db/sqlite/seed/10004__tag.sqldiff --git a/store/sqlite/sqlite.go b/store/db/sqlite/sqlite.gosimilarity index 88%rename from store/sqlite/sqlite.gorename to store/db/sqlite/sqlite.goindex 3cd1bb1fb..182cfc1ba 100644--- a/store/sqlite/sqlite.go+++ b/store/db/sqlite/sqlite.go@@ -11,15 +11,15 @@ import ("github.com/usememos/memos/store")-type Driver struct {+type DB struct {db *sql.DBprofile *profile.Profile}-// NewDriver opens a database specified by its database driver name and a+// NewDB opens a database specified by its database driver name and a// driver-specific data source name, usually consisting of at least a// database name and connection information.-func NewDriver(profile *profile.Profile) (store.Driver, error) {+func NewDB(profile *profile.Profile) (store.Driver, error) {// Ensure a DSN is set before attempting to open the database.if profile.DSN == "" {return nil, errors.New("dsn required")@@ -44,16 +44,16 @@ func NewDriver(profile *profile.Profile) (store.Driver, error) {return nil, errors.Wrapf(err, "failed to open db with dsn: %s", profile.DSN)}- driver := Driver{db: sqliteDB, profile: profile}+ driver := DB{db: sqliteDB, profile: profile}return &driver, nil}-func (d *Driver) GetDB() *sql.DB {+func (d *DB) GetDB() *sql.DB {return d.db}-func (d *Driver) Vacuum(ctx context.Context) error {+func (d *DB) Vacuum(ctx context.Context) error {tx, err := d.db.BeginTx(ctx, nil)if err != nil {return err@@ -100,7 +100,7 @@ func vacuumImpl(ctx context.Context, tx *sql.Tx) error {return nil}-func (d *Driver) BackupTo(ctx context.Context, filename string) error {+func (d *DB) BackupTo(ctx context.Context, filename string) error {conn, err := d.db.Conn(ctx)if err != nil {return errors.Wrap(err, "fail to open new connection")@@ -137,6 +137,6 @@ func (d *Driver) BackupTo(ctx context.Context, filename string) error {return nil}-func (d *Driver) Close() error {+func (d *DB) Close() error {return d.db.Close()}diff --git a/store/sqlite/storage.go b/store/db/sqlite/storage.gosimilarity index 80%rename from store/sqlite/storage.gorename to store/db/sqlite/storage.goindex db605ab22..705a4531b 100644--- a/store/sqlite/storage.go+++ b/store/db/sqlite/storage.go@@ -7,7 +7,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {+func (d *DB) CreateStorage(ctx context.Context, create *store.Storage) (*store.Storage, error) {stmt := `INSERT INTO storage (name,@@ -27,7 +27,7 @@ func (d *Driver) CreateStorage(ctx context.Context, create *store.Storage) (*storeturn storage, nil}-func (d *Driver) ListStorages(ctx context.Context, find *store.FindStorage) ([]*store.Storage, error) {+func (d *DB) ListStorages(ctx context.Context, find *store.FindStorage) ([]*store.Storage, error) {where, args := []string{"1 = 1"}, []any{}if find.ID != nil {where, args = append(where, "id = ?"), append(args, *find.ID)@@ -70,7 +70,7 @@ func (d *Driver) ListStorages(ctx context.Context, find *store.FindStorage) ([]*return list, nil}-func (d *Driver) GetStorage(ctx context.Context, find *store.FindStorage) (*store.Storage, error) {+func (d *DB) GetStorage(ctx context.Context, find *store.FindStorage) (*store.Storage, error) {list, err := d.ListStorages(ctx, find)if err != nil {return nil, err@@ -82,7 +82,7 @@ func (d *Driver) GetStorage(ctx context.Context, find *store.FindStorage) (*storreturn list[0], nil}-func (d *Driver) UpdateStorage(ctx context.Context, update *store.UpdateStorage) (*store.Storage, error) {+func (d *DB) UpdateStorage(ctx context.Context, update *store.UpdateStorage) (*store.Storage, error) {set, args := []string{}, []any{}if update.Name != nil {set = append(set, "name = ?")@@ -117,7 +117,7 @@ func (d *Driver) UpdateStorage(ctx context.Context, update *store.UpdateStorage)return storage, nil}-func (d *Driver) DeleteStorage(ctx context.Context, delete *store.DeleteStorage) error {+func (d *DB) DeleteStorage(ctx context.Context, delete *store.DeleteStorage) error {stmt := `DELETE FROM storageWHERE id = ?diff --git a/store/sqlite/system_setting.go b/store/db/sqlite/system_setting.gosimilarity index 83%rename from store/sqlite/system_setting.gorename to store/db/sqlite/system_setting.goindex 492a94add..95474fa0d 100644--- a/store/sqlite/system_setting.go+++ b/store/db/sqlite/system_setting.go@@ -7,7 +7,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSetting) (*store.SystemSetting, error) {+func (d *DB) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSetting) (*store.SystemSetting, error) {stmt := `INSERT INTO system_setting (name, value, description@@ -25,7 +25,7 @@ func (d *Driver) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSereturn upsert, nil}-func (d *Driver) ListSystemSettings(ctx context.Context, find *store.FindSystemSetting) ([]*store.SystemSetting, error) {+func (d *DB) ListSystemSettings(ctx context.Context, find *store.FindSystemSetting) ([]*store.SystemSetting, error) {where, args := []string{"1 = 1"}, []any{}if find.Name != "" {where, args = append(where, "name = ?"), append(args, find.Name)diff --git a/store/sqlite/tag.go b/store/db/sqlite/tag.gosimilarity index 85%rename from store/sqlite/tag.gorename to store/db/sqlite/tag.goindex 0132b3f41..fce43c5a5 100644--- a/store/sqlite/tag.go+++ b/store/db/sqlite/tag.go@@ -8,7 +8,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, error) {+func (d *DB) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag, error) {stmt := `INSERT INTO tag (name, creator_id@@ -26,7 +26,7 @@ func (d *Driver) UpsertTag(ctx context.Context, upsert *store.Tag) (*store.Tag,return tag, nil}-func (d *Driver) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) {+func (d *DB) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tag, error) {where, args := []string{"creator_id = ?"}, []any{find.CreatorID}query := `SELECT@@ -62,7 +62,7 @@ func (d *Driver) ListTags(ctx context.Context, find *store.FindTag) ([]*store.Tareturn list, nil}-func (d *Driver) DeleteTag(ctx context.Context, delete *store.DeleteTag) error {+func (d *DB) DeleteTag(ctx context.Context, delete *store.DeleteTag) error {where, args := []string{"name = ?", "creator_id = ?"}, []any{delete.Name, delete.CreatorID}stmt := `DELETE FROM tag WHERE ` + strings.Join(where, " AND ")result, err := d.db.ExecContext(ctx, stmt, args...)diff --git a/store/sqlite/user.go b/store/db/sqlite/user.gosimilarity index 90%rename from store/sqlite/user.gorename to store/db/sqlite/user.goindex 1e97d9b50..e1c5efde5 100644--- a/store/sqlite/user.go+++ b/store/db/sqlite/user.go@@ -7,7 +7,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) CreateUser(ctx context.Context, create *store.User) (*store.User, error) {+func (d *DB) CreateUser(ctx context.Context, create *store.User) (*store.User, error) {stmt := `INSERT INTO user (username,@@ -40,7 +40,7 @@ func (d *Driver) CreateUser(ctx context.Context, create *store.User) (*store.Usereturn create, nil}-func (d *Driver) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.User, error) {+func (d *DB) UpdateUser(ctx context.Context, update *store.UpdateUser) (*store.User, error) {set, args := []string{}, []any{}if v := update.UpdatedTs; v != nil {set, args = append(set, "updated_ts = ?"), append(args, *v)@@ -90,7 +90,7 @@ func (d *Driver) UpdateUser(ctx context.Context, update *store.UpdateUser) (*storeturn user, nil}-func (d *Driver) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User, error) {+func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User, error) {where, args := []string{"1 = 1"}, []any{}if v := find.ID; v != nil {@@ -158,7 +158,7 @@ func (d *Driver) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.return list, nil}-func (d *Driver) DeleteUser(ctx context.Context, delete *store.DeleteUser) error {+func (d *DB) DeleteUser(ctx context.Context, delete *store.DeleteUser) error {result, err := d.db.ExecContext(ctx, `DELETE FROM user WHERE id = ?`, delete.ID)diff --git a/store/sqlite/user_setting.go b/store/db/sqlite/user_setting.gosimilarity index 88%rename from store/sqlite/user_setting.gorename to store/db/sqlite/user_setting.goindex f1916ec7f..96d086a5e 100644--- a/store/sqlite/user_setting.go+++ b/store/db/sqlite/user_setting.go@@ -12,7 +12,7 @@ import ("github.com/usememos/memos/store")-func (d *Driver) UpsertUserSetting(ctx context.Context, upsert *store.UserSetting) (*store.UserSetting, error) {+func (d *DB) UpsertUserSetting(ctx context.Context, upsert *store.UserSetting) (*store.UserSetting, error) {stmt := `INSERT INTO user_setting (user_id, key, value@@ -28,7 +28,7 @@ func (d *Driver) UpsertUserSetting(ctx context.Context, upsert *store.UserSettinreturn upsert, nil}-func (d *Driver) ListUserSettings(ctx context.Context, find *store.FindUserSetting) ([]*store.UserSetting, error) {+func (d *DB) ListUserSettings(ctx context.Context, find *store.FindUserSetting) ([]*store.UserSetting, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Key; v != "" {@@ -71,7 +71,7 @@ func (d *Driver) ListUserSettings(ctx context.Context, find *store.FindUserSettireturn userSettingList, nil}-func (d *Driver) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) {+func (d *DB) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) {stmt := `INSERT INTO user_setting (user_id, key, value@@ -98,7 +98,7 @@ func (d *Driver) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSereturn upsert, nil}-func (d *Driver) ListUserSettingsV1(ctx context.Context, find *store.FindUserSettingV1) ([]*storepb.UserSetting, error) {+func (d *DB) ListUserSettingsV1(ctx context.Context, find *store.FindUserSettingV1) ([]*storepb.UserSetting, error) {where, args := []string{"1 = 1"}, []any{}if v := find.Key; v != storepb.UserSettingKey_USER_SETTING_KEY_UNSPECIFIED {diff --git a/store/driver.go b/store/driver.goindex 299b82620..c7494e98f 100644--- a/store/driver.go+++ b/store/driver.go@@ -7,6 +7,8 @@ import (storepb "github.com/usememos/memos/proto/gen/store")+// Driver is an interface for store driver.+// It contains all methods that store database driver should implement.type Driver interface {GetDB() *sql.DBClose() error@@ -15,50 +17,61 @@ type Driver interface {Vacuum(ctx context.Context) errorBackupTo(ctx context.Context, filename string) error+ // Activity model related methods.CreateActivity(ctx context.Context, create *Activity) (*Activity, error)+ // Resource model related methods.CreateResource(ctx context.Context, create *Resource) (*Resource, error)ListResources(ctx context.Context, find *FindResource) ([]*Resource, error)UpdateResource(ctx context.Context, update *UpdateResource) (*Resource, error)DeleteResource(ctx context.Context, delete *DeleteResource) error+ // Memo model related methods.CreateMemo(ctx context.Context, create *Memo) (*Memo, error)ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)UpdateMemo(ctx context.Context, update *UpdateMemo) errorDeleteMemo(ctx context.Context, delete *DeleteMemo) errorFindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error)+ // MemoRelation model related methods.UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error)ListMemoRelations(ctx context.Context, find *FindMemoRelation) ([]*MemoRelation, error)DeleteMemoRelation(ctx context.Context, delete *DeleteMemoRelation) error+ // MemoOrganizer model related methods.UpsertMemoOrganizer(ctx context.Context, upsert *MemoOrganizer) (*MemoOrganizer, error)GetMemoOrganizer(ctx context.Context, find *FindMemoOrganizer) (*MemoOrganizer, error)DeleteMemoOrganizer(ctx context.Context, delete *DeleteMemoOrganizer) error+ // SystemSetting model related methods.UpsertSystemSetting(ctx context.Context, upsert *SystemSetting) (*SystemSetting, error)ListSystemSettings(ctx context.Context, find *FindSystemSetting) ([]*SystemSetting, error)+ // User model related methods.CreateUser(ctx context.Context, create *User) (*User, error)UpdateUser(ctx context.Context, update *UpdateUser) (*User, error)ListUsers(ctx context.Context, find *FindUser) ([]*User, error)DeleteUser(ctx context.Context, delete *DeleteUser) error+ // UserSetting model related methods.UpsertUserSetting(ctx context.Context, upsert *UserSetting) (*UserSetting, error)ListUserSettings(ctx context.Context, find *FindUserSetting) ([]*UserSetting, error)UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error)ListUserSettingsV1(ctx context.Context, find *FindUserSettingV1) ([]*storepb.UserSetting, error)+ // IdentityProvider model related methods.CreateIdentityProvider(ctx context.Context, create *IdentityProvider) (*IdentityProvider, error)ListIdentityProviders(ctx context.Context, find *FindIdentityProvider) ([]*IdentityProvider, error)GetIdentityProvider(ctx context.Context, find *FindIdentityProvider) (*IdentityProvider, error)UpdateIdentityProvider(ctx context.Context, update *UpdateIdentityProvider) (*IdentityProvider, error)DeleteIdentityProvider(ctx context.Context, delete *DeleteIdentityProvider) error+ // Tag model related methods.UpsertTag(ctx context.Context, upsert *Tag) (*Tag, error)ListTags(ctx context.Context, find *FindTag) ([]*Tag, error)DeleteTag(ctx context.Context, delete *DeleteTag) error+ // Storage model related methods.CreateStorage(ctx context.Context, create *Storage) (*Storage, error)ListStorages(ctx context.Context, find *FindStorage) ([]*Storage, error)GetStorage(ctx context.Context, find *FindStorage) (*Storage, error)diff --git a/store/resource.go b/store/resource.goindex 87c149a16..829995642 100644--- a/store/resource.go+++ b/store/resource.go@@ -39,7 +39,6 @@ type UpdateResource struct {Filename *stringInternalPath *stringMemoID *int32- UnbindMemo boolBlob []byte}diff --git a/store/sqlite/migration/prod/LATEST__SCHEMA.sql b/store/sqlite/migration/prod/LATEST__SCHEMA.sqldeleted file mode 100644index 225eef376..000000000--- a/store/sqlite/migration/prod/LATEST__SCHEMA.sql+++ /dev/null@@ -1,138 +0,0 @@--- migration_history-CREATE TABLE migration_history (- version TEXT NOT NULL PRIMARY KEY,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now'))-);---- system_setting-CREATE TABLE system_setting (- name TEXT NOT NULL,- value TEXT NOT NULL,- description TEXT NOT NULL DEFAULT '',- UNIQUE(name)-);---- user-CREATE TABLE user (- id INTEGER PRIMARY KEY AUTOINCREMENT,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',- username TEXT NOT NULL UNIQUE,- role TEXT NOT NULL CHECK (role IN ('HOST', 'ADMIN', 'USER')) DEFAULT 'USER',- email TEXT NOT NULL DEFAULT '',- nickname TEXT NOT NULL DEFAULT '',- password_hash TEXT NOT NULL,- avatar_url TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_user_username ON user (username);---- user_setting-CREATE TABLE user_setting (- user_id INTEGER NOT NULL,- key TEXT NOT NULL,- value TEXT NOT NULL,- UNIQUE(user_id, key)-);---- memo-CREATE TABLE memo (- id INTEGER PRIMARY KEY AUTOINCREMENT,- creator_id INTEGER NOT NULL,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',- content TEXT NOT NULL DEFAULT '',- visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE'-);--CREATE INDEX idx_memo_creator_id ON memo (creator_id);-CREATE INDEX idx_memo_content ON memo (content);-CREATE INDEX idx_memo_visibility ON memo (visibility);---- memo_organizer-CREATE TABLE memo_organizer (- memo_id INTEGER NOT NULL,- user_id INTEGER NOT NULL,- pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,- UNIQUE(memo_id, user_id)-);---- shortcut-CREATE TABLE shortcut (- id INTEGER PRIMARY KEY AUTOINCREMENT,- creator_id INTEGER NOT NULL,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',- title TEXT NOT NULL DEFAULT '',- payload TEXT NOT NULL DEFAULT '{}'-);---- resource-CREATE TABLE resource (- id INTEGER PRIMARY KEY AUTOINCREMENT,- creator_id INTEGER NOT NULL,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- filename TEXT NOT NULL DEFAULT '',- blob BLOB DEFAULT NULL,- external_link TEXT NOT NULL DEFAULT '',- type TEXT NOT NULL DEFAULT '',- size INTEGER NOT NULL DEFAULT 0,- internal_path TEXT NOT NULL DEFAULT ''-);--CREATE INDEX idx_resource_creator_id ON resource (creator_id);---- memo_resource-CREATE TABLE memo_resource (- memo_id INTEGER NOT NULL,- resource_id INTEGER NOT NULL,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- UNIQUE(memo_id, resource_id)-);---- tag-CREATE TABLE tag (- name TEXT NOT NULL,- creator_id INTEGER NOT NULL,- UNIQUE(name, creator_id)-);---- activity-CREATE TABLE activity (- id INTEGER PRIMARY KEY AUTOINCREMENT,- creator_id INTEGER NOT NULL,- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),- type TEXT NOT NULL DEFAULT '',- level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')) DEFAULT 'INFO',- payload TEXT NOT NULL DEFAULT '{}'-);---- storage-CREATE TABLE storage (- id INTEGER PRIMARY KEY AUTOINCREMENT,- name TEXT NOT NULL,- type TEXT NOT NULL,- config TEXT NOT NULL DEFAULT '{}'-);---- idp-CREATE TABLE idp (- id INTEGER PRIMARY KEY AUTOINCREMENT,- name TEXT NOT NULL,- type TEXT NOT NULL,- identifier_filter TEXT NOT NULL DEFAULT '',- config TEXT NOT NULL DEFAULT '{}'-);---- memo_relation-CREATE TABLE memo_relation (- memo_id INTEGER NOT NULL,- related_memo_id INTEGER NOT NULL,- type TEXT NOT NULL,- UNIQUE(memo_id, related_memo_id, type)-);diff --git a/test/server/server.go b/test/server/server.goindex ee262a9d6..99524edb9 100644--- a/test/server/server.go+++ b/test/server/server.go@@ -18,7 +18,7 @@ import ("github.com/usememos/memos/server""github.com/usememos/memos/server/profile""github.com/usememos/memos/store"- "github.com/usememos/memos/store/sqlite"+ "github.com/usememos/memos/store/db""github.com/usememos/memos/test")@@ -31,15 +31,15 @@ type TestingServer struct {func NewTestingServer(ctx context.Context, t *testing.T) (*TestingServer, error) {profile := test.GetTestingProfile(t)- driver, err := sqlite.NewDriver(profile)+ dbDriver, err := db.NewDBDriver(profile)if err != nil {return nil, errors.Wrap(err, "failed to create db driver")}- if err := driver.Migrate(ctx); err != nil {+ if err := dbDriver.Migrate(ctx); err != nil {return nil, errors.Wrap(err, "failed to migrate db")}- store := store.New(driver, profile)+ store := store.New(dbDriver, profile)server, err := server.NewServer(ctx, profile, store)if err != nil {return nil, errors.Wrap(err, "failed to create server")diff --git a/test/store/store.go b/test/store/store.goindex e6e40cdd1..46ecaebd1 100644--- a/test/store/store.go+++ b/test/store/store.go@@ -11,30 +11,20 @@ import (_ "modernc.org/sqlite""github.com/usememos/memos/store"- "github.com/usememos/memos/store/mysql"- "github.com/usememos/memos/store/sqlite"+ "github.com/usememos/memos/store/db""github.com/usememos/memos/test")func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {profile := test.GetTestingProfile(t)- var driver store.Driver- var err error- switch profile.Driver {- case "sqlite":- driver, err = sqlite.NewDriver(profile)- case "mysql":- driver, err = mysql.NewDriver(profile)- default:- panic(fmt.Sprintf("unknown db driver: %s", profile.Driver))- }+ dbDriver, err := db.NewDBDriver(profile)if err != nil {fmt.Printf("failed to create db driver, error: %+v\n", err)}- if err := driver.Migrate(ctx); err != nil {+ if err := dbDriver.Migrate(ctx); err != nil {fmt.Printf("failed to migrate db, error: %+v\n", err)}- store := store.New(driver, profile)+ store := store.New(dbDriver, profile)return store}