mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-21 01:53:33 +00:00
a4a701367a
- Create Dialect abstraction for SQLite/PostgreSQL SQL differences (JSON ops, FTS, placeholders, datetime, aggregation) - Add Store.NewPostgres() constructor with connection pooling - Create consolidated PostgreSQL schema (pgmigrations/001_initial.sql) with tsvector FTS, JSONB columns, and GIN indexes - Refactor all store queries (~150) to use s.q() for placeholder rebinding - Replace hardcoded json_extract/FTS5/GROUP_CONCAT with dialect methods - Support PAD_DB_DRIVER=postgres + PAD_DATABASE_URL env vars - Keep SQLite as the default for local/self-hosted mode - Add dialect unit tests (rebind, SQLite, PostgreSQL)
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package store
|
|
|
|
import "database/sql"
|
|
|
|
// GetPlatformSetting returns a single platform setting value, or empty string if not set.
|
|
func (s *Store) GetPlatformSetting(key string) (string, error) {
|
|
var value string
|
|
err := s.db.QueryRow(s.q("SELECT value FROM platform_settings WHERE key = ?"), key).Scan(&value)
|
|
if err == sql.ErrNoRows {
|
|
return "", nil
|
|
}
|
|
return value, err
|
|
}
|
|
|
|
// SetPlatformSetting upserts a platform setting.
|
|
func (s *Store) SetPlatformSetting(key, value string) error {
|
|
_, err := s.db.Exec(s.q(`
|
|
INSERT INTO platform_settings (key, value, updated_at) VALUES (?, ?, ?)
|
|
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at
|
|
`), key, value, now())
|
|
return err
|
|
}
|
|
|
|
// GetPlatformSettings returns all platform settings as a map.
|
|
func (s *Store) GetPlatformSettings() (map[string]string, error) {
|
|
rows, err := s.db.Query(s.q("SELECT key, value FROM platform_settings ORDER BY key"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
settings := make(map[string]string)
|
|
for rows.Next() {
|
|
var k, v string
|
|
if err := rows.Scan(&k, &v); err != nil {
|
|
return nil, err
|
|
}
|
|
settings[k] = v
|
|
}
|
|
return settings, rows.Err()
|
|
}
|
|
|
|
// DeletePlatformSetting removes a platform setting.
|
|
func (s *Store) DeletePlatformSetting(key string) error {
|
|
_, err := s.db.Exec(s.q("DELETE FROM platform_settings WHERE key = ?"), key)
|
|
return err
|
|
}
|