Live data from Hacker News

Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

github.com

41–50 of 124 posts

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#41

sql"SOME SQL"; This looks to be a "tagged template": https://basarat.gitbook.io/typescript/future-javascript/temp... . I'm a TS user but hadn't seen that feature before. AFAICT, the library is using a side-side-side-feature (tagged templates) of TS as the core abstraction [1]. Impressive. Might be a little brittle in the face of significant SQL or query composition? Anyhow, I'm a heavier-ORM user but that's impressiv…

Tagged templates are a core feature of JS, not just of TS

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#42

sql"SOME SQL"; This looks to be a "tagged template": https://basarat.gitbook.io/typescript/future-javascript/temp... . I'm a TS user but hadn't seen that feature before. AFAICT, the library is using a side-side-side-feature (tagged templates) of TS as the core abstraction [1]. Impressive. Might be a little brittle in the face of significant SQL or query composition? Anyhow, I'm a heavier-ORM user but that's impressiv…

Not specific to TS, just one of the modern JS features: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Scroll down to the part explaining how to use custom tags.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#43
post #26
post #11

All these things fall short the moment you need real "production" features, such as reliable migrations (writing them by hand? no thanks. Outsourcing to another library like knex? no thanks), transactions, community support, relationship/nested/join queries without a ton of boilerplate and being battle tested. So far, the best thing I've found in the node ecosystem is Prisma [1], and it's better than the alternatives…

I find that most of the production features you mentioned are actually more difficult using a fat ORM. How many hours have i wasted figuring out how i can write and map some complex joins or aggregation query with ? Would have been a 3 minute task if all i had to write was just SQL ... Plus i have a hard time seeing the benefit of Prisma. You are learning an entirely new DSL just to define your schema - which actuall…

>I find that most of the production features you mentioned are actually more difficult using a fat ORM.

Prisma doesn't look like the traditional ORM to me. In fact, the library from the OP uses classes, which prisma and Knex do not use

> How many hours have i wasted figuring out how i can write and map some complex joins or aggregation query with ? Would have been a 3 minute task if all i had to write was just SQL

In my experience this is just a very, very small percent of the cases. Most of the time I find myself doing pretty simple CRUD operations, and the boilerplate for the simple cases goes out of hand quickly, specially when running joins.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#44
post #24
post #11

All these things fall short the moment you need real "production" features, such as reliable migrations (writing them by hand? no thanks. Outsourcing to another library like knex? no thanks), transactions, community support, relationship/nested/join queries without a ton of boilerplate and being battle tested. So far, the best thing I've found in the node ecosystem is Prisma [1], and it's better than the alternatives…

I love Prisma and am a huge fan of Nexus[1] in particular. But it's interesting that you mention transactions as Prisma does not yet support long running transactions[2]. I have a side project that I've been working on for a little while, but I haven't touched it in months as I'm waiting on LRT support. Prisma is being very actively developed though as far as I can see, so I'm confident that there will be a solution…

Because to me, long running transactions are not something that should be done so lightly. A transaction is expensive for the database, so interpolating transactions with requests to external systems, other databases, etc is a bad idea from the get go to me. Just write down what you know at the moment, and update when you have the result, or use a small CQRS implementation for that specific use case. It is more reliable and scalable.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#45
post #11

All these things fall short the moment you need real "production" features, such as reliable migrations (writing them by hand? no thanks. Outsourcing to another library like knex? no thanks), transactions, community support, relationship/nested/join queries without a ton of boilerplate and being battle tested. So far, the best thing I've found in the node ecosystem is Prisma [1], and it's better than the alternatives…

> reliable migrations My experience is that libraries which do handle that for you automatically do a really bad job at it. Writing it by hand and most important thoroughly testing it and trying to avoid doing any changes needing complex migrations is in my experience more reliable on the long run. EDIT: removed inappropriate caps usage

Tell that to the Django ORM. I've used it in really big projects, for really big companies and it never failed on us.

As I said in another thread, the problem is not writing the SQL. The problem is everything else after you have written it (applying on deploy, automating for other's dev envs, rollback, etc)

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#47
post #22

Earlier quoted context omitted.

> reliable migrations (writing them by hand? no thanks. Outsourcing to another library like knex? no thanks) IMHO, "real production features" means also caring about the long term maintenance, performance and reliability of the data. My experience with ORMs (especially ActiveRecord patterns) is that it always becomes a mess once you reach a certain level of complexity. It is very fast to get started, but gets slower…

Interesting, then what is your alternative? It seems like hand-rolling all of your migrations would be an enormous pain on larger projects.

Well, this project is my alternative, and so far I did not see any case where it fails, but I'd be happy to learn.

This migration pattern is quite common in many frameworks, I just removed the query-building abstraction layer.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#48
When using raw SQL in strings, I really miss the automatic formatting that is provided for HTML, TSX and TS with prettier.

Raw SQL query strings also do not compose well and I miss auto completion when writing them (yes, I'm a spoiled kid after so much Typescript usage).

As with everybody else, I didn't like existing ORM/builder approaches, so I built and use my own with type-inference: https://github.com/hoeck/typesafe-query-builder. Any feedback would be great because I have the gut feeling that this one has gone way too far on the type astronaut side of things.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#49
post #40
post #15

Earlier quoted context omitted.

tl;dr: thank god it finally has been done. Long version: i've been seriously frustrated with the state of ORM (in Javascript in particular) for years. Javascript ORM are nice and handy if all you're doing is simple CRUD stuff. If you're starting with more complex relational queries (we're using an RDBMS so why wouldn't we?) you quickly reach the limits of what the ORM can map. If you start doing more complex aggregat…

Thanks for your comment! As you say, one of the main arguments for query-builders is allowing the support of different RDBMS. But in my experience it not only never happens, but the abstraction is never perfect and makes any unsupported edge case impossible to solve without hacking around. There is so much that can be done with SQL that would result in a mess of inefficient spaghetti code...

Also one of the bigger reasons why i dislike SQL abstractions: you usually pick your RDBMS for a reason, because of some vendor-specific features, extensions or something. Abstracting SQL away makes end up with the smallest common denominator which defeats the purpose of choosing one specific RDMBS.

So whenever you have reasons to spend some thoughs on the choice of RDBMS, you'll probably not want to abstract SQL away.

Re: Show HN: ORM for TypeScript with no query-builder, supporting full SQL queries

#50
post #8

still yet to find an ActiveRecord equivalent for javascript.

That's Prisma [1] for me. Coming from Django, I've found prisma even better than the Django ORM, despite not yet as complete. [1] https://www.prisma.io/docs/understand-prisma/why-prisma

This. I haven't tried anything complex but so far Prisma 2 has just been amazing. The API is just so clean and simple.
Post reply on HN