@gigamusic/db
v4.4.0
Published
Drizzle schema + a typed query factory for the gigamusic platform.
Readme
@gigamusic/db
Drizzle schema + a typed createQueries(db) factory for the gigamusic platform. Consumers import the schema objects into their own Drizzle setup and pass a drizzle() instance into the factory.
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import { createQueries } from "@gigamusic/db";
import * as schema from "@gigamusic/db/schema";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool, { schema });
export const queries = createQueries(db);For Neon: import drizzle from drizzle-orm/neon-serverless instead and pass a @neondatabase/serverless Pool. The Queries interface is the same.
Schema subpath
@gigamusic/db/schema exports the table objects, relations, and column shapes:
import {
releases, tracks, trackFiles,
orders, orderItems, downloadTokens,
siteSettings, links, rateLimits,
releasesRelations, tracksRelations, /* ... */
releaseColumns, trackColumns, /* ... */
} from "@gigamusic/db/schema";Pass the full namespace import (import * as schema from "@gigamusic/db/schema") into drizzle(pool, { schema }) so the relational query API (db.query.releases.findFirst(...)) works.
Extending tables
If you want to add columns to a bundled table, declare your own pgTable using the exported column object:
import { releaseColumns } from "@gigamusic/db/schema";
import { pgTable, text } from "drizzle-orm/pg-core";
export const releases = pgTable("releases", {
...releaseColumns,
vinylSku: text("vinyl_sku"),
});Library queries (createQueries) close over the base table, so they only read/write the base columns. Provide your own queries for the extended columns.
Reserved names (don't redeclare these in consumer schemas)
Tables (pgTable first-arg targets): releases, tracks, track_files, orders, order_items, download_tokens, site_settings, links, rate_limits, link_pages, link_page_items
Enums: ReleaseType, OrderStatus
link_pages / link_page_items are part of this package's schema and createQueries; @gigamusic/links owns the link-page admin handlers + UI helpers on top of them.
What this package does not own
- The Drizzle client construction (
drizzle(pool, { schema })) — consumers build their own with whatever adapter (node-postgres,neon-serverless, etc.). - Migrations — consumers run
drizzle-kit push(orgenerate+migrate) themselves. - Database connection state — the
dbinstance is passed intocreateQueries; this package never readsprocess.env.
