Skip to content

db

import { db, pages, inquiries, siteSettings, siteSettingsColumns } from "louisecms/db";

A thin wrapper around Drizzle’s D1 driver. Raw binding in, Drizzle instance out — the schema is yours, never Louise’s.

Peer dependency: drizzle-orm.

function db<TSchema extends Record<string, unknown>>(
d1: D1Database,
schema?: TSchema,
): DrizzleD1Database<TSchema>;

Returns a Drizzle instance bound to your D1 database. Pass your own schema object for typed relational queries; omit it for a schema-less handle.

import { db } from "louisecms/db";
import * as schema from "./schema"; // your Drizzle tables
export async function GET({ locals, request }, env: Env) {
const orm = db(env.DB, schema);
const rows = await orm.select().from(schema.artworks);
return Response.json(rows);
}

Because the binding is passed in, the same call works in astro dev, in production, and in a test with a fake D1.

A framework-owned singleton config table you can compose into your schema or use as-is, so a generic “site settings” row doesn’t drift between projects.

import { siteSettings } from "louisecms/db";
const [settings] = await db(env.DB).select().from(siteSettings).limit(1);

siteSettingsColumns exposes the column set for composing your own table variant when you need to extend it.

The two other framework-generic CMS tables, offered on the same compose-or-use-as-is pattern:

  • pages (pagesColumns, Page, NewPage) — slug, title, sanitized rich body, publish status, SEO/OG, ordering, timestamps.
  • inquiries (inquiriesColumns, Inquiry, NewInquiry) — contact-form submissions.
import { sqliteTable, integer } from "drizzle-orm/sqlite-core";
import { pagesColumns } from "louisecms/db";
// Use as-is, or spread the columns to add site-specific fields:
export const pages = sqliteTable("pages", {
...pagesColumns,
authorId: integer("author_id"),
});

drizzle-kit still generates each site’s migration from its composed schema, so sharing the column set costs no flexibility.