Aidan Laycock
Aidan Laycock
DTDrizzle Team
Created by Aidan Laycock on 9/7/2023 in #help
Transactions for DB reset in testing
Hi, has anyone leveraged DB transactions as a wrapper around all DB calls within a test so that it can be rolled back at the end of a test process (We're currently purging all tables directly, but that seems inefficient really).
1 replies
DTDrizzle Team
Created by Aidan Laycock on 9/4/2023 in #help
Data factories
Is there a good way to add a data factory to Drizzle, so that I can add new users quickly for testing etc. (Ideally with being able to pass through relationship data as well).
6 replies
DTDrizzle Team
Created by Aidan Laycock on 8/17/2023 in #help
Conditional findFirst
Is it possible to conditionally use findFirst, rather than having to chain the underlying model. E.g.
const result = await db.query.users.findMany({
with: {
posts: true
},
});
const result = await db.query.users.findMany({
with: {
posts: true
},
});
Into either:
const result = await db.query(users).findMany({
with: {
posts: true
},
});

OR

const result = await db.query[modelName]findMany({
with: {
posts: true
},
});
const result = await db.query(users).findMany({
with: {
posts: true
},
});

OR

const result = await db.query[modelName]findMany({
with: {
posts: true
},
});
27 replies
DTDrizzle Team
Created by Aidan Laycock on 8/11/2023 in #help
Issue with Jest tests in Next.js
I seem to be hitting an error with Jest tests when using DrizzleORM in my tests. I get
Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
And then
/Users/a.laycock/Desktop/Work/project/database/client.ts:18
const connection = await _promise.default.createConnection({
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
/Users/a.laycock/Desktop/Work/project/database/client.ts:18
const connection = await _promise.default.createConnection({
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules
9 replies