- Replace Create+Get+Update with UpsertGame/UpsertSnakeGame queries - Extract free functions (saveGame, loadGame, etc.) from duplicated receiver methods on Store and Instance types - Remove duplicate generateID from snake package, reuse game.GenerateID - Throttle snake game DB writes to every 2s instead of every tick - Fix double-lock in c4game chat handler - Update all code for sqlc pointer types (*string instead of sql.NullString)
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (id, username, password_hash)
|
|
VALUES (?, ?, ?)
|
|
RETURNING id, username, password_hash, created_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
ID string `db:"id" json:"id"`
|
|
Username string `db:"username" json:"username"`
|
|
PasswordHash string `db:"password_hash" json:"password_hash"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (*User, error) {
|
|
row := q.db.QueryRowContext(ctx, createUser, arg.ID, arg.Username, arg.PasswordHash)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, username, password_hash, created_at FROM users WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id string) (*User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
SELECT id, username, password_hash, created_at FROM users WHERE username = ?
|
|
`
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (*User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByUsername, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.CreatedAt,
|
|
)
|
|
return &i, err
|
|
}
|