119 lines
2.6 KiB
Go
119 lines
2.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: countries.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createCountry = `-- name: CreateCountry :execresult
|
|
INSERT INTO countries (name) VALUES (?)
|
|
`
|
|
|
|
func (q *Queries) CreateCountry(ctx context.Context, name string) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createCountry, name)
|
|
}
|
|
|
|
const deleteCountry = `-- name: DeleteCountry :exec
|
|
DELETE FROM countries WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteCountry(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteCountry, id)
|
|
return err
|
|
}
|
|
|
|
const getCountry = `-- name: GetCountry :one
|
|
SELECT id, name FROM countries
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetCountry(ctx context.Context, id int32) (Country, error) {
|
|
row := q.db.QueryRowContext(ctx, getCountry, id)
|
|
var i Country
|
|
err := row.Scan(&i.ID, &i.Name)
|
|
return i, err
|
|
}
|
|
|
|
const listCountries = `-- name: ListCountries :many
|
|
SELECT id, name FROM countries
|
|
ORDER BY name
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListCountriesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListCountries(ctx context.Context, arg ListCountriesParams) ([]Country, error) {
|
|
rows, err := q.db.QueryContext(ctx, listCountries, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Country{}
|
|
for rows.Next() {
|
|
var i Country
|
|
if err := rows.Scan(&i.ID, &i.Name); 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 searchCountriesByName = `-- name: SearchCountriesByName :many
|
|
SELECT id, name FROM countries
|
|
WHERE name LIKE CONCAT('%', ?, '%')
|
|
ORDER BY name
|
|
LIMIT 10
|
|
`
|
|
|
|
func (q *Queries) SearchCountriesByName(ctx context.Context, concat interface{}) ([]Country, error) {
|
|
rows, err := q.db.QueryContext(ctx, searchCountriesByName, concat)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Country{}
|
|
for rows.Next() {
|
|
var i Country
|
|
if err := rows.Scan(&i.ID, &i.Name); 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 updateCountry = `-- name: UpdateCountry :exec
|
|
UPDATE countries SET name = ? WHERE id = ?
|
|
`
|
|
|
|
type UpdateCountryParams struct {
|
|
Name string `json:"name"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCountry(ctx context.Context, arg UpdateCountryParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateCountry, arg.Name, arg.ID)
|
|
return err
|
|
}
|