mirror of
https://github.com/usememos/memos.git
synced 2024-11-16 19:56:11 +08:00
9c18960f47
* 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
61 lines
1.4 KiB
Go
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
|
|
}
|