Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of ssh://github.com/dresende/node-orm

* 'master' of ssh://github.com/dresende/node-orm:
  add callback support for sync()
  • Loading branch information...
commit 69ba440c5f06f3a08e5494e97d51d6173b81723b 2 parents 19ef703 + 7206c75
@dresende authored
View
8 lib/databases/mongodb.js
@@ -26,9 +26,13 @@ DBClient.prototype.getCollection = function (collection, cb) {
})(this));
};
-DBClient.prototype.createCollection = function (collection, fields, assocs) {
+DBClient.prototype.createCollection = function (collection, fields, assocs, callback) {
var _collection = collection.toLowerCase(collection);
- this._client.createCollection(_collection, function () {});
+ this._client.createCollection(_collection, function () {
+ if (callback !== undefined) {
+ callback(true);
+ }
+ });
return;
};
View
11 lib/databases/mysql.js
@@ -8,7 +8,7 @@ function DBClient(client) {
DBClient.prototype.getClient = function () {
return this._client;
};
-DBClient.prototype.createCollection = function (collection, fields, assocs, opts) {
+DBClient.prototype.createCollection = function (collection, fields, assocs, opts, callback) {
var _table = collection.toLowerCase();
var _query = "", _fields = [], _indexes = [];
var k, assoc_fields;
@@ -127,11 +127,10 @@ DBClient.prototype.createCollection = function (collection, fields, assocs, opts
_query = _query.replace("%values", _fields.join(", "));
this._client.query(_query, function (err, info) {
- /*
- console.log(err);
- console.log(info);
- console.log("collection synced");
- */
+ if (callback !== undefined) {
+ var success = !err;
+ callback(success);
+ }
});
};
DBClient.prototype.selectRecords = function (collection, config) {
View
7 lib/databases/postgresql.js
@@ -30,7 +30,7 @@ DBClient.prototype.getClient = function () {
return this._client;
};
-DBClient.prototype.createCollection = function (collection, fields, assocs, opts) { /* opts not used yet */
+DBClient.prototype.createCollection = function (collection, fields, assocs, opts, callback) { /* opts not used yet */
var _table = collection.toLowerCase();
var _query = "CREATE TABLE \"%table\" (%values)", _fields = [], _indexes = [];
_query = _query.replace("%table", _table);
@@ -129,6 +129,11 @@ DBClient.prototype.createCollection = function (collection, fields, assocs, opts
self._client.query("CREATE INDEX \"" + _table + "_" + _indexes[i] + "_idx\" " + "ON \"" + _table + "\"(" + _indexes[i] + ")", emptycb);
}
}
+
+ if (callback !== undefined) {
+ var success = !err;
+ callback(success);
+ }
});
};
DBClient.prototype.selectRecords = function (collection, config) {
View
4 lib/orm.js
@@ -364,7 +364,7 @@ ORM.prototype.define = function (model, fields, colParams) {
return this;
};
- Model.sync = function (opts) {
+ Model.sync = function (opts, callback) {
for (var i = 0; i < associations.length; i++) {
if (!associations[i].hasOwnProperty("opts") || !associations[i].opts.hasOwnProperty("properties")) continue;
@@ -386,7 +386,7 @@ ORM.prototype.define = function (model, fields, colParams) {
}
}
}
- orm._db.createCollection(model, fields, associations, opts);
+ orm._db.createCollection(model, fields, associations, opts, callback);
};
Model.clear = function (callback) {
orm._db.clearRecords(model, {
Please sign in to comment.
Something went wrong with that request. Please try again.