node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

reversere engineer table/database into models

Open GoNode5 opened this issue 11 years ago • 19 comments

thnx for node-orm2.

Would reversere engineer an existing table/database to node-orm2 model an possibilty in the future?

GoNode5 avatar Apr 09 '13 08:04 GoNode5

I already thought about it. It's also in my plans. Something like:

// look for table 'person' in database and populate properties / associations in model
var Person = db.discover('person');

dresende avatar Apr 09 '13 09:04 dresende

sounds great !!! Would also be easier to adopt to orm without retyping everything...

GoNode5 avatar Apr 09 '13 09:04 GoNode5

I like this, but also would be nice to dump the discovered model to the console or file (for when migrating projects)

mspisars avatar Apr 12 '13 03:04 mspisars

+1

flosse avatar Apr 23 '13 20:04 flosse

This could be done now using plugins. I'm going to try to create a plugin and will post the link here when I have something.

dresende avatar Apr 25 '13 14:04 dresende

Has there been any progress on this?

A data-intensive application I am working on needs it. If there hasn't been much done, I plan to start tackling this for at least PostgreSQL.

kcphysics avatar Feb 20 '14 20:02 kcphysics

So I have a working piece of code that reverse engineers orm models from a PostgreSQL database. I need to generalize this and write tests for it, but I do have a question. To launch this command, to generate the models, how would we do this.

Make it a script available when you globally install? Make a grunt task? Would anyone be opposed to grunt?

kcphysics avatar Feb 25 '14 14:02 kcphysics

I'm for a grunt task.

On Tue, Feb 25, 2014 at 9:11 AM, Lawrence Selvy [email protected]:

So I have a working piece of code that reverse engineers orm models from a PostgreSQL database. I need to generalize this and write tests for it, but I do have a question. To launch this command, to generate the models, how would we do this.

Make it a script available when you globally install? Make a grunt task? Would anyone be opposed to grunt?

Reply to this email directly or view it on GitHubhttps://github.com/dresende/node-orm2/issues/105#issuecomment-36010401 .

Michael S. Pisarski

[email protected]

phone: 704.900.3130

"I cannot imagine how the clockwork of the universe can exist without a clockmaker." - Voltaire

mspisars avatar Feb 25 '14 14:02 mspisars

I'm for https://github.com/joliss/broccoli or http://gulpjs.com/

flosse avatar Feb 25 '14 17:02 flosse

What does dresende think about this? It would add a dependency to the library.

kcphysics avatar Feb 25 '14 19:02 kcphysics

ORM needs to be independent of grunt, broccoli, cabbage or anything else. It should have a function that can be called by any of the mentioned frameworks. One could also create some sort of executable if need be - which just calls this function.

I'm curious about the code itself; does it in some way integrate with sql-ddl-sync which is now a dependency of ORM ?

dxg avatar Feb 25 '14 22:02 dxg

Currently the code is implemented as a script.

It currently is not specifically integrated with sql-ddl-sync. The code is entirely dependent on ORM and does raw queries to inspect the PostgreSQL meta catalog.

The issue I am having is that you this runs outside of any framework or use of ORM. IT is its own application basically, looking at the schema within the Postgres and then making model definitions for it. It prints all of these out to stdout so they can later be used in a file inside of a framework.

I understand wanting to keep node-orm2 separate from all of these task runners, in that case the best that can be done is to have a script file somewhere and during global installation install it somewhere to be used. I think that's about all we can do.

kcphysics avatar Feb 26 '14 16:02 kcphysics

Ahh makes sense. Given that it is totally postgres specific & it's own standalone app, I think it would make sense to make it a separate package and we can have a link in the readme. If we put it in ORM core, people will expect it to 'just work' in mysql & sqlite and so that may introduce confusion. What are your thoughts?

dxg avatar Feb 28 '14 03:02 dxg

sql-ddl-sync could help this task a lot. I'm not sure if it's feasible but it could be a more clean way of doing it since it already abstracts the several drivers.

dresende avatar Feb 28 '14 11:02 dresende

@dxg I am working on generalizing the script right now. Basically it just uses the meta-data catalogs (information_schema databases/schema) for the SQL databases and fill in everything that it can from the definitions therein. Hopefully soon I will be able to get this to work with sql-ddl-sync's Dialects and all SQL databases. Unfortunately, for no-sql databases, this sort of inspection does not necessarily make sense, as every entry in a group may be significantly different.

@dresende I am going to try and integrate with sql-ddl-sync, but the actual script should remain with orm, as it builds orm models.

I do have a general question that this sort of hints at, how do you keep all these sub-packages in line? For instance, I may have to change some in the sql-ddl-sync dialects to get this integrated properly, but that means everything has to be updated for the effects to be felt in orm2. Do you just make sure when updating for npm usage you update all of the simultaneously?

kcphysics avatar Feb 28 '14 13:02 kcphysics

First, you suggest or request the changes on the sql-ddl-sync. Then we can publish a new version of it and orm can update it's dependencies and publish a version too later on.

dresende avatar Mar 01 '14 00:03 dresende

Alright, sounds good. I'll work on getting the script working with sql-ddl-sync. On Feb 28, 2014 7:07 PM, "Diogo Resende" [email protected] wrote:

First, you suggest or request the changes on the sql-ddl-sync. Then we can publish a new version of it and orm can update it's dependencies and publish a version too later on.

Reply to this email directly or view it on GitHubhttps://github.com/dresende/node-orm2/issues/105#issuecomment-36407846 .

kcphysics avatar Mar 01 '14 00:03 kcphysics

I just want to share this with you guys. https://github.com/sequelize/sequelize-auto

thomasgroch avatar Apr 21 '16 01:04 thomasgroch

Hello there, four years later and still nothing.. To be honest I first tried Sequelize (yes the concurrent 😆 ) but I have faced a lot of issues with the relations between tables. Then I have switched to orm2 but faced this problem.. However I'm not here to complain, just wanted to know if there is any evolution with this, I don't want to make a whole script that I would throw to trash right after that.. ORM is awesome, but need this (really annoying) feature. Thank you.

omomthings avatar Apr 17 '17 18:04 omomthings