feat(store): sqlc-запросы, dto TemplateDoc, Repository, интеграционные тесты CRUD
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: accounts.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAccount = `-- name: CreateAccount :one
|
||||
INSERT INTO provider_accounts (id, project_id, provider, secret_enc, comment)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, project_id, provider, secret_enc, comment, created_at
|
||||
`
|
||||
|
||||
type CreateAccountParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Provider string `json:"provider"`
|
||||
SecretEnc string `json:"secret_enc"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (ProviderAccount, error) {
|
||||
row := q.db.QueryRow(ctx, createAccount,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.Provider,
|
||||
arg.SecretEnc,
|
||||
arg.Comment,
|
||||
)
|
||||
var i ProviderAccount
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Provider,
|
||||
&i.SecretEnc,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAccount = `-- name: DeleteAccount :exec
|
||||
DELETE FROM provider_accounts WHERE id = $1 AND project_id = $2
|
||||
`
|
||||
|
||||
type DeleteAccountParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteAccount(ctx context.Context, arg DeleteAccountParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteAccount, arg.ID, arg.ProjectID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAccount = `-- name: GetAccount :one
|
||||
SELECT id, project_id, provider, secret_enc, comment, created_at FROM provider_accounts WHERE id = $1 AND project_id = $2
|
||||
`
|
||||
|
||||
type GetAccountParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAccount(ctx context.Context, arg GetAccountParams) (ProviderAccount, error) {
|
||||
row := q.db.QueryRow(ctx, getAccount, arg.ID, arg.ProjectID)
|
||||
var i ProviderAccount
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Provider,
|
||||
&i.SecretEnc,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAccounts = `-- name: ListAccounts :many
|
||||
SELECT id, project_id, provider, secret_enc, comment, created_at FROM provider_accounts WHERE project_id = $1 ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ListAccounts(ctx context.Context, projectID pgtype.UUID) ([]ProviderAccount, error) {
|
||||
rows, err := q.db.Query(ctx, listAccounts, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ProviderAccount
|
||||
for rows.Next() {
|
||||
var i ProviderAccount
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Provider,
|
||||
&i.SecretEnc,
|
||||
&i.Comment,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: check_runs.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createCheckRun = `-- name: CreateCheckRun :one
|
||||
INSERT INTO check_runs (id, domain_id, result)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, domain_id, result, created_at
|
||||
`
|
||||
|
||||
type CreateCheckRunParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
DomainID pgtype.UUID `json:"domain_id"`
|
||||
Result []byte `json:"result"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCheckRun(ctx context.Context, arg CreateCheckRunParams) (CheckRun, error) {
|
||||
row := q.db.QueryRow(ctx, createCheckRun, arg.ID, arg.DomainID, arg.Result)
|
||||
var i CheckRun
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DomainID,
|
||||
&i.Result,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: domains.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
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 pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
ProviderAccountID pgtype.UUID `json:"provider_account_id"`
|
||||
ZoneName string `json:"zone_name"`
|
||||
ZoneID string `json:"zone_id"`
|
||||
TemplateID pgtype.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 pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.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 pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.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 pgtype.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
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
dto "github.com/vasyakrg/dns-autoresolver/internal/store/dto"
|
||||
)
|
||||
|
||||
type CheckRun struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
DomainID pgtype.UUID `json:"domain_id"`
|
||||
Result []byte `json:"result"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
ProviderAccountID pgtype.UUID `json:"provider_account_id"`
|
||||
ZoneName string `json:"zone_name"`
|
||||
ZoneID string `json:"zone_id"`
|
||||
TemplateID pgtype.UUID `json:"template_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type ProviderAccount struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Provider string `json:"provider"`
|
||||
SecretEnc string `json:"secret_enc"`
|
||||
Comment string `json:"comment"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Name string `json:"name"`
|
||||
Doc *dto.TemplateDoc `json:"doc"`
|
||||
Version int32 `json:"version"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: templates.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
dto "github.com/vasyakrg/dns-autoresolver/internal/store/dto"
|
||||
)
|
||||
|
||||
const createTemplate = `-- name: CreateTemplate :one
|
||||
INSERT INTO templates (id, project_id, name, doc, version)
|
||||
VALUES ($1, $2, $3, $4, 1)
|
||||
RETURNING id, project_id, name, doc, version, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateTemplateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Name string `json:"name"`
|
||||
Doc *dto.TemplateDoc `json:"doc"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTemplate(ctx context.Context, arg CreateTemplateParams) (Template, error) {
|
||||
row := q.db.QueryRow(ctx, createTemplate,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.Name,
|
||||
arg.Doc,
|
||||
)
|
||||
var i Template
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Name,
|
||||
&i.Doc,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteTemplate = `-- name: DeleteTemplate :exec
|
||||
DELETE FROM templates WHERE id = $1 AND project_id = $2
|
||||
`
|
||||
|
||||
type DeleteTemplateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteTemplate(ctx context.Context, arg DeleteTemplateParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteTemplate, arg.ID, arg.ProjectID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getTemplate = `-- name: GetTemplate :one
|
||||
SELECT id, project_id, name, doc, version, created_at, updated_at FROM templates WHERE id = $1 AND project_id = $2
|
||||
`
|
||||
|
||||
type GetTemplateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetTemplate(ctx context.Context, arg GetTemplateParams) (Template, error) {
|
||||
row := q.db.QueryRow(ctx, getTemplate, arg.ID, arg.ProjectID)
|
||||
var i Template
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Name,
|
||||
&i.Doc,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listTemplates = `-- name: ListTemplates :many
|
||||
SELECT id, project_id, name, doc, version, created_at, updated_at FROM templates WHERE project_id = $1 ORDER BY created_at
|
||||
`
|
||||
|
||||
func (q *Queries) ListTemplates(ctx context.Context, projectID pgtype.UUID) ([]Template, error) {
|
||||
rows, err := q.db.Query(ctx, listTemplates, projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Template
|
||||
for rows.Next() {
|
||||
var i Template
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Name,
|
||||
&i.Doc,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateTemplate = `-- name: UpdateTemplate :one
|
||||
UPDATE templates
|
||||
SET name = $3, doc = $4, version = version + 1, updated_at = now()
|
||||
WHERE id = $1 AND project_id = $2
|
||||
RETURNING id, project_id, name, doc, version, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateTemplateParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
ProjectID pgtype.UUID `json:"project_id"`
|
||||
Name string `json:"name"`
|
||||
Doc *dto.TemplateDoc `json:"doc"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTemplate(ctx context.Context, arg UpdateTemplateParams) (Template, error) {
|
||||
row := q.db.QueryRow(ctx, updateTemplate,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.Name,
|
||||
arg.Doc,
|
||||
)
|
||||
var i Template
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.Name,
|
||||
&i.Doc,
|
||||
&i.Version,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user