121 lines
2.4 KiB
Go
121 lines
2.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: states.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createState = `-- name: CreateState :execresult
|
|
INSERT INTO states (
|
|
name, shortform, enqform
|
|
) VALUES (
|
|
?, ?, ?
|
|
)
|
|
`
|
|
|
|
type CreateStateParams struct {
|
|
Name string `json:"name"`
|
|
Shortform sql.NullString `json:"shortform"`
|
|
Enqform sql.NullString `json:"enqform"`
|
|
}
|
|
|
|
func (q *Queries) CreateState(ctx context.Context, arg CreateStateParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createState, arg.Name, arg.Shortform, arg.Enqform)
|
|
}
|
|
|
|
const deleteState = `-- name: DeleteState :exec
|
|
DELETE FROM states
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteState(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteState, id)
|
|
return err
|
|
}
|
|
|
|
const getState = `-- name: GetState :one
|
|
SELECT id, name, shortform, enqform FROM states
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetState(ctx context.Context, id int32) (State, error) {
|
|
row := q.db.QueryRowContext(ctx, getState, id)
|
|
var i State
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Shortform,
|
|
&i.Enqform,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listStates = `-- name: ListStates :many
|
|
SELECT id, name, shortform, enqform FROM states
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListStatesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListStates(ctx context.Context, arg ListStatesParams) ([]State, error) {
|
|
rows, err := q.db.QueryContext(ctx, listStates, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []State{}
|
|
for rows.Next() {
|
|
var i State
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Shortform,
|
|
&i.Enqform,
|
|
); 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 updateState = `-- name: UpdateState :exec
|
|
UPDATE states
|
|
SET name = ?,
|
|
shortform = ?,
|
|
enqform = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateStateParams struct {
|
|
Name string `json:"name"`
|
|
Shortform sql.NullString `json:"shortform"`
|
|
Enqform sql.NullString `json:"enqform"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateState(ctx context.Context, arg UpdateStateParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateState,
|
|
arg.Name,
|
|
arg.Shortform,
|
|
arg.Enqform,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|