Addressing review comments

This commit is contained in:
Denis Makogon
2017-09-12 20:07:40 +03:00
parent 33a8b87dc0
commit 4052a7d428
4 changed files with 15 additions and 32 deletions

View File

@@ -221,10 +221,16 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
}
func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error {
ds.db.ExecContext(ctx, ds.db.Rebind(
`DELETE FROM routes, calls, logs WHERE app_name=?`), appName)
query := ds.db.Rebind(`DELETE FROM apps WHERE name = ?`)
_, err := ds.db.ExecContext(ctx, query, appName)
res, err := ds.db.ExecContext(ctx, query, appName)
if _, err := res.RowsAffected(); err != nil {
return models.ErrAppsNotFound
}
_, err = ds.db.ExecContext(ctx, ds.db.Rebind(
`DELETE FROM routes, calls, logs WHERE app_name=?`), appName)
if err != nil {
return err
}
return err
}
@@ -624,24 +630,6 @@ func (ds *sqlStore) DeleteLog(ctx context.Context, appName, callID string) error
return err
}
func (ds *sqlStore) BatchDeleteLogs(ctx context.Context, appName string) error {
query := ds.db.Rebind(`DELETE FROM logs WHERE app_name=?`)
_, err := ds.db.ExecContext(ctx, query, appName)
return err
}
func (ds *sqlStore) BatchDeleteCalls(ctx context.Context, appName string) error {
query := ds.db.Rebind(`DELETE FROM calls WHERE app_name=?`)
_, err := ds.db.ExecContext(ctx, query, appName)
return err
}
func (ds *sqlStore) BatchDeleteRoutes(ctx context.Context, appName string) error {
query := ds.db.Rebind(`DELETE FROM routes WHERE app_name=?`)
_, err := ds.db.ExecContext(ctx, query, appName)
return err
}
// TODO scrap for sqlx scanx ?? some things aren't perfect (e.g. config is a json string)
type RowScanner interface {
Scan(dest ...interface{}) error