| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- // Code generated by sqlc. DO NOT EDIT.
- // versions:
- // sqlc v1.30.0
- // source: records.sql
- package queries
- import (
- "context"
- "time"
- )
- const createRecord = `-- name: CreateRecord :one
- INSERT INTO records (zone_id, cf_record_id, name, type, content, proxied, is_static)
- VALUES (?, ?, ?, ?, ?, ?, ?)
- RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
- `
- type CreateRecordParams struct {
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- }
- func (q *Queries) CreateRecord(ctx context.Context, arg CreateRecordParams) (Record, error) {
- row := q.db.QueryRowContext(ctx, createRecord,
- arg.ZoneID,
- arg.CfRecordID,
- arg.Name,
- arg.Type,
- arg.Content,
- arg.Proxied,
- arg.IsStatic,
- )
- var i Record
- err := row.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- )
- return i, err
- }
- const deleteRecord = `-- name: DeleteRecord :exec
- DELETE FROM records WHERE id = ?
- `
- func (q *Queries) DeleteRecord(ctx context.Context, id int64) error {
- _, err := q.db.ExecContext(ctx, deleteRecord, id)
- return err
- }
- const deleteRecordByCfID = `-- name: DeleteRecordByCfID :exec
- DELETE FROM records WHERE zone_id = ? AND cf_record_id = ?
- `
- type DeleteRecordByCfIDParams struct {
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- }
- func (q *Queries) DeleteRecordByCfID(ctx context.Context, arg DeleteRecordByCfIDParams) error {
- _, err := q.db.ExecContext(ctx, deleteRecordByCfID, arg.ZoneID, arg.CfRecordID)
- return err
- }
- const getRecord = `-- name: GetRecord :one
- SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
- FROM records r
- JOIN zones z ON z.id = r.zone_id
- WHERE r.id = ?
- `
- type GetRecordRow struct {
- ID int64 `json:"id"`
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- CfZoneID string `json:"cf_zone_id"`
- ZoneName string `json:"zone_name"`
- }
- func (q *Queries) GetRecord(ctx context.Context, id int64) (GetRecordRow, error) {
- row := q.db.QueryRowContext(ctx, getRecord, id)
- var i GetRecordRow
- err := row.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- &i.CfZoneID,
- &i.ZoneName,
- )
- return i, err
- }
- const listNonStaticRecords = `-- name: ListNonStaticRecords :many
- SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.api_key as zone_api_key
- FROM records r
- JOIN zones z ON z.id = r.zone_id
- WHERE r.is_static = 0
- `
- type ListNonStaticRecordsRow struct {
- ID int64 `json:"id"`
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- CfZoneID string `json:"cf_zone_id"`
- ZoneApiKey string `json:"zone_api_key"`
- }
- func (q *Queries) ListNonStaticRecords(ctx context.Context) ([]ListNonStaticRecordsRow, error) {
- rows, err := q.db.QueryContext(ctx, listNonStaticRecords)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- var items []ListNonStaticRecordsRow
- for rows.Next() {
- var i ListNonStaticRecordsRow
- if err := rows.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- &i.CfZoneID,
- &i.ZoneApiKey,
- ); 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 listRecordCfIDsByZone = `-- name: ListRecordCfIDsByZone :many
- SELECT cf_record_id FROM records WHERE zone_id = ?
- `
- func (q *Queries) ListRecordCfIDsByZone(ctx context.Context, zoneID int64) ([]string, error) {
- rows, err := q.db.QueryContext(ctx, listRecordCfIDsByZone, zoneID)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- var items []string
- for rows.Next() {
- var cf_record_id string
- if err := rows.Scan(&cf_record_id); err != nil {
- return nil, err
- }
- items = append(items, cf_record_id)
- }
- if err := rows.Close(); err != nil {
- return nil, err
- }
- if err := rows.Err(); err != nil {
- return nil, err
- }
- return items, nil
- }
- const listRecords = `-- name: ListRecords :many
- SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
- FROM records r
- JOIN zones z ON z.id = r.zone_id
- ORDER BY r.name
- `
- type ListRecordsRow struct {
- ID int64 `json:"id"`
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- CfZoneID string `json:"cf_zone_id"`
- ZoneName string `json:"zone_name"`
- }
- func (q *Queries) ListRecords(ctx context.Context) ([]ListRecordsRow, error) {
- rows, err := q.db.QueryContext(ctx, listRecords)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- var items []ListRecordsRow
- for rows.Next() {
- var i ListRecordsRow
- if err := rows.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- &i.CfZoneID,
- &i.ZoneName,
- ); 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 listRecordsByZone = `-- name: ListRecordsByZone :many
- SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
- FROM records r
- JOIN zones z ON z.id = r.zone_id
- WHERE r.zone_id = ?
- ORDER BY r.name
- `
- type ListRecordsByZoneRow struct {
- ID int64 `json:"id"`
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- CfZoneID string `json:"cf_zone_id"`
- ZoneName string `json:"zone_name"`
- }
- func (q *Queries) ListRecordsByZone(ctx context.Context, zoneID int64) ([]ListRecordsByZoneRow, error) {
- rows, err := q.db.QueryContext(ctx, listRecordsByZone, zoneID)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
- var items []ListRecordsByZoneRow
- for rows.Next() {
- var i ListRecordsByZoneRow
- if err := rows.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- &i.CfZoneID,
- &i.ZoneName,
- ); 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 updateRecord = `-- name: UpdateRecord :one
- UPDATE records
- SET name = ?, type = ?, content = ?, proxied = ?, is_static = ?, updated_at = CURRENT_TIMESTAMP
- WHERE id = ?
- RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
- `
- type UpdateRecordParams struct {
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- ID int64 `json:"id"`
- }
- func (q *Queries) UpdateRecord(ctx context.Context, arg UpdateRecordParams) (Record, error) {
- row := q.db.QueryRowContext(ctx, updateRecord,
- arg.Name,
- arg.Type,
- arg.Content,
- arg.Proxied,
- arg.IsStatic,
- arg.ID,
- )
- var i Record
- err := row.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- )
- return i, err
- }
- const updateRecordContent = `-- name: UpdateRecordContent :exec
- UPDATE records
- SET content = ?, updated_at = CURRENT_TIMESTAMP
- WHERE id = ?
- `
- type UpdateRecordContentParams struct {
- Content string `json:"content"`
- ID int64 `json:"id"`
- }
- func (q *Queries) UpdateRecordContent(ctx context.Context, arg UpdateRecordContentParams) error {
- _, err := q.db.ExecContext(ctx, updateRecordContent, arg.Content, arg.ID)
- return err
- }
- const upsertRecord = `-- name: UpsertRecord :one
- INSERT INTO records (zone_id, cf_record_id, name, type, content, proxied, is_static)
- VALUES (?, ?, ?, ?, ?, ?, ?)
- ON CONFLICT(zone_id, cf_record_id) DO UPDATE SET
- name = excluded.name,
- type = excluded.type,
- content = excluded.content,
- proxied = excluded.proxied,
- updated_at = CURRENT_TIMESTAMP
- RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
- `
- type UpsertRecordParams struct {
- ZoneID int64 `json:"zone_id"`
- CfRecordID string `json:"cf_record_id"`
- Name string `json:"name"`
- Type string `json:"type"`
- Content string `json:"content"`
- Proxied int64 `json:"proxied"`
- IsStatic int64 `json:"is_static"`
- }
- func (q *Queries) UpsertRecord(ctx context.Context, arg UpsertRecordParams) (Record, error) {
- row := q.db.QueryRowContext(ctx, upsertRecord,
- arg.ZoneID,
- arg.CfRecordID,
- arg.Name,
- arg.Type,
- arg.Content,
- arg.Proxied,
- arg.IsStatic,
- )
- var i Record
- err := row.Scan(
- &i.ID,
- &i.ZoneID,
- &i.CfRecordID,
- &i.Name,
- &i.Type,
- &i.Content,
- &i.Proxied,
- &i.IsStatic,
- &i.CreatedAt,
- &i.UpdatedAt,
- )
- return i, err
- }
|