What does HackerNews think of mammoth?

A type-safe Postgres query builder for TypeScript.

Language: TypeScript

#30 in Node.js
#22 in PostgreSQL
#27 in TypeScript
Super happy user of this [1] it's rather minimalistic but great.

[1] https://github.com/Ff00ff/mammoth

In a type-safe environment I think you should just be able to switch your pur sang SQL builder to another dialect. Because of the type-safety you’ll be able to find incompatibilities at compile time which makes the migration easy enough (ignoring data migration). This avoids creating a weird ad hoc SQL dialect trying to fit all the others in a single API.

I work on Mammoth which is a pur sang Postgres query builder, see https://github.com/Ff00ff/mammoth.

If you’re ok with a query builder interface that matches postgres you might like Mammoth.

https://github.com/Ff00ff/mammoth

Have been experimenting with mammoth [1] for postgresql and am quite happy with how close it is to actual SQL.

[1] https://github.com/Ff00ff/mammoth

Until yesterday, I would've voted Prisma. There was actually a Show HN post recently that debuted Zapatos: https://news.ycombinator.com/item?id=23273543. The top comment also mentions mammoth: https://github.com/Ff00ff/mammoth. Probably going to switch over to one of them as they're closer to raw to raw SQl and well typed.
Looks pretty good. Looks like a good compromise between Prisma [1] and pure pg.

Also the way you show examples is one of the best I've seen so far, with the output right below, optionally showing imports imports and the option to show it in a monaco editor with types.

Could you also compare it to Prisma and Mammoth [2]?

[1]: https://www.prisma.io/ [2]: https://github.com/Ff00ff/mammoth

This seems to be solving mostly the same problem as the following libraries:

[1] https://github.com/phiresky/ts-typed-sql [2] https://github.com/Ff00ff/mammoth [3] https://github.com/AnyhowStep/tsql [4] https://github.com/travigd/vulcyn

A query in one of those looks like the following:

    const rows = await select(list.id, list.createdAt)
      .from(list)
      .where(list.createdAt.gt(now().minus(`2 days`)).or(list.value.eq(0)))
      .limit(10);
The resulting type of `rows` is inferred by TypeScript to the corresponding correct type (`{id: string, createdAt: Date}`)

Prisma solves the problem by generating code, while all of these do it completely in type-level within typescript. Prisma also seems to introduce its own query language, while the above linked libraries stay closer to SQL.

[1] was written by a friend of mine and I'm using it in production to great success. I wouldn't recommend it though because it has repeatedly broken with new TypeScript updates since it uses very complex type structures and the dev has basically given up on it due to the complexity.

[2] is probably the most production-ready, though it has some design choices I'm not sure about.

[3] is the most well-designed, and can handle complex scenarios (including differentiating between join types etc). But it's incomplete so far.

[4] I have not used.

Pure type-level has the advantage of not adding a compile-step and keeping everything in a tool you already know. But all of the above have the disadvantage that the resulting type structures are very complex - most TS devs would have a hard time understanding the internals of the libraries and the resulting type errors can be unreadable. They can also cause the TS compiler to slow down significantly (in the past [1] had exponential compile time when adding a new column, though this has been fixed).

Also, since the TS compiler uses heuristics in multiple places and the type system is not sound, Microsoft has introduced regressions that have broken [1] in every other release.

Mammoth https://github.com/Ff00ff/mammoth is also worth paying attention to. Still early, but a promising approach.
Prisma looks good and I hope it succeeds.

Another interesting and unique approach I'd love to see get more attention is Mammoth[0]. Instead of abstracting the database away, you define columns using its raw primitives (in this case, Postgres) and in return get a type-safe client, along with auto-generated migrations.

I imagine this approach allows you to leverage the features of the database much more easily. And Postgres has quite a lot of rich features to take advantage of! :)

[0]: https://github.com/Ff00ff/mammoth