memos/store/db/postgres/system_setting.go
Irving Ou 9c18960f47
feat: support Postgres (#2569)
* skeleton of postgres

skeleton

* Adding Postgres specific db schema sql

* user test passed

* memo store test passed

* tag is working

* update user setting test done

* activity test done

* idp test passed

* inbox test done

* memo_organizer, UNTESTED

* memo relation test passed

* webhook test passed

* system setting test passed

* passed storage test

* pass resource test

* migration_history done

* fix memo_relation_test

* fixing server memo_relation test

* passes memo relation server test

* paess memo test

* final manual testing done

* final fixes

* final fixes cleanup

* sync schema

* lint

* lint

* lint

* lint

* lint
2023-12-03 13:31:29 +08:00

61 lines
1.4 KiB
Go

package postgres
import (
"context"
"github.com/Masterminds/squirrel"
"github.com/usememos/memos/store"
)
func (d *DB) UpsertSystemSetting(ctx context.Context, upsert *store.SystemSetting) (*store.SystemSetting, error) {
qb := squirrel.Insert("system_setting").
Columns("name", "value", "description").
Values(upsert.Name, upsert.Value, upsert.Description)
query, args, err := qb.PlaceholderFormat(squirrel.Dollar).ToSql()
if err != nil {
return nil, err
}
_, err = d.db.ExecContext(ctx, query, args...)
if err != nil {
return nil, err
}
return upsert, nil
}
func (d *DB) ListSystemSettings(ctx context.Context, find *store.FindSystemSetting) ([]*store.SystemSetting, error) {
qb := squirrel.Select("name", "value", "description").From("system_setting")
if find.Name != "" {
qb = qb.Where(squirrel.Eq{"name": find.Name})
}
query, args, err := qb.PlaceholderFormat(squirrel.Dollar).ToSql()
if err != nil {
return nil, err
}
rows, err := d.db.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
list := []*store.SystemSetting{}
for rows.Next() {
systemSetting := &store.SystemSetting{}
if err := rows.Scan(&systemSetting.Name, &systemSetting.Value, &systemSetting.Description); err != nil {
return nil, err
}
list = append(list, systemSetting)
}
if err := rows.Err(); err != nil {
return nil, err
}
return list, nil
}