What is monolayer?
monolayer-pg is a PostgreSQL database schema manager for TypeScript projects built on top of kysely
with:
- Declarative, type-safe database schema definition.
- Type-safe database client(s) for
kysely
(no codegen 🎉). - An advanced migration system with non-blocking migrations by default, migrations by phases, and detailed warnings.
- Comprehensive Zod validations for all supported data types (no codegen 🎉) for
kysely
. - Support for multiple databases.
- Support for multiple schemas per database.
- Effortless
Prisma
integration.
Here's a taste of how you define database schemas with monolayer-pg
:
ts
const users = table({
columns: {
id: integer().generatedAlwaysAsIdentity(),
email: text().notNull(),
name: text(),
},
constraints: {
primaryKey: primaryKey(["id"]),
unique: [unique(["email"])],
},
indexes: [index(["email"])],
});
const posts = table({
columns: {
id: integer().generatedAlwaysAsIdentity(),
title: text().notNull(),
content: text(),
published: boolean().default(false),
authorId: integer(),
createdAt: timestampWithTimeZone().notNull().default(sql`now()`),
updatedAt: timestampWithTimeZone().notNull().default(sql`now()`),
},
constraints: {
primaryKey: primaryKey(["id"]),
foreignKeys: [
foreignKey(["authorId"], users, ["id"])
.deleteRule("set null")
.updateRule("cascade"),
],
},
indexes: [index(["authorId"])],
});
export const dbSchema = schema({
tables: {
users,
posts,
},
});
Head over to the Quickstart and begin using monolayer-pg
!