dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 376 forks source link

reversere engineer table/database into models #105

Open GoNode5 opened 11 years ago

GoNode5 commented 11 years ago

thnx for node-orm2.

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

dresende commented 11 years ago

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');
GoNode5 commented 11 years ago

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

mspisars commented 11 years ago

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

flosse commented 11 years ago

+1

dresende commented 11 years ago

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.

kcphysics commented 10 years ago

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 commented 10 years ago

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?

mspisars commented 10 years ago

I'm for a grunt task.

On Tue, Feb 25, 2014 at 9:11 AM, Lawrence Selvy notifications@github.comwrote:

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

mspisars@gmail.com

phone: 704.900.3130

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

flosse commented 10 years ago

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

kcphysics commented 10 years ago

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

dxg commented 10 years ago

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 ?

kcphysics commented 10 years ago

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.

dxg commented 10 years ago

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?

dresende commented 10 years ago

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.

kcphysics commented 10 years ago

@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?

dresende commented 10 years ago

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.

kcphysics commented 10 years ago

Alright, sounds good. I'll work on getting the script working with sql-ddl-sync. On Feb 28, 2014 7:07 PM, "Diogo Resende" notifications@github.com 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 .

thomasgroch commented 8 years ago

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

omomthings commented 7 years ago

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.