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

Use joliCreator function to allow multiple db instances; Add to exports var instead of replacing it. #20

Closed nicjansma closed 12 years ago

nicjansma commented 12 years ago

This looks like a big change via the diff, but there's no change between from the previous var joli = { ... }, it's just wrapped in a new joliCreator() function now. There's a second small change at the end to make CommonJS work -- instead of replacing the exports object, we need to add properties to it. I don't know if replacing exports worked in 1.7.x, but it doesn't work in 1.8.x.

The two changes are:

1) For CommonJS usage, a single var joli in the module doesn't work if you want multiple db instances. Subsequent require('joli').connect()s will overwrite previous connection since they're using the same joli var in the module. Instead, a new joliCreator() function is used that will return a new joli object on each call. For parity with Ti.include(), create a module joli var with this function right away. This allows us to have multiple joli connections with CommonJS usage.

2) CommonJS usage shouldn't replace the entire exports object, it should add to the object as needed. (https://jira.appcelerator.org/browse/TIMOB-5406)

xavierlacot commented 12 years ago

Hi Nic,

I just pushed the changes that you proposed, along with other modifications. See https://github.com/xavierlacot/joli.js/commit/dc0c3a0ae39a20e5f2fc5768255844915b8d5ce3

Thanks a lot,