drafting persistence
parent
c395c22bc2
commit
535baf7e1b
@ -0,0 +1,31 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.30.0
|
||||||
|
|
||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DBTX interface {
|
||||||
|
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
||||||
|
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
||||||
|
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
||||||
|
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(db DBTX) *Queries {
|
||||||
|
return &Queries{db: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Queries struct {
|
||||||
|
db DBTX
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
||||||
|
return &Queries{
|
||||||
|
db: tx,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.30.0
|
||||||
|
|
||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Exit struct {
|
||||||
|
ID int64
|
||||||
|
To sql.NullInt64
|
||||||
|
From sql.NullInt64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Inventory struct {
|
||||||
|
ID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Location struct {
|
||||||
|
ID int64
|
||||||
|
X int64
|
||||||
|
Y int64
|
||||||
|
Z int64
|
||||||
|
World int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Observable struct {
|
||||||
|
ID int64
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pool struct {
|
||||||
|
ID int64
|
||||||
|
Type int64
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.30.0
|
||||||
|
// source: query.sql
|
||||||
|
|
||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
const getLocation = `-- name: GetLocation :one
|
||||||
|
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
|
||||||
|
err := row.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.X,
|
||||||
|
&i.Y,
|
||||||
|
&i.Z,
|
||||||
|
&i.World,
|
||||||
|
)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLocationExitsFrom = `-- name: GetLocationExitsFrom :many
|
||||||
|
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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Exit
|
||||||
|
for rows.Next() {
|
||||||
|
var i Exit
|
||||||
|
if err := rows.Scan(&i.ID, &i.To, &i.From); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLocationExitsTo = `-- name: GetLocationExitsTo :many
|
||||||
|
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 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Exit
|
||||||
|
for rows.Next() {
|
||||||
|
var i Exit
|
||||||
|
if err := rows.Scan(&i.ID, &i.To, &i.From); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
-- name: GetLocation :one
|
||||||
|
select * from locations where id = ? LIMIT 1;
|
||||||
|
|
||||||
|
-- name: GetLocationExitsTo :many
|
||||||
|
select * from exits where to = ? LIMIT 1;
|
||||||
|
|
||||||
|
-- name: GetLocationExitsFrom :many
|
||||||
|
select * from exits where from = ? LIMIT 1;
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
create TABLE locations (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
x INTEGER NOT NULL,
|
||||||
|
y INTEGER NOT NULL,
|
||||||
|
z INTEGER NOT NULL,
|
||||||
|
world INTEGER NOT NULL
|
||||||
|
)
|
||||||
|
|
||||||
|
create TABLE exits (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
to INTEGER REFERENCES locations(id),
|
||||||
|
from INTEGER REFERENCES locations(id)
|
||||||
|
)
|
||||||
|
|
||||||
|
create TABLE observables (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
description TEXT NOT NULL
|
||||||
|
)
|
||||||
|
|
||||||
|
create TABLE inventories (
|
||||||
|
id INTEGER PRIMARY KEY
|
||||||
|
)
|
||||||
|
|
||||||
|
create TABLE pools (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
type INTEGER NOT NULL
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue