Live data from Hacker News

Litdb – type safe SQL for JavaScript/TS

litdb.dev

61–70 of 70 posts

Re: Litdb – type safe SQL for JavaScript/TS

#61
post #15
post #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#. Perhap…

Right, it's effectively a spiritual port of our C# LINQ OrmLite library [1]. I've been using a lot of bun:sqlite [2] lately which has an amazing DX and lets you create lots of stand-alone .ts scripts (i.e. without deps) to access SQLite DB's. The only issue is that I didn't want all my SQL queries to be coupled to a single driver, so I created litdb to provide a RDBMS-agnostic API + Query Builders so all my queries c…

Thanks for the detailed explanation! I think it would be great to drop this (or something like this) in the project README.

Re: Litdb – type safe SQL for JavaScript/TS

#64
post #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.

I created https://github.com/a2lix/schemql that maybe could fit your demand.

Re: Litdb – type safe SQL for JavaScript/TS

#65
post #2

Title makes it seem as if you writr typesafe SQL, but you really use a builder which generates SQL for you. I was expecting something more like sqlx, which I believe provides compile-time checking for SQL queries without a DSL, but for Rust

Right, my sentiments too. I was expecting type-safe SQL. The manifold-sql[1] project has this down.

1. https://github.com/manifold-systems/manifold/blob/master/man...

Re: Litdb – type safe SQL for JavaScript/TS

#66
post #22

nit: i feel like this is a typesafe sql query builder and not typesafe sql. i'm always on the look out for _good_ typesafe sql which i have yet to encounter.

Agree, I want to write raw SQL and have some tool that validate it and generate the correct return type for it, similar to sqlx[0], but AFAIK there is no such tool yet in Typescript land, there are a few that are taking that direction. [0] https://github.com/launchbadge/sqlx

Something like manifold-sql[1] for ts would be awesome.

1. https://github.com/manifold-systems/manifold/blob/master/man...

Re: Litdb – type safe SQL for JavaScript/TS

#67
post #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

You should check out sdf (semantic data fabric). https://sdf.com

Re: Litdb – type safe SQL for JavaScript/TS

#68
post #53

Type-safe query builders sound great in theory, but it seems there are always edge cases that are not supported by the query builder. For example, the issue asking for deferrable constraint support for Postgres in drizzle has been open for about a year: https://github.com/drizzle-team/drizzle-orm/issues/1429 In any non-trivial application, you are increasingly likely to run into something that your database supports…

This is the reason I find it odd that most of these tools require their own system/DSL for defining the schema and the migrations. Using vanilla SQL DDL for that part gives you more escape hatches. This is possible with e.g. kysely + kysely-codegen.

Re: Litdb – type safe SQL for JavaScript/TS

#69
post #22

nit: i feel like this is a typesafe sql query builder and not typesafe sql. i'm always on the look out for _good_ typesafe sql which i have yet to encounter.

Agree, I want to write raw SQL and have some tool that validate it and generate the correct return type for it, similar to sqlx[0], but AFAIK there is no such tool yet in Typescript land, there are a few that are taking that direction. [0] https://github.com/launchbadge/sqlx

There is Slonik [1] for instance.

[1] https://github.com/gajus/slonik

Post reply on HN