go-project-template/db/example.sql.go

64 lines
1.3 KiB
Go
Raw Normal View History

2024-05-05 22:10:32 +00:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: example.sql
package db
import (
"context"
)
const exampleCreate = `-- name: ExampleCreate :exec
INSERT INTO example (name) VALUES ($1)
`
func (q *Queries) ExampleCreate(ctx context.Context, name string) error {
_, err := q.db.Exec(ctx, exampleCreate, name)
return err
}
const exampleDelete = `-- name: ExampleDelete :exec
DELETE FROM example WHERE id = $1
`
func (q *Queries) ExampleDelete(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, exampleDelete, id)
return err
}
const exampleGetAll = `-- name: ExampleGetAll :many
SELECT id, name FROM example
`
func (q *Queries) ExampleGetAll(ctx context.Context) ([]Example, error) {
rows, err := q.db.Query(ctx, exampleGetAll)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Example
for rows.Next() {
var i Example
if err := rows.Scan(&i.ID, &i.Name); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const exampleGetByID = `-- name: ExampleGetByID :one
SELECT id, name FROM example WHERE id = $1
`
func (q *Queries) ExampleGetByID(ctx context.Context, id int64) (Example, error) {
row := q.db.QueryRow(ctx, exampleGetByID, id)
var i Example
err := row.Scan(&i.ID, &i.Name)
return i, err
}