News for hackers. Stuff that matters.
Re:Litdb – type safe SQL for JavaScript/TS by nikeee on Thursday December 05, 2024 @08:25PM (#42335019)
I played around with parsing and inferring SQL on a type level. Simple stuff works, but as soon as you have a DB-specific dialect, it becomes hard. Parsing is already hard enough, but type inference on a type level is just not maintainable on the long run.

You can find it here: https://github.com/nikeee/sequelts

Re:Litdb – type safe SQL for JavaScript/TS by norman784 on Friday December 06, 2024 @05:06AM (#42338215)
I was thinking on how a library could work with the type inference, one idea that came to mind is to have some script running in the background (if you are using a bundler, you might be able to hook into it) that search for all sql tag templates, execute them against a live database to validate and get the result structure. This is how sqlx[0] works and might is worth exploring more in deep.

One downside of course is that AFAIK typescript is not powerful enough to match all queries to types, so my idea was to build a .d.ts file that maps the queries with the result.

ts-safeql seems to work with a lsp plugin? I didn't dig into how lsp and plugin works, so I cannot speak of if my approach will work with it, but I suppose no, because it needs to generate files.

[0] https://github.com/launchbadge/sqlx

Re:Litdb – type safe SQL for JavaScript/TS by alexkbog on Friday December 06, 2024 @02:11PM (#42343123)
You should check out sdf (semantic data fabric). https://sdf.com