xavierlacot / joli.js

joli.js is an Activerecord-like javascript ORM, particularly suited for being used in the Appcelerator Titanium Mobile framework.
MIT License
267 stars 60 forks source link

Database First #15

Open whitneyland opened 12 years ago

whitneyland commented 12 years ago

Salut Xavier –

Have you ever considered a feature that would generate the javascript necessary to define joli models by reading an existing database?

So for example a utility could exists that takes as input a SQLite database file, and generates the model definitions by emitting javascript, which could then be used by joli.

This is sometimes referred to in the ORM world as a “database first” approach.

The advantage of this approach would be there is no need to manually define models for databases which already exist.

I am interested in your opinion on the feasibility of this approach with joli.

Regards, Lee

xavierlacot commented 12 years ago

Hi WhitneyLand,

Sorry for the delay, I've been rather busy on other topics lately. I have pushed yesterday a new version of joli.js, which allows to embed a pre-existing database. It won't retro-engeneer the database (so you still have to write the definition of the models), but it allows to open a database bundled in your app.

As for a utility which would help converting an existing database into the joli.js model definition file, taht would be a great idea, and actually not complicated to achieve - just a matter of introspecting the database and generate a model object for each of the tables. I don't know if you have gone ahead with this idea during the last few months. If it is the case, you 'are welcome to share your code :)