dev: automated commit - 2025-08-10 18:18:05
This commit is contained in:
parent
47fb2fb928
commit
81967b4d8e
13 changed files with 438 additions and 53 deletions
|
|
@ -9,6 +9,21 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
const addStaticRecord = `-- name: AddStaticRecord :exec
|
||||
INSERT OR REPLACE INTO static_records (record_id, record_name)
|
||||
VALUES (?, ?)
|
||||
`
|
||||
|
||||
type AddStaticRecordParams struct {
|
||||
RecordID string `json:"record_id"`
|
||||
RecordName string `json:"record_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddStaticRecord(ctx context.Context, arg AddStaticRecordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, addStaticRecord, arg.RecordID, arg.RecordName)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteAllConfig = `-- name: DeleteAllConfig :exec
|
||||
DELETE FROM config
|
||||
`
|
||||
|
|
@ -22,6 +37,7 @@ const getConfig = `-- name: GetConfig :one
|
|||
SELECT api_token, zone_id, domain, update_period FROM config LIMIT 1
|
||||
`
|
||||
|
||||
// db/queries.sql
|
||||
func (q *Queries) GetConfig(ctx context.Context) (Config, error) {
|
||||
row := q.db.QueryRowContext(ctx, getConfig)
|
||||
var i Config
|
||||
|
|
@ -34,6 +50,38 @@ func (q *Queries) GetConfig(ctx context.Context) (Config, error) {
|
|||
return i, err
|
||||
}
|
||||
|
||||
const getStaticRecords = `-- name: GetStaticRecords :many
|
||||
SELECT record_id, record_name FROM static_records
|
||||
`
|
||||
|
||||
type GetStaticRecordsRow struct {
|
||||
RecordID string `json:"record_id"`
|
||||
RecordName string `json:"record_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetStaticRecords(ctx context.Context) ([]GetStaticRecordsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getStaticRecords)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetStaticRecordsRow
|
||||
for rows.Next() {
|
||||
var i GetStaticRecordsRow
|
||||
if err := rows.Scan(&i.RecordID, &i.RecordName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const initSchema = `-- name: InitSchema :exec
|
||||
CREATE TABLE IF NOT EXISTS config (
|
||||
api_token TEXT NOT NULL DEFAULT '',
|
||||
|
|
@ -70,6 +118,26 @@ func (q *Queries) InsertConfig(ctx context.Context, arg InsertConfigParams) erro
|
|||
return err
|
||||
}
|
||||
|
||||
const isStaticRecord = `-- name: IsStaticRecord :one
|
||||
SELECT CAST(EXISTS(SELECT 1 FROM static_records WHERE record_id = ?) AS BOOLEAN) AS is_static
|
||||
`
|
||||
|
||||
func (q *Queries) IsStaticRecord(ctx context.Context, recordID string) (bool, error) {
|
||||
row := q.db.QueryRowContext(ctx, isStaticRecord, recordID)
|
||||
var is_static bool
|
||||
err := row.Scan(&is_static)
|
||||
return is_static, err
|
||||
}
|
||||
|
||||
const removeStaticRecord = `-- name: RemoveStaticRecord :exec
|
||||
DELETE FROM static_records WHERE record_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) RemoveStaticRecord(ctx context.Context, recordID string) error {
|
||||
_, err := q.db.ExecContext(ctx, removeStaticRecord, recordID)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertConfig = `-- name: UpsertConfig :exec
|
||||
INSERT INTO config (api_token, zone_id, domain, update_period)
|
||||
VALUES (?, ?, ?, ?)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue