nicoalbanese / kirimase

Build full-stack Next.js apps, incredibly fast

Home Page:https://kirimase.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Enable drizzle queries rather than exclusively leveraging SQL API

afogel opened this issue · comments

Is your feature request related to a problem? Please describe.
Currently, leveraging the drizzle query API is not set up when generating scaffolds out of the box.

Describe the solution you'd like
Create a src/lib/db/schema/index.ts that exports a schema object, e.g.

import * as animals from "@/lib/db/schema/animals";

export const schema = {
  animals,
};

In the src/lib/db/index.ts, pass the schema object into the drizzle client that gets instantiated, e.g.

import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg"
import { env } from "@/lib/env.mjs";
import { schema } from "@/lib/db/schema";

export const pool = new Pool({
  connectionString: env.DATABASE_URL,
});
export const db = drizzle(pool, {
  schema
});

Whenever the generator creates a new model, the schema object gets automatically updated, e.g.

import * as animals from "@/lib/db/schema/animals";
import * as books from "@/lib/db/schema/books";

export const schema = {
  animals,
  books,
};

These changes will enable the drizzle query interface, which could simplify the default scaffolded queries that use drizzle.