@marmeon/database
v0.3.0
Published
Data access on Kysely for Marmeon apps: connections, migrations per module, generated table types, repositories, relations derived from foreign keys (with), tryInsert/tryUpdate returning a Result, transactions that roll back on err, and pagination.
Maintainers
Readme
@marmeon/database
The data layer of Marmeon apps on Kysely: connections, migrations per module, generated table types, repositories, relations
derived from foreign keys (with), tryInsert/tryUpdate returning a Result, factories, transactions that roll back on err
and pagination.
Installation
Part of every new Marmeon app: pnpm create marmeon installs it.
SQLite is built in (node:sqlite, no native addon). Postgres needs the pg driver, an optional peer the app installs as a
dependency: pnpm add pg@^8. Without it, the first query fails and names that command.
A first repository
import { Repository } from '@marmeon/database';
export class NoteRepository extends Repository<'notes'> {
static table = 'notes' as const;
latestOf(userId: number) {
return this.query().selectAll().where('user_id', '=', userId).orderBy('updated_at', 'desc').limit(10).execute();
}
}notes is typed from the app's migrations (marmeon db:types): a column that does not exist is a compile error.
Documentation
- Database: Getting Started
- Repositories & Queries
- Migrations
- Seeding & Factories
- Transactions
- Pagination
- Database Testing
- Deployment: drivers
MIT · part of Marmeon
