drizzle
Postgres and SQLite repositories for the server.
@softzweig/suitcase-drizzle provides the repositories and transaction runner the server needs,
backed by Drizzle. It is dialect-agnostic: the base class targets a small structural
DrizzleDatabase port, not a concrete driver type.
Server adapters
Section titled “Server adapters”import { createSqliteServerAdapters } from "@softzweig/suitcase-drizzle/sqlite-core";
const server = createSuitcaseServer(definition, createSqliteServerAdapters(db));import { createPostgresServerAdapters } from "@softzweig/suitcase-drizzle/pg-core";
const server = createSuitcaseServer(definition, createPostgresServerAdapters(db));Both return ServerAdapters: the three repositories, a transaction runner, and the upload key
strategy. Writes require a driver that supports returning().
Tables and migrations
Section titled “Tables and migrations”Both dialects export their schema, not their migrations. Import the tables and unpack them into a file drizzle-kit can read:
import { tables } from "@softzweig/suitcase-drizzle/pg-core";
export const { assets, resources, uploadSessions } = tables;Generate and apply migrations from there with your own tooling, or run drizzle-kit push in
development. Rows are the DTOs with dialect column types applied: ids are uuid on Postgres and
text on SQLite, jsonb becomes text in JSON mode, and instants are timestamp (3) with time zone on Postgres against ISO-8601 text on SQLite.
The migrations/ folders in this repository are fixtures that the integration tests apply to PGlite
and libSQL; they are not published.
Custom repositories
Section titled “Custom repositories”Extend AbstractDrizzleRepository and supply the table, two mappers, and the id filter:
class AssetRepository extends AbstractDrizzleRepository<Asset, typeof assets, AssetFilter> { protected readonly table = assets; protected toDto(row: AssetRow): Asset { // row -> domain } protected toRow(dto: Partial<Omit<Asset, "id">>): Partial<AssetRow> { // domain -> row } protected idFilter(ids: string[]): AssetFilter { return { id: ids }; }}The base class builds findOne, findById, findByIds, patch, delete, and transaction on
top of findMany, insert, patchWhere, and deleteWhere.
Filters
Section titled “Filters”Filter keys are DTO property names, resolved through the table’s columns. A scalar becomes =, an
array becomes in (...), and an unknown property throws a TypeError.
Transactions
Section titled “Transactions”transaction runs the callback against repositories bound to the transaction handle:
await assets.transaction(async (context) => { await resources.withContext(context).patch(resourceId, { label: "Avatar" });});context.isTransactional is true, and context.db is the transaction handle. withContext is how
a second repository joins the same transaction.
In-memory alternative
Section titled “In-memory alternative”The memory repositories in @softzweig/suitcase-server/memory implement the same contracts for
tests and local development. They are not durable and should not back a deployment.