Merge pull request #347 from fnproject/fix-queries-for-mysql-pg

Split queries to make them work on Postgres and MySQL
This commit is contained in:
Reed Allman
2017-09-20 17:07:24 -07:00
committed by GitHub
3 changed files with 44 additions and 13 deletions

View File

@@ -222,19 +222,33 @@ 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)
if err != nil {
return err
}
_, err = res.RowsAffected()
if err == sql.ErrNoRows {
return models.ErrAppsNotFound
}
return err
return ds.Tx(func(tx *sqlx.Tx) error {
res, err := tx.ExecContext(ctx, tx.Rebind(`DELETE FROM apps WHERE name=?`), appName)
if err != nil {
return err
}
n, err := res.RowsAffected()
if err != nil {
return err
}
if n == 0 {
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 := tx.ExecContext(ctx, tx.Rebind(stmt), appName)
if err != nil {
return err
}
}
return nil
})
}
func (ds *sqlStore) GetApp(ctx context.Context, name string) (*models.App, error) {