mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Split queries to make them work on Postgres and MySQL
Only SQLite supports multiple deletes in one transaction/statement, but other are not.
This commit is contained in:
@@ -222,10 +222,7 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
|
||||
|
||||
func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error {
|
||||
res, err := ds.db.ExecContext(ctx, ds.db.Rebind(
|
||||
`DELETE FROM apps WHERE name = ?;
|
||||
DELETE FROM logs WHERE app_name=?;
|
||||
DELETE FROM calls WHERE app_name=?;
|
||||
DELETE FROM routes WHERE app_name=?;`), appName, appName, appName, appName)
|
||||
`DELETE FROM apps WHERE name = ?`), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -233,8 +230,22 @@ func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error {
|
||||
if err == sql.ErrNoRows {
|
||||
return models.ErrAppsNotFound
|
||||
}
|
||||
|
||||
deletes := []string{
|
||||
`DELETE FROM logs WHERE app_name=?`,
|
||||
`DELETE FROM calls WHERE app_name=?`,
|
||||
`DELETE FROM routes WHERE app_name=?`,
|
||||
}
|
||||
|
||||
for _, stmt := range deletes {
|
||||
_, err = ds.db.ExecContext(ctx, ds.db.Rebind(stmt), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds *sqlStore) GetApp(ctx context.Context, name string) (*models.App, error) {
|
||||
query := ds.db.Rebind(`SELECT name, config FROM apps WHERE name=?`)
|
||||
|
||||
Reference in New Issue
Block a user