eatmoose
eatmoose
DTDrizzle Team
Created by eatmoose on 1/24/2024 in #help
Transaction not respecting locks
await db.transaction(async (trx) => {
await trx.execute(sql`LOCK TABLE myTable IN SHARE MODE;`);
await trx.select.where name === kat
if name === kat throw
await trx.insert(myTable).set({name:'kat'})


})
await db.transaction(async (trx) => {
await trx.execute(sql`LOCK TABLE myTable IN SHARE MODE;`);
await trx.select.where name === kat
if name === kat throw
await trx.insert(myTable).set({name:'kat'})


})
using supabase and postgres spam the above function, sometimes kat gets created more than once however adding trx.execute(BEGIN TRANSACTION ) and then manually comitting it solves the problem, but drizzle logs gives an warning that a transaction is ongoing
25 replies
DTDrizzle Team
Created by eatmoose on 10/17/2023 in #help
bug: three column unique index no change never detected
ex:
uniqueReactPerPost: unique('post_id_reaction_user_id').on(
postId,
reaction,
reactorId,
),
uniqueReactPerPost: unique('post_id_reaction_user_id').on(
postId,
reaction,
reactorId,
),
the above index will be ran, but if you run it again, it'll prompt you to truncate the table, and if you chose not to, it'll run sucessfully but will drop -> then recreates. orm latest, pg 15
5 replies
DTDrizzle Team
Created by eatmoose on 10/5/2023 in #help
GIN index
index('content_json_index').on(content).using('gin'), how do i do gin index on jsonB? postgres.
2 replies
DTDrizzle Team
Created by eatmoose on 9/25/2023 in #help
storing time?
Hello, how to store time in drizzle? If I store new Date(), does it handle timezone? Is it stored as utc or Unix milliseconds?
3 replies
DTDrizzle Team
Created by eatmoose on 7/26/2023 in #help
When using transaction should I use client or pool for postgre connection?
title
1 replies
DTDrizzle Team
Created by eatmoose on 7/21/2023 in #help
is there a way to subscribe to db changes using drizzle?
Title
2 replies
DTDrizzle Team
Created by eatmoose on 6/3/2023 in #help
Type error?
import { pgTable, serial, integer } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
id: serial('id').primaryKey(),
});

export const products = pgTable('products', {
id: serial('id').primaryKey(),
});

export const metadata = pgTable('metadata', {
id: serial('id').primaryKey(),

someOtherRef: integer('some_other_ref_id').references(() => someOtherRef.id),
});

export const someOtherRef = pgTable('someOtherRef', {
id: serial('id').primaryKey(),

metadataId: integer('meta_data_id').references(() => metadata.id),
});
import { pgTable, serial, integer } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
id: serial('id').primaryKey(),
});

export const products = pgTable('products', {
id: serial('id').primaryKey(),
});

export const metadata = pgTable('metadata', {
id: serial('id').primaryKey(),

someOtherRef: integer('some_other_ref_id').references(() => someOtherRef.id),
});

export const someOtherRef = pgTable('someOtherRef', {
id: serial('id').primaryKey(),

metadataId: integer('meta_data_id').references(() => metadata.id),
});
....it does not have a type annotation and is referenced directly or indirectly in its own initializer.
2 replies
DTDrizzle Team
Created by eatmoose on 6/2/2023 in #help
Auto update timestamp fields
How to auto update fields like updated_at?
17 replies
DTDrizzle Team
Created by eatmoose on 6/1/2023 in #help
OrderBy with dynamic queries dont work
....orderBy(sql`${products.xyz} ${order}`)
....orderBy(sql`${products.xyz} ${order}`)
error: syntax error at or near "$2"
error: syntax error at or near "$2"
order is 'asc' / 'desc'
2 replies
DTDrizzle Team
Created by eatmoose on 5/30/2023 in #help
noob help : transaction not acid
return await this.drizzle.db.transaction(async (trx) => {
const u = await trx
.select({
usd: users.usd,
})
.from(users)
.where(eq(users.id, 1));
if (!u || u.length == 0) {
throw new HttpException(
{
message: 'User not found',
success: false,
},
404,
);
}

const user = u[0];
await this.timeout(5000);
return (
await trx
.update(users)
.set({
usd: user.usd + val,
})
.where(eq(users.id, 1))
.returning()
)[0].usd;
return await this.drizzle.db.transaction(async (trx) => {
const u = await trx
.select({
usd: users.usd,
})
.from(users)
.where(eq(users.id, 1));
if (!u || u.length == 0) {
throw new HttpException(
{
message: 'User not found',
success: false,
},
404,
);
}

const user = u[0];
await this.timeout(5000);
return (
await trx
.update(users)
.set({
usd: user.usd + val,
})
.where(eq(users.id, 1))
.returning()
)[0].usd;
sending two req at the same time, one with +10 the other with +100, the expected behavior for the trasnaction to wait for previous req to complete so its consistent
39 replies