dsqlbase
v0.1.4
Published
Query client and schema definition for distributed SQL databases
Readme
[!CAUTION] dsqlbase is in early-stage development and not suited for production environments. Features may change at any time, without prior notice.
dsqlbase is an ORM and migration toolkit purpose-built for Aurora DSQL. It treats DSQL's distributed-database constraints (no foreign keys, no in-place column changes, async-only index builds, etc.) as first-class — refusing unsupported DDL up front and emitting DSQL-shaped SQL by default. See the project README for the longer motivation.
Install
npm install dsqlbaseQuickstart
// schema.ts
import { table, uuid, text, datetime, relations, hasMany, belongsTo } from "dsqlbase/schema";
export const teams = table("teams", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
createdAt: datetime("created_at").notNull().defaultNow(),
});
export const projects = table("projects", {
id: uuid("id").primaryKey().defaultRandom(),
teamId: uuid("team_id").notNull(),
name: text("name").notNull(),
});
export const teamRelations = relations(teams, {
projects: hasMany(projects, {
from: [teams.columns.id],
to: [projects.columns.teamId],
}),
});
export const projectRelations = relations(projects, {
team: belongsTo(teams, {
from: [projects.columns.teamId],
to: [teams.columns.id],
}),
});// client.ts
import { Pool } from "pg";
import { createPgSession } from "dsqlbase/pg";
import { createClient, type Session, type SQLStatement } from "dsqlbase";
import * as schema from "./schema";
const session = createPgSession(
new Pool({
connectionString: process.env.DATABASE_URL,
})
);
export const dsql = createClient({ schema, session });
// Use it
const recent = await dsql.projects.findMany({
orderBy: { name: "asc" },
limit: 10,
join: { team: true },
});Links
License
MIT.
