Skip to main content

Components reference

The DB-X Postgres component library ships a small, focused set of schema primitives. Each is a defineComponent from @db-x/runtime.

Auto-generated API

A full TypeDoc-generated reference is on the way. The summary here covers the shipped Postgres surface; SQLite and MongoDB components are documented on their own engine pages.

<DatabaseTarget>

Connection target for production-direct deployments. Reads connection info from a postgres:// URL.

<DatabaseTarget url={process.env.DATABASE_URL!}>
{/* Postgres tree goes here */}
</DatabaseTarget>
PropTypeNotes
urlstringConnection URL. Required.
descriptionstring?Surfaced in describe output.

<Postgres>

The database itself. Children declare schema objects.

<Postgres name="todos-db">
<Extension name="pgcrypto" />
<Table name="todos">...</Table>
</Postgres>
PropTypeNotes
namestringDatabase name. Required.
ownerstring?Database owner role.

<Extension>

Installs a Postgres extension idempotently.

<Extension name="pgcrypto" />
<Extension name="vector" version="0.7.4" />
PropTypeNotes
namestringExtension name.
versionstring?Pin a specific version when needed.

<Table>

A table; children declare columns and indexes.

<Table name="todos">
<Column name="id" type="serial" primaryKey />
<Column name="title" type="text" notNull />
<Index columns={['title']} unique />
</Table>
PropTypeNotes
namestringTable name.
fromstring?Previous name — triggers RENAME TABLE when changed.

<Column>

A column. Type, default, NOT NULL and UNIQUE changes are detected and emitted as ALTER COLUMN statements; from= renames losslessly rather than drop-and-add.

<Column name="title" type="text" notNull />
<Column name="status" from="legacy_status" type="text" default="'pending'" />
PropTypeNotes
namestringColumn name.
typestringSQL type.
fromstring?Previous name — triggers RENAME COLUMN.
primaryKeyboolean?
notNullboolean?
defaultstring?SQL expression.
uniqueboolean?

<Index>

A regular or unique index on the parent <Table>.

<Index columns={['user_id', 'created_at']} />
<Index columns={['email']} unique />

<SeedData>

One-shot seed inserts, run once at table creation.

<SeedData
rows={[
{ title: 'Pick the project', done: false },
{ title: 'Ship it', done: false },
]}
/>

<DbUser>

A database role with grants.

<DbUser name="todos_ro" password={process.env.RO_PASS!} grants={['SELECT']} />