add games sql
This commit is contained in:
@@ -57,12 +57,35 @@ func (db *DatabasePostgreSQL) GetGameById(id string) (*model.Game, error) {
|
|||||||
return &game, err
|
return &game, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DatabasePostgreSQL) CreateGame(*model.Game) error {
|
func (db *DatabasePostgreSQL) CreateGame(game *model.Game) error {
|
||||||
return nil
|
q := `
|
||||||
|
INSERT INTO public.game
|
||||||
|
(server_id, user_id)
|
||||||
|
VALUES
|
||||||
|
($1, $2)
|
||||||
|
RETURNING id, created_at
|
||||||
|
`
|
||||||
|
|
||||||
|
err := db.session.
|
||||||
|
QueryRow(q, game.Server.ID, game.User.ID).
|
||||||
|
Scan(&game.ID, &game.CreatedAt)
|
||||||
|
if errPq, ok := err.(*pq.Error); ok {
|
||||||
|
return handlePgError(errPq)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DatabasePostgreSQL) DeleteGame(string) error {
|
func (db *DatabasePostgreSQL) DeleteGame(id string) error {
|
||||||
return nil
|
q := `
|
||||||
|
DELETE FROM public.game
|
||||||
|
WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
_, err := db.session.Exec(q, id)
|
||||||
|
if errPq, ok := err.(*pq.Error); ok {
|
||||||
|
return handlePgError(errPq)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DatabasePostgreSQL) UpdateGame(*model.Game) error {
|
func (db *DatabasePostgreSQL) UpdateGame(*model.Game) error {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (db *DatabasePostgreSQL) CreateUser(user *model.User) error {
|
|||||||
INSERT INTO public.user
|
INSERT INTO public.user
|
||||||
(nickname, google_id)
|
(nickname, google_id)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3)
|
($1, $2)
|
||||||
RETURNING id, created_at
|
RETURNING id, created_at
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user