Zamiel
Zamiel
Explore posts from servers
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Ah perfect, I'll use a union, thanks. Any news on the select without from PR?
19 replies
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Which might be important at scale when N is not just 3 (like it is in the above code) but is instead 100, for example.
19 replies
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Well, I mean to say that they would run at roughly the same speed, but the second one avoids the fixed cost of generating a network packet, the server acknowledging each request, and so on.
19 replies
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Sorry, perhaps I am misusing the term "batch queries". Allow me to clarify. Consider the following two SQL queries:
SELECT field_1 from foo WHERE foo.user_id = $1;
SELECT field_2 from bar WHERE foo.user_id = $1;
SELECT field_3 from baz WHERE foo.user_id = $1;
SELECT field_1 from foo WHERE foo.user_id = $1;
SELECT field_2 from bar WHERE foo.user_id = $1;
SELECT field_3 from baz WHERE foo.user_id = $1;
SELECT (
(SELECT field_1 from foo WHERE foo.user_id = $1) as field_1,
(SELECT field_2 from bar WHERE bar.user_id = $1) as field_2,
(SELECT field_3 from baz WHERE baz.user_id = $1) as field_3
);
SELECT (
(SELECT field_1 from foo WHERE foo.user_id = $1) as field_1,
(SELECT field_2 from bar WHERE bar.user_id = $1) as field_2,
(SELECT field_3 from baz WHERE baz.user_id = $1) as field_3
);
In the first query, 3 SQL queries are sent over the wire. In the second query, 1 SQL query is sent over the wire. Isn't the second one faster?
19 replies
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Maybe transactions would help? But I'm not quite sure, as I might not need the atomicity of a transaction, since I have a bunch of SELECT statements. (The Drizzle documentation indeed shows a transaction example using INSERT.)
19 replies
DTDrizzle Team
Created by Zamiel on 1/1/2024 in #help
How to perform multiple queries?
Hi Angelelz, thanks for the reply. I think what you are suggesting is something like the following code:
await Promise.all([
db.select({ field1: foo.field1 }).from(foo).where(eq(foo.userID, userID)),
db.select({ field2: bar.field2 }).from(bar).where(eq(bar.userID, userID)),
db.select({ field3: baz.field3 }).from(baz).where(eq(baz.userID, userID)),
]);
await Promise.all([
db.select({ field1: foo.field1 }).from(foo).where(eq(foo.userID, userID)),
db.select({ field2: bar.field2 }).from(bar).where(eq(bar.userID, userID)),
db.select({ field3: baz.field3 }).from(baz).where(eq(baz.userID, userID)),
]);
But this would still result in 3 separate queries being sent to the PostgreSQL server, right? They would just be sent all at the same time. If so, I don't think that solves my problem, as it would be inefficient.
19 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
How to check if a row exists in Drizzle?
6 replies
DTDrizzle Team
Created by Zamiel on 12/18/2023 in #help
How do I use NOW() in Drizzle?
Additionally, I did actually come across the docs talking about sql, but it wasn't clear that you can use it inside of a .set call. The only example talks about using it to replace the entire query with SQL using db.execute.
6 replies
DTDrizzle Team
Created by Zamiel on 12/18/2023 in #help
How do I use NOW() in Drizzle?
I feel like using NOW() must be pretty common for people using Postgres.
6 replies
DTDrizzle Team
Created by Zamiel on 12/18/2023 in #help
How do I use NOW() in Drizzle?
Thank you very much! Is this worth adding to the docs?
6 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
to be honest i think i'll just stick with the normal sql code, its easier to read and one less layer of abstraction
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
ah, thanks
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
I can't convert the OP to findFirst because it has a where clause, right?
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
Yeah, I mean, people usually complain about the opposite, seeing User | undefined but wanting to see the keys.
Oh, that's ironic, lol
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
(The inferSelect is a nice trick though that gets me half of the way there at least.)
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
Right, which is exactly the premise of my question. I was envisioning something like setting up the shape of the SELECT call beforehand, such that the type interference can be stored in a User type, and then during runtime inside of the actual get function I can re-use the SELECT schema. Is something like that possible?
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
What I want is to have User | undefined, which makes it much easier to reason about, and so that it matches the name of the variable (user).
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
@Angelelz That's the type, but just imagine with 20+ fields instead of 3.
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
No description
40 replies
DTDrizzle Team
Created by Zamiel on 11/27/2023 in #help
What are the Drizzle conventions for giving names to Drizzle return types?
If that doesn't make sense I can try to explain better
40 replies