mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Run queries inside one transaction
This commit is contained in:
@@ -221,30 +221,32 @@ 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 = ?`), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = res.RowsAffected()
|
||||
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)
|
||||
return ds.Tx(func(tx *sqlx.Tx) error {
|
||||
res, err := ds.db.ExecContext(ctx, ds.db.Rebind(
|
||||
`DELETE FROM apps WHERE name = ?`), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = res.RowsAffected()
|
||||
if err == sql.ErrNoRows {
|
||||
return models.ErrAppsNotFound
|
||||
}
|
||||
|
||||
return nil
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user