@fougere/adapter-sql
Entity → SQL tables through Kysely (SQLite, PostgreSQL, MySQL, SQL Server).
Use it
npm install @fougere/adapter-sql
pnpm add @fougere/adapter-sql
bun add @fougere/adapter-sql
yarn add @fougere/adapter-sql
// fougere.config.ts
import '@fougere/adapter-sql';
export default defineFougere({
sources: { main: { type: 'sqlite', path: '…' } },
// or main: { type: 'pg', url: '…' }
// or main: { type: 'mysql', url: '…' }
// or main: { type: 'mssql', url: '…' }
// or main: { type: 'd1', binding: '…' }
});
The import is what makes the word exist: without it, the editor and the boot both refuse it.
export default class Post extends entity({ … }, { adapters: { sql: { … } } }) {}
Every key each one admits: sources.
What it extends
The interfaces of Fougere this package adds its words to, with declare module — see Interfaces to extend.
| interface | adds |
|---|---|
FougereSources | sqlite, pg, mysql, mssql, d1 |
FougereEntityAdapters | sql |
Entries: @fougere/adapter-sql
What you import
| name | |
|---|---|
autoMigrate | Create every missing table. |
compiler | A Kysely bound to a dialect's compiler but to no connection — renders SQL only. |
createTableSQL | Render CREATE TABLE for one described table. |
generateSQL | CREATE TABLE for every entity a source holds. |
onQuery | Be told about every statement this process runs, and get the unsubscription back. |
toSnakeCase | camelCase → snake_case |
toTable | Describe one entity as a table — the single reader of the axes. |
toTableName | orderItem → order_items: the plural, then snake_case. |
toTables | Every entity an app hosts, as tables aware of their foreign keys. |
orderTables | Tables ordered so a ref()'s target exists before the table pointing at it. |
columnTypeFor | The type a column is emitted with: what the entity stated for this engine, else the shape's answer. |
dialects | |
SqlStorage | |
createStorageFactory | Create a StorageFactory backed by Kysely — same call shape on every engine. |
codecsOf | Field name → codec, for every column that needs one. Identity columns are omitted. |
createKyselySource | Wrap any Kysely dialect — Postgres, MySQL, SQL Server. |
createSqliteSource | |
createD1Source | |
drift | What a live table holds that differs from its declaration, which a migration leaves alone. |
actualState | Read the live schema. Only names are needed — an additive pass never inspects types. |
changeSQL | Render one change. |
delta | Compare the two states. Pure — the only place that decides what is missing. |
desiredTables | Project a source's entities into the tables they ask for. |
migrate | Bring the database up to what the entities describe — additively. |
pendingOf | The tables and columns the database lacks, read and never written. |
undeclaredColumns | The columns a live table keeps that no field declares, for the tables that also gain one. |
applyStep | Runs a step, or refuses it whole when the plan holds a refusal. |
collapseChain | Collapse a chain of steps into one, following each field through its renames. |
planStep | Turn a frozen step into what the tables must do, and what nobody may decide for you. |
Types
TypeScript types only — they do not run. Import them with import type to type your own code: a variable, a parameter, an option object.
| name | |
|---|---|
QueryEvent | One statement this process ran, and what it cost. |
QuerySink | |
EntityEntry | A live class in-process, or one rebuilt from the card of a frond that never crossed. |
Dialect | |
SqlField | |
SqlFields | What sql holds, addressed by field — the shape every augmentation of the registry takes. |
SqliteSource | |
SqliteSourceOptions | |
SqlSource | A Source realized by SQL — and the three members that are SQL's, not the routing's. |
Drift | One column whose declaration moved and whose table did not follow. |
Change | |
SchemaState | What the database actually holds: column names per table. |
Plan | |
StepChange | What a step asks of the tables — beyond what an additive pass already covers. |