fix: add _foreign_keys to sqlite dsn

This commit is contained in:
Steven 2022-09-18 22:48:26 +08:00
parent a1066322c8
commit 4608894e56
5 changed files with 1 additions and 5 deletions

View File

@ -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)
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {