ashishansurkar
ashishansurkar
DTDrizzle Team
Created by fermentfan on 7/30/2023 in #help
Mocking Drizzle instance
Just sharing this if any helpful to anyone: I ended up using in-memory db from @electric-sql/pglite instead of mocking. So even if I am using "drizzle-orm/node-postgres" in my actual application, tests are working as expected with "Pglite"
import { PGlite } from "@electric-sql/pglite";
import { drizzle } from "drizzle-orm/pglite";
import { migrate } from "drizzle-orm/pglite/migrator";
import path from "path";

import * as clientSchema from "../src/drizzle/schema/clients";
import * as usersSchema from "../src/drizzle/schema/users";

export const testDB = async () => {
const sqlite = new PGlite();
const db = drizzle(sqlite, { schema: { ...clientSchema, ...usersSchema } });
const migrationPath = path.join(process.cwd(), "src/drizzle/migrations");
await migrate(db, { migrationsFolder: migrationPath });
return { dblite: db };
};
import { PGlite } from "@electric-sql/pglite";
import { drizzle } from "drizzle-orm/pglite";
import { migrate } from "drizzle-orm/pglite/migrator";
import path from "path";

import * as clientSchema from "../src/drizzle/schema/clients";
import * as usersSchema from "../src/drizzle/schema/users";

export const testDB = async () => {
const sqlite = new PGlite();
const db = drizzle(sqlite, { schema: { ...clientSchema, ...usersSchema } });
const migrationPath = path.join(process.cwd(), "src/drizzle/migrations");
await migrate(db, { migrationsFolder: migrationPath });
return { dblite: db };
};
22 replies
DTDrizzle Team
Created by ashishansurkar on 1/19/2024 in #help
Insert on migration
Thanks, can you please guide more on this. Should I write queries into .sql migrations files or in the trypescript schema/config file ?
6 replies
DTDrizzle Team
Created by ashishansurkar on 1/8/2024 in #help
how to define postgres schema (other than 'public') while setting up with drizzle-orm/node-postgres
@solo , Thanks again. That worked as well. I tried this earlier but forgot to import dotenv and thought it wouldn't work. Much appreciated.
8 replies
DTDrizzle Team
Created by ashishansurkar on 1/8/2024 in #help
how to define postgres schema (other than 'public') while setting up with drizzle-orm/node-postgres
In the doc, we have to set the schema and then set the table. Is there a way we can set the schema after setting the table? I want to have the benefit of types from the table but I want to assign Postgres schema dynamically at runtime based on dev/prod environment.
8 replies
DTDrizzle Team
Created by ashishansurkar on 1/8/2024 in #help
how to define postgres schema (other than 'public') while setting up with drizzle-orm/node-postgres
That worked. Thank you very much @solo
8 replies