san4d
san4d
Explore posts from servers
DTDrizzle Team
Created by san4d on 4/22/2024 in #help
Error with Nested Transactions
I'm experiencing an issue with nested transactions on neon serverless 0.9.1, drizzle-orm 0.30.9, and ws 8.16.0. The following works locally but not in production:
async function createOrGet<T>(
parentTxn: DbTransaction<T>,
entity: NewEntity,
): Promise<string | null> {
try {
return await parentTxn.transaction(async (childTxn) => {
return await createInTxn(childTxn, entity)
})
} catch (e: unknown) {
if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
} else {
return null
}
}
}
async function createOrGet<T>(
parentTxn: DbTransaction<T>,
entity: NewEntity,
): Promise<string | null> {
try {
return await parentTxn.transaction(async (childTxn) => {
return await createInTxn(childTxn, entity)
})
} catch (e: unknown) {
if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
} else {
return null
}
}
}
The following works in production but not locally:
async function createOrGet<T>(
parentTxn: DbTransaction<T>,
entity: NewEntity,
): Promise<string | null> {
try {
return await createInTxn(parentTxn, entity)
} catch (e: unknown) {
if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
} else {
return null
}
}
}
async function createOrGet<T>(
parentTxn: DbTransaction<T>,
entity: NewEntity,
): Promise<string | null> {
try {
return await createInTxn(parentTxn, entity)
} catch (e: unknown) {
if (isDbErrorWithCode(e, PostgresErrorCode.UNIQUE_VIOLATION)) {
return await findWorkflowTemplateByNameInTxn(parentTxn, entity.id)
} else {
return null
}
}
}
I'd expect the 1st (parent-child transactions) to work. Instead, I get a 25P01 error NO_ACTIVE_SQL_TRANSACTION with message
error: ROLLBACK TO SAVEPOINT can only be used in transaction blocks\n at file:///var/task/dist/server/entry.mjs:148485:23\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async _NeonTransaction.transaction
5 replies
DTDrizzle Team
Created by san4d on 4/11/2024 in #help
Parameterized Interval in Where Clause
I'm trying to write a query that uses an interval as a parameter. The SQL looks like this and works fine:
where now() - interval '1 month' < table.date
where now() - interval '1 month' < table.date
When I try to write it using drizzle, it also works fine if a hard code the interval:
lt(
sql<Date>`now() - interval '1 month'`,
sql<Date>`table.date`
)
lt(
sql<Date>`now() - interval '1 month'`,
sql<Date>`table.date`
)
However, it does not work if I try to parameterize the interval like this:
lt(
sql<Date>`now() - interval '${interval}'`,
sql<Date>`table.date`
)
lt(
sql<Date>`now() - interval '${interval}'`,
sql<Date>`table.date`
)
or this:
sql<boolean>`now() - interval '${interval}' < table.date`,
sql<boolean>`now() - interval '${interval}' < table.date`,
I get this error
Error: could not determine data type of parameter $3
I tried this
lt(
sql<Date>`now() - ${interval}`,
sql<Date>`table.date`
)
lt(
sql<Date>`now() - ${interval}`,
sql<Date>`table.date`
)
and got this error
operator does not exist: interval < timestamp with time zone
Since the raw SQL works, I must be missing something in the ORM usage. Any suggestions? I'm running Postgres 16 on neon using drizzle 0.30.7.
1 replies
DTDrizzle Team
Created by san4d on 1/31/2024 in #help
Error when making a websocket-based transaction on an AWS Lambda Function
Problem I'm seeing this error when I try to make a connection:
{
"errorType":"TypeError","errorMessage":"bufferUtil2.mask is not a function",
"stack":[
"TypeError: bufferUtil2.mask is not a function",
"at bufferUtil$1.exports.mask (file:///var/task/dist/server/entry.mjs:111053:25)",
"at Sender.frame (file:///var/task/dist/server/entry.mjs:112347:11)",
"at Sender.send (file:///var/task/dist/server/entry.mjs:112536:20)",
"WebSocket2.send (file:///var/task/dist/server/entry.mjs:113273:22)",
"at Timeout._onTimeout (file:///var/task/dist/server/entry.mjs:109102:25)",
"at listOnTimeout (node:internal/timers:569:17)",
"at process.processTimers (node:internal/timers:512:7)"
]
}
{
"errorType":"TypeError","errorMessage":"bufferUtil2.mask is not a function",
"stack":[
"TypeError: bufferUtil2.mask is not a function",
"at bufferUtil$1.exports.mask (file:///var/task/dist/server/entry.mjs:111053:25)",
"at Sender.frame (file:///var/task/dist/server/entry.mjs:112347:11)",
"at Sender.send (file:///var/task/dist/server/entry.mjs:112536:20)",
"WebSocket2.send (file:///var/task/dist/server/entry.mjs:113273:22)",
"at Timeout._onTimeout (file:///var/task/dist/server/entry.mjs:109102:25)",
"at listOnTimeout (node:internal/timers:569:17)",
"at process.processTimers (node:internal/timers:512:7)"
]
}
I'm able to make HTTP calls no problem. Setup - Node 18.v20 Runtime on AWS Lambda - Postgres 16 on Neon - @Neondatabase/serverless v0.6.1 - drizzle-orm v0.29.3 - ws v8.16.0 Ask Has anyone ran into this before? If so, what did you you need to change? I'm looking into the bufferUtil2.mask error currently. Solution I figured out that I needed to add bufferutil as an optional dependency:
"optionalDependencies": {
"bufferutil": "^4.0.8"
}
"optionalDependencies": {
"bufferutil": "^4.0.8"
}
3 replies
DTDrizzle Team
Created by san4d on 10/8/2023 in #help
Type Generated from $inferInsert does not change after column type update
No description
5 replies
CDCloudflare Developers
Created by san4d on 9/4/2023 in #pages-help
The Workers runtime failed to start on Fedora Linux
Hello! I'm deploying a vanilla Astro website using pages. I'm now trying to connect that website to a D1 instance. When I start wrangler, I see an error stating that "✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above." The D1 binding I set up in the console is properly registered locally, and there are no additional logs related to the startup failure. I'm currently running the cloudflare plugin in advanced mode. I've attempted to follow these instructions to no avail: - https://developers.cloudflare.com/pages/framework-guides/deploy-an-astro-site/#use-bindings-in-your-astro-application - https://docs.astro.build/en/core-concepts/endpoints/#server-endpoints-api-routes I'm running Fedora Linux 38, wrangler 3.6.0, astro 3.0.7, and version 7.0.1 of the astro cloudflare plugin.
3 replies