Objection.js: Model Generation

Created on 14 Apr 2019  路  11Comments  路  Source: Vincit/objection.js

Is anyone interested in a model generation tool?

I.e. generate objection models directly from the db?

I plan to take a stab at this sometime soon probably using gnorm fo a proof of concept

Ciaran

All 11 comments

I think that would be very useful! I've thought of starting a similar project in the past, but never found time for it.

would be great to see this package move towards the sophistication available in ActiveRecord, Django, and its inspiration, Laravel's Eloquent. might be useful to start a feature comparison and goals for achieving desired features

@heisian Are you talking about objection or the gnorm-typescript package? If you are talking about objection, I'm pretty happy with its level of sophistication. Objection was never meant to become Eloquent or Django's ORM. The goal is very very different. Most of the features those ORM's have, are left out by choice. If you want something like that, you should probably check out TypeORM.

The feature discussed here was never meant to be included in objection, neither by me nor @cliedeman, but implemented as a separate module instead.

@koskimas Makes sense, I think - from a reliability perspective I think it is better to keep things as simple as possible.

(rant):
It is a bit unfortunate, though, that if one is using Node.js as a backend, the most mainstream ORM is lackluster. For Node, unlike Ruby, PHP, and Elixir, there is no Rails, Laravel, or Phoenix - a unified framework with most of the community support offering a high level of sophistication, reliability, and extensibility. I've generally felt that the Node.js community is fragmented amongst a number of decent (but not amazing) frameworks, but that is a much larger scope than just the Objection.js project and certainly a discussion for another place.

This issue is not the place for this discussion and this will be my last message here on the subject :smile:

Why are you using node then? You can definitely do the same things using any of the languages you mentioned. I have never missed those kind of frameworks in node. I like to build my apps from small pieces. I use node when I need more flexibility. Frameworks like django are awesome for most projects, but when you build something really custom and complex, they often get in the way. Most of the development time goes to either learning the framework or fighting against it.

I don't feel it's a matter of "sophistication". I've been able to build the most sophisticated software of my career using node.

I created such an open source tool for PostgreSQL.

Anyone interested may see:

  • http://www.pg-generator.com: Uses nunjucks templates to create models. Sample ORM templates including objection are included for reference. Strongly suggested to create your own templates by modifying provided templates.

  • http://www.pg-structure.com: Base tool used by pg-generator to get PostgreSQL schema in JavaScript.

Hope it helps,

@koskimas I agree with you - I like using Node.js for small services to build systems that rely on realtime communication. It excels at quickly getting services up that can support good throughput, asynchronicity, reliability.

To give a bit more context I maintain an API that houses a lot more logic and is closer to a traditional monolithic API that you'll usually find in Rails, Django, etc. The project was started in Node.js before I joined - this is why I mentioned those things in my previous comment. I would not choose to use node in these "heavier" situations, but like to see it in situations where it excels, and my feelings coincide with the pluses you mentioned.

Closing for lack of activity.

I created such an open source tool for PostgreSQL.

Anyone interested may see:

  • http://www.pg-generator.com: Uses nunjucks templates to create models. Sample ORM templates including objection are included for reference. Strongly suggested to create your own templates by modifying provided templates.
  • http://www.pg-structure.com: Base tool used by pg-generator to get PostgreSQL schema in JavaScript.

Hope it helps,

I know this issue is old and closed, but I would like to add that the pg-generator tool by @ozum works perfectly and is easy to customize! It's as easy as this:

$ npm install pg-generator
$ npx pgen template objection-alpha --target models-template
$ npx pgen exec models-template --target models --database <dbname> --user <dbuser> --password <dbpass>

And there you go: the "models" directory will have all the models (including relationMappings and jsonSchema) in separate nodejs modules, ready to be used in the app. Fantastic!

Please consider adding it to the recipes page (I can make a PR if there is interest).

Was this page helpful?
0 / 5 - 0 ratings