Never gonna let you down

This commit is contained in:
2023-08-07 20:38:50 -04:00
parent ca56ca7b29
commit 04ebe9e855
4 changed files with 166 additions and 8 deletions

View File

@@ -10,6 +10,33 @@ import (
"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
@@ -146,3 +173,18 @@ func (q *Queries) InsertGun(ctx context.Context, arg InsertGunParams) (int64, er
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
}