Skip to content

Commit

Permalink
fix(db): quote postgres keywords (#383)
Browse files Browse the repository at this point in the history
The keyword "key" is a reserved word in Postgres and must be quoted if
used as a column name.

Fixes: #380
  • Loading branch information
aymanbagabas authored Sep 13, 2023
1 parent 5464150 commit 6a42d89
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/store/database/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ store.SettingStore = (*settingsStore)(nil)
// GetAllowKeylessAccess implements store.SettingStore.
func (*settingsStore) GetAllowKeylessAccess(ctx context.Context, tx db.Handler) (bool, error) {
var allow bool
query := tx.Rebind(`SELECT value FROM settings WHERE key = "allow_keyless"`)
query := tx.Rebind(`SELECT value FROM settings WHERE "key" = 'allow_keyless'`)
if err := tx.GetContext(ctx, &allow, query); err != nil {
return false, db.WrapError(err)
}
Expand All @@ -25,7 +25,7 @@ func (*settingsStore) GetAllowKeylessAccess(ctx context.Context, tx db.Handler)
// GetAnonAccess implements store.SettingStore.
func (*settingsStore) GetAnonAccess(ctx context.Context, tx db.Handler) (access.AccessLevel, error) {
var level string
query := tx.Rebind(`SELECT value FROM settings WHERE key = "anon_access"`)
query := tx.Rebind(`SELECT value FROM settings WHERE "key" = 'anon_access'`)
if err := tx.GetContext(ctx, &level, query); err != nil {
return access.NoAccess, db.WrapError(err)
}
Expand All @@ -34,14 +34,14 @@ func (*settingsStore) GetAnonAccess(ctx context.Context, tx db.Handler) (access.

// SetAllowKeylessAccess implements store.SettingStore.
func (*settingsStore) SetAllowKeylessAccess(ctx context.Context, tx db.Handler, allow bool) error {
query := tx.Rebind(`UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE key = "allow_keyless"`)
query := tx.Rebind(`UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE "key" = 'allow_keyless'`)
_, err := tx.ExecContext(ctx, query, allow)
return db.WrapError(err)
}

// SetAnonAccess implements store.SettingStore.
func (*settingsStore) SetAnonAccess(ctx context.Context, tx db.Handler, level access.AccessLevel) error {
query := tx.Rebind(`UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE key = "anon_access"`)
query := tx.Rebind(`UPDATE settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE "key" = 'anon_access'`)
_, err := tx.ExecContext(ctx, query, level.String())
return db.WrapError(err)
}

0 comments on commit 6a42d89

Please sign in to comment.