generated from VLADIMIR/template
clear
This commit is contained in:
@@ -29,12 +29,30 @@ func New(pool *pgxpool.Pool) *Repo {
|
|||||||
func (r *Repo) Ensure(ctx context.Context, gameID int, kind string, itemID int) error {
|
func (r *Repo) Ensure(ctx context.Context, gameID int, kind string, itemID int) error {
|
||||||
_, err := r.pool.Exec(ctx, `
|
_, err := r.pool.Exec(ctx, `
|
||||||
INSERT INTO game_map_items (game_id, kind, item_id)
|
INSERT INTO game_map_items (game_id, kind, item_id)
|
||||||
VALUES ($1, $2, $3) ON CONFLICT (game_id, kind, item_id) DO NOTHING`, gameID, kind, itemID)
|
VALUES ($1, $2, $3)
|
||||||
|
ON CONFLICT (game_id, kind, item_id) DO NOTHING`,
|
||||||
|
gameID,
|
||||||
|
kind,
|
||||||
|
itemID,
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) List(ctx context.Context, gameID int) ([]Item, error) {
|
func (r *Repo) List(ctx context.Context, gameID int) ([]Item, error) {
|
||||||
rows, err := r.pool.Query(ctx, `SELECT game_id, kind, item_id, x, y, hidden FROM game_map_items WHERE game_id = $1 ORDER BY kind, item_id`, gameID)
|
rows, err := r.pool.Query(
|
||||||
|
ctx,
|
||||||
|
`SELECT
|
||||||
|
game_id,
|
||||||
|
kind,
|
||||||
|
item_id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
hidden
|
||||||
|
FROM game_map_items
|
||||||
|
WHERE game_id = $1
|
||||||
|
ORDER BY kind, item_id`,
|
||||||
|
gameID,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -51,7 +69,23 @@ func (r *Repo) List(ctx context.Context, gameID int) ([]Item, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) Update(ctx context.Context, item Item) error {
|
func (r *Repo) Update(ctx context.Context, item Item) error {
|
||||||
result, err := r.pool.Exec(ctx, `UPDATE game_map_items SET x = $4, y = $5, hidden = $6 WHERE game_id = $1 AND kind = $2 AND item_id = $3`, item.GameID, item.Kind, item.ItemID, item.X, item.Y, item.Hidden)
|
result, err := r.pool.Exec(
|
||||||
|
ctx,
|
||||||
|
`UPDATE game_map_items
|
||||||
|
SET
|
||||||
|
x = $4,
|
||||||
|
y = $5,
|
||||||
|
hidden = $6
|
||||||
|
WHERE game_id = $1
|
||||||
|
AND kind = $2
|
||||||
|
AND item_id = $3`,
|
||||||
|
item.GameID,
|
||||||
|
item.Kind,
|
||||||
|
item.ItemID,
|
||||||
|
item.X,
|
||||||
|
item.Y,
|
||||||
|
item.Hidden,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -62,6 +96,15 @@ func (r *Repo) Update(ctx context.Context, item Item) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repo) Delete(ctx context.Context, item Item) error {
|
func (r *Repo) Delete(ctx context.Context, item Item) error {
|
||||||
_, err := r.pool.Exec(ctx, `DELETE FROM game_map_items WHERE game_id = $1 AND kind = $2 AND item_id = $3`, item.GameID, item.Kind, item.ItemID)
|
_, err := r.pool.Exec(
|
||||||
|
ctx,
|
||||||
|
`DELETE FROM game_map_items
|
||||||
|
WHERE game_id = $1
|
||||||
|
AND kind = $2
|
||||||
|
AND item_id = $3`,
|
||||||
|
item.GameID,
|
||||||
|
item.Kind,
|
||||||
|
item.ItemID,
|
||||||
|
)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user