Live data from Hacker News

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

github.com

51–60 of 124 posts

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

#51
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 actually much prefer writing migrations by hand. It's actually pretty simple, and it gives you complete control over the schema.

Same here, it's way more flexible. I find it quite important to know exactly what will be run as a migration given how critical changing the schema can be.

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

#52
Seems similar to PureORM[1]. It allows you to write regular native SQL and receive back properly structured (nested) pure business objects.

The name pureORM reflects both that it is pure ORM (there is no query builder dimension) as well as the purity of the mapped Objects.

[1] https://github.com/craigmichaelmartin/pure-orm

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

#53
post #15
post #2

For a long time, I have been frustrated with the state-of-the-art about the existing ORMs. I like things to be simple, but somehow all ORMs seems to be bloated and overcomplicate a lot of things. When designing a new project, I have been trying to find a more satisfying design while avoiding the existing ORMs. I especially wanted to use proper SQL rather than reducing it's syntax to fit it in another language. This i…

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…

IMHO one of the key use cases for query builders like Knex is that you can programmatically build up a query in a very clean fashion.

Otherwise you need to resort to workarounds like concatenating strings, or building the biggest possible query and using boolean toggles to disable parts of your query.

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

#54
post #39

Earlier quoted context omitted.

I actually much prefer writing migrations by hand. It's actually pretty simple, and it gives you complete control over the schema.

Agree, it's pretty simple writing them. The problem is deciding which ones to apply for a given version of your application, when, running them automatically on each of your developer's laptops, your testing environment, and automate and keep track of all the changes. Or are we talking of just writing a "CREATE TABLE..." and hand it over the wall to the ops? I agree that's simpler. Not something I like to do these da…

1. create a "schema_version" table

2. have a unique, incremental migration ID in each migration filename

3. apply them one by one in order depending on the current schema_version from the target environment, and update the schema_version accordingly

4. rollback the transaction in case of error, otherwise commit and enjoy your updated schema

I used golang-migrate/migrate in production for the past 3 years to do exactly this but you can easily implement it yourself too. golang-migrate/migrate can be used either as a Go library or as a CLI tool.

https://github.com/golang-migrate/migrate

Or did I misunderstand the issues you're talking about?

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

#55
post #43
post #26

Earlier quoted context omitted.

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…

> 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.

That's true, although the most frustrating percent of the cases :)

I think what KISS will eventually need is some simple toolbelt for the basic CRUD queries, e.g. expanding lists of column names, dealing with casing (snake_case to camelCase). So making the stuff you write 90% of the times easy without inventing a custom SQL abstraction.

MyBatis (which i mentioned in another comment) approached this for example with sql snippets one could re-use in queries.

KISS enables the same thing by allowing nesting of tagged sql strings. I guess time will show which additional helpers are needed to make the devs life easy/reduce the boilerplate for the simple queries.

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

#58
Thank you for creating Kiss ORM. I have even created a HackerNews account to be able to comment on it.

I have been searching for this type of ORM in Typescript for a while. I agree to write raw SQL for queries. So easy and expressive and one less layer of abstraction. I also agree on the value of the respository pattern and methods for CRUD operations to not write this SQL by hand. Making the loading of associations an explicit decision is also the right way to go. The Rails community has good experience with performance surprises of automatic loading of relationships.

Personally I found the most useful ORM in Ecto for the Elixir (Erlang) language: https://hexdocs.pm/ecto/Ecto.html (ignoring the query capability). It follows very much the repository pattern like Kiss ORM. The API is a bit more succinct (you only define a schema for each table and use a generic repository instead of subclassing for each table) but that might be possible only due to Elixir's language capabilities like meta-programming.

One piece of Ecto that might be a win to implement in Kiss ORM is the "Changeset" pattern to give a canonical, succinct and productive solution to validate data (https://hexdocs.pm/ecto/Ecto.Changeset.html#content). For example have a look at how Ecto unifies validation (checked without hitting the DB) and constraints (checked by hitting the DB) in a single API. This type of functionality increases the usefulness of the repository's CRUD operations.

Thank's for your initiative to create KISS ORM. I will sure try it out and follow along it's evolution.

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

#59
post #15
post #2

For a long time, I have been frustrated with the state-of-the-art about the existing ORMs. I like things to be simple, but somehow all ORMs seems to be bloated and overcomplicate a lot of things. When designing a new project, I have been trying to find a more satisfying design while avoiding the existing ORMs. I especially wanted to use proper SQL rather than reducing it's syntax to fit it in another language. This i…

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…

I don't undertand your frustration. Virtually every ORM I know has a query builder which as a .raw() function that lets you do anything you want.

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

#60
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…

Thanks for sharing your thoughts about Prisma.

> Plus i have a hard time seeing the benefit of Prisma

Prisma is supposed to improve your productivity and confidence when working with a database. It does so with a strong focus on type safety.

Most ORMs and query builders in the Node.js/TypeScript ecosystem do not provide the level of type safety that Prisma does.

For example in a blog with users and posts (1:n) querying a user and related posts looks as follows:

  const user = await prisma.user.findOne({
      where: {
        id: 1
      },
      include: {
        posts: true
      }
    })

  console.log(user.posts)

The user object will have the correct TypeScript type, including the posts object. If you remove the include object from the findOne call and avoid fetching related posts, the user's type will change. This approach to type safety helps in catching many problems at build time.

It's possible because of the Prisma schema, which is the single source of truth for both the database schema and the generated TypeScript client.

You don't have the burden of mapping between the database schema and the types in their application. Besides that, it's a declarative and concise description for the database schema and is database agnostic.

The type safety features come at "zero-cost" because you don't have to write all the TypeScript types and mappings to the database. Prisma generates the TypeScript client from your Prisma schema.

> You are learning an entirely new DSL just to define your schema - which actually isn't that far off standard JS or TS syntax-wise

The Prisma schema is actually fundamentally different to JS or TS because it's declarative rather than imperative.

Post reply on HN