// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.20.0 // source: query.sql package db import ( "context" "database/sql" ) const deleteGun = `-- name: DeleteGun :exec DELETE from guns where id = ? ` func (q *Queries) DeleteGun(ctx context.Context, id int64) error { _, err := q.db.ExecContext(ctx, deleteGun, id) return err } const deleteGunPhotosByGunId = `-- name: DeleteGunPhotosByGunId :exec DELETE FROM photos where gun_id = ? ` func (q *Queries) DeleteGunPhotosByGunId(ctx context.Context, gunID sql.NullInt64) error { _, err := q.db.ExecContext(ctx, deleteGunPhotosByGunId, gunID) return err } const deleteGunPhotosById = `-- name: DeleteGunPhotosById :exec DELETE FROM photos where id = ? ` func (q *Queries) DeleteGunPhotosById(ctx context.Context, id int64) error { _, err := q.db.ExecContext(ctx, deleteGunPhotosById, id) return err } 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 } const insertGunPhoto = `-- name: InsertGunPhoto :exec INSERT into photos (gun_id, photo, filename) values (?, ?, ?) ` type InsertGunPhotoParams struct { GunID sql.NullInt64 `json:"gun_id"` Photo []byte `json:"photo"` Filename sql.NullString `json:"filename"` } func (q *Queries) InsertGunPhoto(ctx context.Context, arg InsertGunPhotoParams) error { _, err := q.db.ExecContext(ctx, insertGunPhoto, arg.GunID, arg.Photo, arg.Filename) return err } const updateGun = `-- name: UpdateGun :exec UPDATE guns set make = ?, model = ?, serial_number = ?, purchase_amount = ?, value_amount = ?, date_purchased = ?, notes = ? where id = ? ` type UpdateGunParams 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"` ID int64 `json:"id"` } func (q *Queries) UpdateGun(ctx context.Context, arg UpdateGunParams) error { _, err := q.db.ExecContext(ctx, updateGun, arg.Make, arg.Model, arg.SerialNumber, arg.PurchaseAmount, arg.ValueAmount, arg.DatePurchased, arg.Notes, arg.ID, ) return err }