Paul
Paul
Explore posts from servers
DTDrizzle Team
Created by Paul on 6/3/2024 in #help
How to set a GIN index on the JSONB column?
Awesome. Thanks so much @Mykhailo . I updated the syntax slightly for the second one and it works perfectly with the latest API.
ginIndex1: index('gin_idx_1').using('gin', t.metadata),
ginIndex2: index('gin_idx_2').using('gin', sql`metadata->'name'`),
ginIndex1: index('gin_idx_1').using('gin', t.metadata),
ginIndex2: index('gin_idx_2').using('gin', sql`metadata->'name'`),
Gives me
CREATE INDEX IF NOT EXISTS "gin_idx_1" ON "users" USING gin (metadata);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "gin_idx_2" ON "users" USING gin (metadata->'name');
CREATE INDEX IF NOT EXISTS "gin_idx_1" ON "users" USING gin (metadata);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "gin_idx_2" ON "users" USING gin (metadata->'name');
3 replies
DTDrizzle Team
Created by Paul on 6/3/2024 in #help
When using a foreignKey({}), is there a way to specify onDelete: "cascade'?
Thanks a lot. This works. I think adding this to the documentation would be helpful to avoid this question forever since the AI in the docs is getting it wrong currently.
4 replies
DTDrizzle Team
Created by Paul on 12/5/2023 in #help
Does Drizzle-Orm Expose Wrapper Types?
Thank you. And if I just want to provide some additional options like filtering, orderBy, where options around my wrapper get method, are there any examples for this by any chance? async getEmailById(data: string, options: any): Promise<void> { await client.select().from(emails).where(eq(emails.id, data)); } I got something like the code below from AI, but wondering how to define the difference argument types - Predicate, Order, SelectedFields
import { eq, asc } from 'drizzle-orm';

async function getFilteredEmailData(
whereClause?: Predicate | Predicate[],
orderByClause?: Order | Order[],
filterFields?: SelectedFields<emails>,
): Promise<void> {
let query = client.select(filterFields).from(emails);

if (whereClause) {
query = query.where(whereClause);
}

if (orderByClause) {
query = query.orderBy(orderByClause);
}

await query;
}
import { eq, asc } from 'drizzle-orm';

async function getFilteredEmailData(
whereClause?: Predicate | Predicate[],
orderByClause?: Order | Order[],
filterFields?: SelectedFields<emails>,
): Promise<void> {
let query = client.select(filterFields).from(emails);

if (whereClause) {
query = query.where(whereClause);
}

if (orderByClause) {
query = query.orderBy(orderByClause);
}

await query;
}
5 replies
DTDrizzle Team
Created by Paul on 11/12/2023 in #help
How to implement Row Level Security in Postgres?
Thanks! Helpful as always!
4 replies
DTDrizzle Team
Created by Paul on 10/19/2023 in #help
How to create unique lowercase index?
As a side note, how can I use sql when declaring the schema to run a check against the column (in postgres)? I note that the check function isn't implemented yet in drizzle-orm as per this. Just to confirm, this isn't possible via the sql operator either? Also, is it possible to create a trigger using the
sql``
sql``
feature when defining the schema? tldr; is it possible to use the sql`` command to create checks and triggers when defining the schema?
4 replies
DTDrizzle Team
Created by Paul on 10/19/2023 in #help
Discussion: cuid2 vs ulid?
Thanks for always replying!
8 replies
DTDrizzle Team
Created by Paul on 9/24/2023 in #help
Is it possible to run javascript between database transactions?
Oh wow. Even without any other javascript code, it's 5 queries. Okay. Thank you. This is very helpful!
9 replies
DTDrizzle Team
Created by Paul on 9/24/2023 in #help
Is it possible to run javascript between database transactions?
Ohh that makes sense. Thank you. So a transaction doesn't have to do with one call or three calls, moreso one failing is all failing. But I do have to ask... if a transaction has 3 consecutive transactions like the one below, does that become one db call? Or it's not clear still.
await db.transaction(async (tx) => {
await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 100.00` }).where(eq(users.name, 'Andrew'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 140.00` }).where(eq(users.name, 'Andrew'));
});
await db.transaction(async (tx) => {
await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 100.00` }).where(eq(users.name, 'Andrew'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 140.00` }).where(eq(users.name, 'Andrew'));
});
9 replies
DTDrizzle Team
Created by Paul on 9/22/2023 in #help
TypeError: Seems like the schema generic is missing - did you forget to add it to your DB type?
Yeah I was looking to allow users of this function to pass in their drizzle schema that should look a certain way for me to query. But I also created the same schema myself as a fallback. On a high level, I'm trying to create an adapter to update a user's database. But I think defining the essential elements of the schema myself may suffice instead of allowing users to pass it in. Anyways, I think it's okay to ignore this question if defining the generic of a schema is bit complicated. Thank you
5 replies