This commit is contained in:
2023-08-07 10:14:38 -04:00
parent a30b1769b3
commit 5dd3fa9451
18 changed files with 548 additions and 276 deletions

148
sql/db/query.sql.go Normal file
View File

@@ -0,0 +1,148 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: query.sql
package db
import (
"context"
"database/sql"
)
const getAllGuns = `-- name: GetAllGuns :many
SELECT id, make, model, value_amount
from guns
order by id desc
`
type GetAllGunsRow struct {
ID int64 `json:"id"`
Make sql.NullString `json:"make"`
Model sql.NullString `json:"model"`
ValueAmount sql.NullInt64 `json:"value_amount"`
}
func (q *Queries) GetAllGuns(ctx context.Context) ([]GetAllGunsRow, error) {
rows, err := q.db.QueryContext(ctx, getAllGuns)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetAllGunsRow
for rows.Next() {
var i GetAllGunsRow
if err := rows.Scan(
&i.ID,
&i.Make,
&i.Model,
&i.ValueAmount,
); 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 getGunById = `-- name: GetGunById :one
SELECT guns.id as id, make, model, serial_number, purchase_amount, value_amount, date_purchased, notes
from guns
where guns.id = ?
`
func (q *Queries) GetGunById(ctx context.Context, id int64) (Gun, error) {
row := q.db.QueryRowContext(ctx, getGunById, id)
var i Gun
err := row.Scan(
&i.ID,
&i.Make,
&i.Model,
&i.SerialNumber,
&i.PurchaseAmount,
&i.ValueAmount,
&i.DatePurchased,
&i.Notes,
)
return i, err
}
const getGunPhotoData = `-- name: GetGunPhotoData :one
select photo from photos where id = ?
`
func (q *Queries) GetGunPhotoData(ctx context.Context, id int64) ([]byte, error) {
row := q.db.QueryRowContext(ctx, getGunPhotoData, id)
var photo []byte
err := row.Scan(&photo)
return photo, err
}
const getGunPhotos = `-- name: GetGunPhotos :many
SELECT id, filename from photos where gun_id = ?
`
type GetGunPhotosRow struct {
ID int64 `json:"id"`
Filename sql.NullString `json:"filename"`
}
func (q *Queries) GetGunPhotos(ctx context.Context, gunID sql.NullInt64) ([]GetGunPhotosRow, error) {
rows, err := q.db.QueryContext(ctx, getGunPhotos, gunID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetGunPhotosRow
for rows.Next() {
var i GetGunPhotosRow
if err := rows.Scan(&i.ID, &i.Filename); 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 insertGun = `-- name: InsertGun :one
INSERT into guns
(make, model, serial_number, purchase_amount, value_amount, date_purchased, notes) VALUES
(?, ?, ?, ?, ?, ?, ?) returning id
`
type InsertGunParams struct {
Make sql.NullString `json:"make"`
Model sql.NullString `json:"model"`
SerialNumber sql.NullString `json:"serial_number"`
PurchaseAmount sql.NullInt64 `json:"purchase_amount"`
ValueAmount sql.NullInt64 `json:"value_amount"`
DatePurchased sql.NullString `json:"date_purchased"`
Notes sql.NullString `json:"notes"`
}
func (q *Queries) InsertGun(ctx context.Context, arg InsertGunParams) (int64, error) {
row := q.db.QueryRowContext(ctx, insertGun,
arg.Make,
arg.Model,
arg.SerialNumber,
arg.PurchaseAmount,
arg.ValueAmount,
arg.DatePurchased,
arg.Notes,
)
var id int64
err := row.Scan(&id)
return id, err
}