Future ideas #7
Replies: 2 comments 1 reply
-
|
I was looking exactly for this and was very happy I found Reddit thread https://www.reddit.com/r/typescript/comments/pal8td/request_for_learning_resources_using_template/ after a while. I wanted to use Kysely but was quite disappointed the raw sql as template strings are not type checked. My ideal would be raw type-safe SQL as an initial constructor with the possibility to add extra commands into it. For example, like this: let query = sql`SELECT name, age FROM users WHERE age >= ${adultAge} ORDER BY age`
if (excludeSeniors) {
query = query.where('age', '<', 62)
}
const rows = query.fetch()Kysely can do that I think but the initial SQL is not type checked which is majority of my queries. Only a few of them have conditional parts added. But it would be still better than patching string literals together. I am interested if you hit any problems during your time with this experiment or how you see this approach. |
Beta Was this translation helpful? Give feedback.
-
|
Hey Mišo, I've actually stopped developing this tool.
I've come to the conclusion that currently Typescript does not compile fast
enough for this to be a worthwhile task, and simultaneously I've started
using drizzle-orm. Drizzle's query builder is great in my opinion. It is
type-safe and very close to raw SQL.
…On Tue, Nov 14, 2023 at 11:25 PM Mišo Belica ***@***.***> wrote:
I was looking exactly for this and was very happy I found Reddit thread
https://www.reddit.com/r/typescript/comments/pal8td/request_for_learning_resources_using_template/
after a while.
I wanted to use Kysely but was quite disappointed the raw sql as template
strings are not type checked.
My ideal would be raw type-safe SQL as an initial constructor with the
possibility to add extra commands into it. For example, like this:
let query = sql`SELECT name, age FROM users WHERE age >= ${adultAge} ORDER BY age`
if (excludeSeniors) {
query = query.where('age', '<', 62)}
const rows = query.fetch()
Kysely can do that I think but the initial SQL is not type checked which
is majority of my queries. Only a few of them have conditional parts added.
But it would be still better than patching string literals together.
I am interested if you hit any problems during your time with this
experiment or how you see this approach.
—
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHNYDWEXN4EPGF3ZP7WY373YEPOUTAVCNFSM6AAAAAA2MYCCN2VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TKNRZHE3DG>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Thanks,
Yuval Peled
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there, Yuval
Have you seen this issue?
microsoft/TypeScript#33304
It looks like this request is now on the "design docket", which hopefully means they're about to discuss it.
I'm sure you're aware of
sql-template-strings- another awesomely minimalistic approach.You most likely chose string literals because you knew string templates wouldn't work?
And maybe that's why your project stalled after this proof on concept?
I'm sure you're aware of Kysely as well? Impressive project - it provides good type safety, but it still gets there by owning too many responsibilities for my taste.
The ideal for me would be SQL as string template literals, with the option to define some simple schema constants with column-specific "to SQL" and "from SQL" value/type transformations.
I built this for PHP some years back - this is also a query-builder, but I'd like to go even simpler than that. What I would like to bring over from this project is the mapping feature, which works over batches of results - as well as a built-in mapper, which applies simple column value transformations like this one, all of it while streaming. None of those things are very complex (and they'd be even simpler in TS) but they provide a lot of utility.
Could you see this project heading anywhere in that direction?
If so, I'd probably like to jump in and help out... just as soon as they get the support for SQL template strings working. 😄
Beta Was this translation helpful? Give feedback.
All reactions