Live data from Hacker News

Litdb – type safe SQL for JavaScript/TS

litdb.dev

1–10 of 70 posts

Re: Litdb – type safe SQL for JavaScript/TS

#4
I'm sure a lot of effort went into this, but I would rather raw dog my database layer with node-postgres/postgres.js and zod. The decorator heavy implementation is visually very busy. Also, I would not consider any SQL toolkit for serious use unless it comes with a sufficiently competent code generation accompaniment.

Re: Litdb – type safe SQL for JavaScript/TS

#5
I'm really curious to see new DX for the problem of "type-safe queries with intellisense". Litdb provides SQL-like syntax, but it feels like knowing actual SQL should be enough.

If the problem is seen as an editor or build-time problem, rather than a library one, you don't have to learn anything new, and you can save the weight in your dependencies.

A fusion of ts-safeql [0] and postgres_lsp [1] is the closest I've seen to solving this as an editor/build problem.

[0] - https://github.com/ts-safeql/safeql

[1] - https://github.com/supabase-community/postgres_lsp

Re: Litdb – type safe SQL for JavaScript/TS

#7
post #5

I'm really curious to see new DX for the problem of "type-safe queries with intellisense". Litdb provides SQL-like syntax, but it feels like knowing actual SQL should be enough. If the problem is seen as an editor or build-time problem, rather than a library one, you don't have to learn anything new, and you can save the weight in your dependencies. A fusion of ts-safeql [0] and postgres_lsp [1] is the closest I've s…

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

#8
post #6

Seems very similar to [drizzle]( https://orm.drizzle.team/ ) - although drizzle is a more mature product.

From Drizzle's SQL-like example [1] by following classical SQL and including .select() first it wont to be able to provide type-safe queries. E.g. In litdb every from/join returns a new typed query builder where every reference is typed to a joined table that's included in the query.

Drizzle also uses its own custom query language e.g.

    .where(eq(countries.id, 10))
Whereas litdb lets you use the full expressiveness of SQL but ensures all references are typed:

    .where(c => $`${c.id} = 10`)
[1] https://orm.drizzle.team/docs/overview

Re: Litdb – type safe SQL for JavaScript/TS

#9
Hmmm I've recently been evaluating https://www.kysely.dev after finding that Prisma can't support foreign data warehousing (FDW) with Postgres.

I don't really know enough about Kysely yet to make an informed opinion between those two. If you know more than me, can you give me your take??

Edit: Hmmm perhaps based on the primary author's other repos (https://github.com/mythz) it looks like they're a fan of C#. Perhaps it's the LINQ-like syntax that separates them the most.

Re: Litdb – type safe SQL for JavaScript/TS

#10

I'm sure a lot of effort went into this, but I would rather raw dog my database layer with node-postgres/postgres.js and zod. The decorator heavy implementation is visually very busy. Also, I would not consider any SQL toolkit for serious use unless it comes with a sufficiently competent code generation accompaniment.

My feelings are similar and I cringe every time I see a "typesafe" db interface that doesn't run time validate the data.
Post reply on HN