148 lines
3.6 KiB
Go
148 lines
3.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: domains.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
dto "github.com/vasyakrg/dns-autoresolver/internal/store/dto"
|
|
)
|
|
|
|
const createDomain = `-- name: CreateDomain :one
|
|
INSERT INTO domains (id, project_id, provider_account_id, zone_name, zone_id, template_id)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at
|
|
`
|
|
|
|
type CreateDomainParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
ProviderAccountID uuid.UUID `json:"provider_account_id"`
|
|
ZoneName string `json:"zone_name"`
|
|
ZoneID string `json:"zone_id"`
|
|
TemplateID *uuid.UUID `json:"template_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateDomain(ctx context.Context, arg CreateDomainParams) (Domain, error) {
|
|
row := q.db.QueryRow(ctx, createDomain,
|
|
arg.ID,
|
|
arg.ProjectID,
|
|
arg.ProviderAccountID,
|
|
arg.ZoneName,
|
|
arg.ZoneID,
|
|
arg.TemplateID,
|
|
)
|
|
var i Domain
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.ProviderAccountID,
|
|
&i.ZoneName,
|
|
&i.ZoneID,
|
|
&i.TemplateID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteDomain = `-- name: DeleteDomain :exec
|
|
DELETE FROM domains WHERE id = $1 AND project_id = $2
|
|
`
|
|
|
|
type DeleteDomainParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteDomain(ctx context.Context, arg DeleteDomainParams) error {
|
|
_, err := q.db.Exec(ctx, deleteDomain, arg.ID, arg.ProjectID)
|
|
return err
|
|
}
|
|
|
|
const getDomain = `-- name: GetDomain :one
|
|
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at FROM domains WHERE id = $1 AND project_id = $2
|
|
`
|
|
|
|
type GetDomainParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
}
|
|
|
|
func (q *Queries) GetDomain(ctx context.Context, arg GetDomainParams) (Domain, error) {
|
|
row := q.db.QueryRow(ctx, getDomain, arg.ID, arg.ProjectID)
|
|
var i Domain
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.ProviderAccountID,
|
|
&i.ZoneName,
|
|
&i.ZoneID,
|
|
&i.TemplateID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listDomains = `-- name: ListDomains :many
|
|
SELECT id, project_id, provider_account_id, zone_name, zone_id, template_id, created_at FROM domains WHERE project_id = $1 ORDER BY created_at
|
|
`
|
|
|
|
func (q *Queries) ListDomains(ctx context.Context, projectID uuid.UUID) ([]Domain, error) {
|
|
rows, err := q.db.Query(ctx, listDomains, projectID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Domain
|
|
for rows.Next() {
|
|
var i Domain
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.ProviderAccountID,
|
|
&i.ZoneName,
|
|
&i.ZoneID,
|
|
&i.TemplateID,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const loadDomainFull = `-- name: LoadDomainFull :one
|
|
SELECT d.zone_id, a.provider, a.secret_enc, t.doc
|
|
FROM domains d
|
|
JOIN provider_accounts a ON a.id = d.provider_account_id
|
|
LEFT JOIN templates t ON t.id = d.template_id
|
|
WHERE d.id = $1
|
|
`
|
|
|
|
type LoadDomainFullRow struct {
|
|
ZoneID string `json:"zone_id"`
|
|
Provider string `json:"provider"`
|
|
SecretEnc string `json:"secret_enc"`
|
|
Doc *dto.TemplateDoc `json:"doc"`
|
|
}
|
|
|
|
func (q *Queries) LoadDomainFull(ctx context.Context, id uuid.UUID) (LoadDomainFullRow, error) {
|
|
row := q.db.QueryRow(ctx, loadDomainFull, id)
|
|
var i LoadDomainFullRow
|
|
err := row.Scan(
|
|
&i.ZoneID,
|
|
&i.Provider,
|
|
&i.SecretEnc,
|
|
&i.Doc,
|
|
)
|
|
return i, err
|
|
}
|