delight
delight
Explore posts from servers
DTDrizzle Team
Created by I am a Dev on 10/3/2023 in #help
Drizzle support SELECT FOR UPDATE of postgres to avoid logical race conditions ?
Prisma often times does multiple queries ... you should check the emitted sql by logging it to console - so that you can figure what prisma does.
23 replies
DTDrizzle Team
Created by divby0 on 10/3/2023 in #help
Get Raw query string of a relational query in drizzle
👍😊
7 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Absolutely, I think that is definitively the right deccission. With the magic sql operator you cover all of those (for the time being)... having dedicated functions for Aggregation etc. is just a nice to have and for sure can be postponed. I guess maybe count might be an exception - not because it is hard to implement with sql but because it is so common that ppl might expect a function for it. But those are just my thoughts + when ppl don't stumble at count () over this they will do just a little bit later - so IMO it is fine the way it is right now. But the docs wasn't that obvious to me at that part + maybe there could be a little more verbose example on .mapWith()
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
yes I understood this by now ... what I mean it is not obvious by reading the docs
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
I think it is little confusing for a drizzle beginner to have "both" sql<T> and the .mapWith() method. Maybe the docs could mention that .mapWith() is superseeding the T - Type / making it obsolete. Well that is still not correct. Well T is just for TS compiler while mapWith() does the mapping - magic + it somehow sets the typing (at least in my use-cases).
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
especially schema definition is awesome compared to ... you know
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
for sure will do as I'm still in a kind of evaluation phase ... but I'm really impressed with drizzle so far.
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Yes I think it does ... need to double check ... but in that case I want the latest date only so needs to be max(date)
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
I'm using postgres right now ... I can/will also try with pg. Using .mapWith(Number) does the right thing for now.
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
I see ... I'll try to play with it
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Ahh nice ... this also works with the max(Date) query I used 👍
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
btw. I just double checked in an old prisma project. Prisma infers the correct types from the database even on a prisma.$queryRaw native sql query. For sure that is no reason to go back to it - but I guess that there might be potential to infer types from the query results. So far drizzle seem to somehow stringify all results.
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Yes that works ... thank you 👍🙂
numberOfLogins: sql<number>`count(${loginlog.createdAt})`
.mapWith(Number)
.as('numberOfLogins'),
numberOfLogins: sql<number>`count(${loginlog.createdAt})`
.mapWith(Number)
.as('numberOfLogins'),
for count and
latestLoginDate: sql<Date>`max(${loginlog.createdAt})`
.mapWith(loginlog.createdAt)
.as('latestLoginDate'),`
latestLoginDate: sql<Date>`max(${loginlog.createdAt})`
.mapWith(loginlog.createdAt)
.as('latestLoginDate'),`
which seems a little verbose - but ultimately works. Even though somehow it seems to still stringify the Date - at least it looks like it when logging to the console. .mapWith(loginlog.createdAt) doesn't make any difference here ... contrary to the count. Why not use the T - type in sql<T> to map the result type too? > Would make it less verbose.
36 replies
DTDrizzle Team
Created by divby0 on 10/3/2023 in #help
Get Raw query string of a relational query in drizzle
Can't you simply activate the logging https://orm.drizzle.team/docs/goodies#logging that should give you the executed sql on the console
7 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
for example: As of now we can only get a string representing the count - if we want to do something like: Select count (*) from X in drizzle
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
As stated at https://orm.drizzle.team/docs/sql#sqlt the T in sql<T> has not effect on the resulting type
numberOfLogins: sql<number>`count(${loginlog.createdAt})`.as('numberOfLogins'),
latestLoginDate: sql<Date>`max(${loginlog.createdAt})`.as('latestLoginDate'),
numberOfLogins: sql<number>`count(${loginlog.createdAt})`.as('numberOfLogins'),
latestLoginDate: sql<Date>`max(${loginlog.createdAt})`.as('latestLoginDate'),
only difference is that drizzle can introspect into e.g. (property) numberOfLogins: SQL.Aliased<number> . I wished drizzle would cast/map the types for primitive values like number etc. What is the recomended way to coerce the results to the right types? zod ?
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
works perfectly, thank you 🙂
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Drizzle is simply awesome ❣️ Powerful query builder, that is easy to get used to + fine grained schema definition / migration without extra build steps. The only thing I couldn't figure out yet is how to do a ORDER BY xyz DESC NULLS LAST The common ORDER BY xyz DESC is trivial.
36 replies
DTDrizzle Team
Created by delight on 10/2/2023 in #help
Attempting to get a Joined Subquery query into drizzle crud api
Wow .. that was it ... I totally overlooked the .as('name') . Thank you so much. Now typescript stopped yelling at me ... need to try if the query works as expected - but I guess I'll figure it out from here if something is not working right. Thank you again 👍🏽
36 replies
DTDrizzle Team
Created by delight on 9/30/2023 in #help
Drizzle Studio on postgres
oh you still have the pg driver in your dependencies ... I see
9 replies