Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: query.sql
|
|
|
|
package querytest
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const createItem = `-- name: CreateItem :exec
|
|
INSERT INTO items (name, cap_read)
|
|
VALUES (?, ?)
|
|
`
|
|
|
|
type CreateItemParams struct {
|
|
Name string
|
|
CapRead string
|
|
}
|
|
|
|
// 当新建条目时,需要写入名称和权限
|
|
func (q *Queries) CreateItem(ctx context.Context, arg CreateItemParams) error {
|
|
_, err := q.db.ExecContext(ctx, createItem, arg.Name, arg.CapRead)
|
|
return err
|
|
}
|
|
|
|
const deleteItem = `-- name: DeleteItem :one
|
|
DELETE FROM items WHERE id = ? RETURNING id, name, cap_read
|
|
`
|
|
|
|
func (q *Queries) DeleteItem(ctx context.Context, id int64) (Item, error) {
|
|
row := q.db.QueryRowContext(ctx, deleteItem, id)
|
|
var i Item
|
|
err := row.Scan(&i.ID, &i.Name, &i.CapRead)
|
|
return i, err
|
|
}
|
|
|
|
const listItems = `-- name: ListItems :many
|
|
|
|
SELECT id, name, cap_read
|
|
FROM items
|
|
WHERE cap_read = 'anonymous'
|
|
ORDER BY name
|
|
`
|
|
|
|
// Multi-byte UTF-8 in comments must not shift the byte offsets used to slice
|
|
// query text out of the source file (#4523, #4235, #4372).
|
|
// an em dash right here — must not truncate the ORDER BY below
|
|
func (q *Queries) ListItems(ctx context.Context) ([]Item, error) {
|
|
rows, err := q.db.QueryContext(ctx, listItems)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Item
|
|
for rows.Next() {
|
|
var i Item
|
|
if err := rows.Scan(&i.ID, &i.Name, &i.CapRead); 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 updateItem = `-- name: UpdateItem :exec
|
|
|
|
UPDATE items SET name = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdateItemParams struct {
|
|
Name string
|
|
ID int64
|
|
}
|
|
|
|
// section — divider between queries
|
|
func (q *Queries) UpdateItem(ctx context.Context, arg UpdateItemParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateItem, arg.Name, arg.ID)
|
|
return err
|
|
}
|