batman
This commit is contained in:
commit
682f25edcd
19 changed files with 1907 additions and 0 deletions
68
db/queries.sql.go
Normal file
68
db/queries.sql.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
// source: queries.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getConfig = `-- name: GetConfig :one
|
||||
SELECT api_token, zone_id, domain, update_period FROM config LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetConfig(ctx context.Context) (Config, error) {
|
||||
row := q.db.QueryRowContext(ctx, getConfig)
|
||||
var i Config
|
||||
err := row.Scan(
|
||||
&i.ApiToken,
|
||||
&i.ZoneID,
|
||||
&i.Domain,
|
||||
&i.UpdatePeriod,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const initSchema = `-- name: InitSchema :exec
|
||||
CREATE TABLE IF NOT EXISTS config (
|
||||
api_token TEXT,
|
||||
zone_id TEXT,
|
||||
domain TEXT NOT NULL DEFAULT 'mz.uy',
|
||||
update_period TEXT NOT NULL DEFAULT '0 */6 * * *'
|
||||
)
|
||||
`
|
||||
|
||||
// This query is used to ensure the schema is set up properly
|
||||
func (q *Queries) InitSchema(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, initSchema)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertConfig = `-- name: UpsertConfig :exec
|
||||
INSERT INTO config (api_token, zone_id, domain, update_period)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT DO UPDATE SET
|
||||
api_token = excluded.api_token,
|
||||
zone_id = excluded.zone_id,
|
||||
domain = excluded.domain,
|
||||
update_period = excluded.update_period
|
||||
`
|
||||
|
||||
type UpsertConfigParams struct {
|
||||
ApiToken string `json:"api_token"`
|
||||
ZoneID string `json:"zone_id"`
|
||||
Domain string `json:"domain"`
|
||||
UpdatePeriod string `json:"update_period"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertConfig(ctx context.Context, arg UpsertConfigParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertConfig,
|
||||
arg.ApiToken,
|
||||
arg.ZoneID,
|
||||
arg.Domain,
|
||||
arg.UpdatePeriod,
|
||||
)
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue