From 9781fb6736907716fe8f51f651e64a285860026a Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Wed, 21 Jan 2026 18:12:28 -0500 Subject: [PATCH] putting db stuff aside for a bit --- db/models.go | 28 ++++++++++++++-------------- db/querier.go | 31 +++++++++++++++++++++++++++++++ db/query.sql.go | 20 ++++++++++++++++---- sqlc.yaml | 3 +++ 4 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 db/querier.go diff --git a/db/models.go b/db/models.go index 481ea98..0ce44b0 100644 --- a/db/models.go +++ b/db/models.go @@ -9,30 +9,30 @@ import ( ) type Exit struct { - ID int64 - To sql.NullInt64 - From sql.NullInt64 + ID int64 `db:"id" json:"id"` + To sql.NullInt64 `db:"to" json:"to"` + From sql.NullInt64 `db:"from" json:"from"` } type Inventory struct { - ID int64 + ID int64 `db:"id" json:"id"` } type Location struct { - ID int64 - X int64 - Y int64 - Z int64 - World int64 + ID int64 `db:"id" json:"id"` + X int64 `db:"x" json:"x"` + Y int64 `db:"y" json:"y"` + Z int64 `db:"z" json:"z"` + World int64 `db:"world" json:"world"` } type Observable struct { - ID int64 - Name string - Description string + ID int64 `db:"id" json:"id"` + Name string `db:"name" json:"name"` + Description string `db:"description" json:"description"` } type Pool struct { - ID int64 - Type int64 + ID int64 `db:"id" json:"id"` + Type int64 `db:"type" json:"type"` } diff --git a/db/querier.go b/db/querier.go new file mode 100644 index 0000000..a66086e --- /dev/null +++ b/db/querier.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db + +import ( + "context" + "database/sql" +) + +type Querier interface { + //CreateLocation + // + // insert INTO LOCATIONS (x,y,z,world) VALUES (?,?,?,?) + CreateLocation(ctx context.Context, arg CreateLocationParams) error + //GetLocation + // + // select id, x, y, z, world from locations where id = ? LIMIT 1 + GetLocation(ctx context.Context, id int64) (Location, error) + //GetLocationExitsFrom + // + // select id, "to", "from" from exits where from = ? LIMIT 1 + GetLocationExitsFrom(ctx context.Context, from sql.NullInt64) ([]Exit, error) + //GetLocationExitsTo + // + // select id, "to", "from" from exits where to = ? LIMIT 1 + GetLocationExitsTo(ctx context.Context, to sql.NullInt64) ([]Exit, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/db/query.sql.go b/db/query.sql.go index 562ba35..01326e8 100644 --- a/db/query.sql.go +++ b/db/query.sql.go @@ -15,12 +15,15 @@ insert INTO LOCATIONS (x,y,z,world) VALUES (?,?,?,?) ` type CreateLocationParams struct { - X int64 - Y int64 - Z int64 - World int64 + X int64 `db:"x" json:"x"` + Y int64 `db:"y" json:"y"` + Z int64 `db:"z" json:"z"` + World int64 `db:"world" json:"world"` } +// CreateLocation +// +// insert INTO LOCATIONS (x,y,z,world) VALUES (?,?,?,?) func (q *Queries) CreateLocation(ctx context.Context, arg CreateLocationParams) error { _, err := q.db.ExecContext(ctx, createLocation, arg.X, @@ -35,6 +38,9 @@ const getLocation = `-- name: GetLocation :one select id, x, y, z, world from locations where id = ? LIMIT 1 ` +// GetLocation +// +// select id, x, y, z, world from locations where id = ? LIMIT 1 func (q *Queries) GetLocation(ctx context.Context, id int64) (Location, error) { row := q.db.QueryRowContext(ctx, getLocation, id) var i Location @@ -52,6 +58,9 @@ const getLocationExitsFrom = `-- name: GetLocationExitsFrom :many select id, "to", "from" from exits where from = ? LIMIT 1 ` +// GetLocationExitsFrom +// +// select id, "to", "from" from exits where from = ? LIMIT 1 func (q *Queries) GetLocationExitsFrom(ctx context.Context, from sql.NullInt64) ([]Exit, error) { rows, err := q.db.QueryContext(ctx, getLocationExitsFrom, from) if err != nil { @@ -79,6 +88,9 @@ const getLocationExitsTo = `-- name: GetLocationExitsTo :many select id, "to", "from" from exits where to = ? LIMIT 1 ` +// GetLocationExitsTo +// +// select id, "to", "from" from exits where to = ? LIMIT 1 func (q *Queries) GetLocationExitsTo(ctx context.Context, to sql.NullInt64) ([]Exit, error) { rows, err := q.db.QueryContext(ctx, getLocationExitsTo, to) if err != nil { diff --git a/sqlc.yaml b/sqlc.yaml index 8fbf10e..754ca4b 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -6,5 +6,8 @@ sql: gen: go: emit_db_tags: true + emit_interface: true + emit_json_tags: true + emit_sql_as_comment: true package: "db" out: "db"