115 lines
2.7 KiB
Go
115 lines
2.7 KiB
Go
// 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
|
|
}
|