From 4608894e56d8cd85ad765b0601b54a522f46af07 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 18 Sep 2022 22:48:26 +0800 Subject: [PATCH] fix: add `_foreign_keys` to sqlite dsn --- store/db/db.go | 2 +- store/memo.go | 1 - store/resource.go | 1 - store/shortcut.go | 1 - store/user.go | 1 - 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/store/db/db.go b/store/db/db.go index 24cd75f8..ebf7a941 100644 --- a/store/db/db.go +++ b/store/db/db.go @@ -43,7 +43,7 @@ func (db *DB) Open(ctx context.Context) (err error) { } // Connect to the database. - sqlDB, err := sql.Open("sqlite3", db.profile.DSN) + sqlDB, err := sql.Open("sqlite3", db.profile.DSN+"?_foreign_keys=1") if err != nil { return fmt.Errorf("failed to open db with dsn: %s, err: %w", db.profile.DSN, err) } diff --git a/store/memo.go b/store/memo.go index 031faa44..17668113 100644 --- a/store/memo.go +++ b/store/memo.go @@ -354,7 +354,6 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me func deleteMemo(ctx context.Context, tx *sql.Tx, delete *api.MemoDelete) error { result, err := tx.ExecContext(ctx, ` - PRAGMA foreign_keys = ON; DELETE FROM memo WHERE id = ? `, delete.ID) if err != nil { diff --git a/store/resource.go b/store/resource.go index 06154354..3ea5db3a 100644 --- a/store/resource.go +++ b/store/resource.go @@ -241,7 +241,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) ( func deleteResource(ctx context.Context, tx *sql.Tx, delete *api.ResourceDelete) error { result, err := tx.ExecContext(ctx, ` - PRAGMA foreign_keys = ON; DELETE FROM resource WHERE id = ? AND creator_id = ? `, delete.ID, delete.CreatorID) if err != nil { diff --git a/store/shortcut.go b/store/shortcut.go index 0eab5c91..2fae474a 100644 --- a/store/shortcut.go +++ b/store/shortcut.go @@ -288,7 +288,6 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ( func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete) error { result, err := tx.ExecContext(ctx, ` - PRAGMA foreign_keys = ON; DELETE FROM shortcut WHERE id = ? `, delete.ID) if err != nil { diff --git a/store/user.go b/store/user.go index dc3a34c3..1bff2586 100644 --- a/store/user.go +++ b/store/user.go @@ -351,7 +351,6 @@ func findUserList(ctx context.Context, tx *sql.Tx, find *api.UserFind) ([]*userR func deleteUser(ctx context.Context, tx *sql.Tx, delete *api.UserDelete) error { result, err := tx.ExecContext(ctx, ` - PRAGMA foreign_keys = ON; DELETE FROM user WHERE id = ? `, delete.ID) if err != nil {