first commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.13.0
|
||||
|
||||
package mysqlgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
|
||||
q := Queries{db: db}
|
||||
var err error
|
||||
if q.deleteTagStmt, err = db.PrepareContext(ctx, deleteTag); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query DeleteTag: %w", err)
|
||||
}
|
||||
if q.findTagStmt, err = db.PrepareContext(ctx, findTag); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query FindTag: %w", err)
|
||||
}
|
||||
if q.listListedTagsStmt, err = db.PrepareContext(ctx, listListedTags); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListListedTags: %w", err)
|
||||
}
|
||||
if q.listTagsStmt, err = db.PrepareContext(ctx, listTags); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ListTags: %w", err)
|
||||
}
|
||||
if q.replaceTagStmt, err = db.PrepareContext(ctx, replaceTag); err != nil {
|
||||
return nil, fmt.Errorf("error preparing query ReplaceTag: %w", err)
|
||||
}
|
||||
return &q, nil
|
||||
}
|
||||
|
||||
func (q *Queries) Close() error {
|
||||
var err error
|
||||
if q.deleteTagStmt != nil {
|
||||
if cerr := q.deleteTagStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing deleteTagStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.findTagStmt != nil {
|
||||
if cerr := q.findTagStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing findTagStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listListedTagsStmt != nil {
|
||||
if cerr := q.listListedTagsStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listListedTagsStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.listTagsStmt != nil {
|
||||
if cerr := q.listTagsStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing listTagsStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
if q.replaceTagStmt != nil {
|
||||
if cerr := q.replaceTagStmt.Close(); cerr != nil {
|
||||
err = fmt.Errorf("error closing replaceTagStmt: %w", cerr)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.ExecContext(ctx, args...)
|
||||
default:
|
||||
return q.db.ExecContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) *sql.Row {
|
||||
switch {
|
||||
case stmt != nil && q.tx != nil:
|
||||
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)
|
||||
case stmt != nil:
|
||||
return stmt.QueryRowContext(ctx, args...)
|
||||
default:
|
||||
return q.db.QueryRowContext(ctx, query, args...)
|
||||
}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
tx *sql.Tx
|
||||
deleteTagStmt *sql.Stmt
|
||||
findTagStmt *sql.Stmt
|
||||
listListedTagsStmt *sql.Stmt
|
||||
listTagsStmt *sql.Stmt
|
||||
replaceTagStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
tx: tx,
|
||||
deleteTagStmt: q.deleteTagStmt,
|
||||
findTagStmt: q.findTagStmt,
|
||||
listListedTagsStmt: q.listListedTagsStmt,
|
||||
listTagsStmt: q.listTagsStmt,
|
||||
replaceTagStmt: q.replaceTagStmt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.13.0
|
||||
|
||||
package mysqlgen
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
ID string
|
||||
ParentID sql.NullString
|
||||
OwnerID string
|
||||
Name string
|
||||
Kind int
|
||||
Description string
|
||||
Listed bool
|
||||
Secret bool
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.13.0
|
||||
// source: tag.sql
|
||||
|
||||
package mysqlgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const deleteTag = `-- name: DeleteTag :exec
|
||||
DELETE FROM tag WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteTag(ctx context.Context, id string) error {
|
||||
_, err := q.exec(ctx, q.deleteTagStmt, deleteTag, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const findTag = `-- name: FindTag :one
|
||||
SELECT id, parent_id, owner_id, name, kind, description, listed, secret
|
||||
FROM tag
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) FindTag(ctx context.Context, id string) (Tag, error) {
|
||||
row := q.queryRow(ctx, q.findTagStmt, findTag, id)
|
||||
var i Tag
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ParentID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Kind,
|
||||
&i.Description,
|
||||
&i.Listed,
|
||||
&i.Secret,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listListedTags = `-- name: ListListedTags :many
|
||||
SELECT id, parent_id, owner_id, name, kind, description, listed, secret
|
||||
FROM tag
|
||||
WHERE listed = 1
|
||||
`
|
||||
|
||||
func (q *Queries) ListListedTags(ctx context.Context) ([]Tag, error) {
|
||||
rows, err := q.query(ctx, q.listListedTagsStmt, listListedTags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Tag{}
|
||||
for rows.Next() {
|
||||
var i Tag
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ParentID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Kind,
|
||||
&i.Description,
|
||||
&i.Listed,
|
||||
&i.Secret,
|
||||
); 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 listTags = `-- name: ListTags :many
|
||||
SELECT id, parent_id, owner_id, name, kind, description, listed, secret
|
||||
FROM tag
|
||||
`
|
||||
|
||||
func (q *Queries) ListTags(ctx context.Context) ([]Tag, error) {
|
||||
rows, err := q.query(ctx, q.listTagsStmt, listTags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Tag{}
|
||||
for rows.Next() {
|
||||
var i Tag
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ParentID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Kind,
|
||||
&i.Description,
|
||||
&i.Listed,
|
||||
&i.Secret,
|
||||
); 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 replaceTag = `-- name: ReplaceTag :exec
|
||||
REPLACE INTO tag (id, parent_id, owner_id, name, kind, description, listed, secret)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`
|
||||
|
||||
type ReplaceTagParams struct {
|
||||
ID string
|
||||
ParentID sql.NullString
|
||||
OwnerID string
|
||||
Name string
|
||||
Kind int
|
||||
Description string
|
||||
Listed bool
|
||||
Secret bool
|
||||
}
|
||||
|
||||
func (q *Queries) ReplaceTag(ctx context.Context, arg ReplaceTagParams) error {
|
||||
_, err := q.exec(ctx, q.replaceTagStmt, replaceTag,
|
||||
arg.ID,
|
||||
arg.ParentID,
|
||||
arg.OwnerID,
|
||||
arg.Name,
|
||||
arg.Kind,
|
||||
arg.Description,
|
||||
arg.Listed,
|
||||
arg.Secret,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user