Use when working with DBX database schema definitions, generating Go database bindings, creating models, or writing CRUD operations. DBX is a code generation tool that creates Go code for Postgres, CockroachDB, Spanner, and SQLite databases.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Use when working with DBX database schema definitions, generating Go database bindings, creating models, or writing CRUD operations. DBX is a code generation tool that creates Go code for Postgres, CockroachDB, Spanner, and SQLite databases.
argument-hint
[create|read|update|delete|model|schema|help]
DBX Database Code Generator
DBX generates database schemas and Go code for interacting with databases. It supports Postgres (pgx), CockroachDB (pgxcockroach), Spanner, and SQLite3 dialects.
DBX uses a tuple/list grammar. Lists are parentheses-enclosed comma-separated tuples. Newlines auto-insert commas.
Model Definition
model <name> (
// Optional: custom table name
table <table_name>
// Required: primary key (single or composite)
key <field_names>
// Optional: unique constraints
unique <field_names>
// Optional: indexes
index (
name <index_name>
fields <field_names>
unique // optional
storing <fields> // optional: include columns (covering index)
where <condition> // optional: partial index
)
// Fields
field <name> <type> ( attributes )
// Foreign key relations
field <name> <model>.<field> <relation> ( attributes )
)
Field Types
Type
Go Type
Description
serial
int
Auto-incrementing integer
serial64
int64
Auto-incrementing 64-bit integer
int
int
32-bit integer
int64
int64
64-bit integer
uint
uint
Unsigned 32-bit integer
uint64
uint64
Unsigned 64-bit integer
bool
bool
Boolean
text
string
Text/varchar
timestamp
time.Time
Timestamp with timezone
utimestamp
time.Time
Timestamp without timezone (UTC)
float
float32
32-bit float
float64
float64
64-bit float
blob
[]byte
Binary data
json
[]byte
JSON data (uses JSON/JSONB SQL type)
date
time.Time
Date only
Field Attributes
Attribute
Description
column <name>
Custom column name
nullable
Field can be NULL
updatable
Field can be updated
autoinsert
Auto-populate on insert (timestamps get current time)
autoupdate
Auto-populate on update (timestamps get current time)
length <n>
Max text length
default <value>
Default value (numbers, strings, "epoch" for timestamps, "{}" for JSON)
Foreign Key Relations
Relation
Behavior on Delete
cascade
Delete this row when related row is deleted
restrict
Prevent deletion of related row
setnull
Set field to NULL (requires nullable)
CRUD Operations
Create
create <model> (
raw // expose all fields, including autoinsert ones
noreturn // don't return the created row
replace // upsert behavior (INSERT OR REPLACE)
suffix <parts> // custom method name suffix
)
model user (
key pk
unique id
unique email
field pk serial64
field created_at timestamp ( autoinsert )
field updated_at timestamp ( autoinsert, autoupdate )
field id text
field email text
field name text ( updatable )
)
create user ( )
read one ( select user, where user.pk = ? )
read one ( select user, where user.id = ? )
update user ( where user.pk = ? )
delete user ( where user.pk = ? )
Many-to-Many Relationship
model user (
key pk
field pk serial64
)
model role (
key pk
field pk serial64
field name text
)
model user_role (
key user_pk role_pk
field user_pk user.pk cascade
field role_pk role.pk cascade
)
create user_role ( )
read all (
select role
join role.pk = user_role.role_pk
join user_role.user_pk = user.pk
where user.pk = ?
)
Nullable Foreign Key with Setnull
model post (
key pk
field pk serial64
field author_pk user.pk setnull ( nullable )
field content text
)
Composite Primary Key
model event_log (
key timestamp source_id
field timestamp utimestamp
field source_id blob
field event_type uint
field payload json
)
create event_log ( noreturn )
read paged (
select event_log
where event_log.source_id = ?
)
Partial Index
model task (
key pk
index (
fields status
where task.status != "completed"
)
field pk serial64
field status text ( updatable )
)
Key-Value Store with Replace
model kv (
key key
field key text
field val text
)
create kv ( replace, noreturn )
read one ( select kv, where kv.key = ? )