Skip to content

Commit 8ef8970

Browse files
committed
Stable Version 0.4.0.
Fixes #2. Fixes #3.
1 parent 23f3c8d commit 8ef8970

File tree

6 files changed

+235
-74
lines changed

6 files changed

+235
-74
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
##### 0.4.0 - 26 March 2015
2+
3+
###### Backwards compatible bug fixes
4+
- #2 - Should not be saving relations (duplicating data)
5+
- #3 - Need to use removeCircular
6+
17
##### 0.3.0 - 11 March 2015
28

3-
- Converted to ES6.
9+
###### Other
10+
- #1 - Converted to ES6.
411

512
##### 0.2.0 - 25 February 2015
613

CONTRIBUTING.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# Contributing Guide
22

3-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-sql/issues).
3+
First, support is handled via the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
4+
5+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
6+
7+
- good - Your versions of js-data, js-data-mongodb, etc., relevant console logs/error, code examples that revealed the issue
8+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
9+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
10+
11+
[Github Issues](https://github.com/js-data/js-data-mongodb/issues).
12+
13+
#### Pull Requests
414

515
1. Contribute to the issue that is the reason you'll be developing in the first place
6-
1. Fork js-data-sql
7-
1. `git clone https://github.com/<you>/js-data-sql.git`
8-
1. `cd js-data-sql; npm install; bower install;`
16+
1. Fork js-data-mongodb
17+
1. `git clone https://github.com/<you>/js-data-mongodb.git`
18+
1. `cd js-data-mongodb; npm install; bower install;`
919
1. `grunt go` (builds and starts a watch)
1020
1. (in another terminal) `grunt karma:dev` (runs the tests)
1121
1. Write your code, including relevant documentation and tests

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ store.registerAdapter('sql', adapter, { default: true });
5252

5353
### Contributing
5454

55-
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-sql/issues).
55+
First, support is handled via the [Mailing List](https://groups.io/org/groupsio/jsdata). Ask your questions there.
56+
57+
When submitting issues on GitHub, please include as much detail as possible to make debugging quick and easy.
58+
59+
- good - Your versions of js-data, js-data-mongodb, etc., relevant console logs/error, code examples that revealed the issue
60+
- better - A [plnkr](http://plnkr.co/), [fiddle](http://jsfiddle.net/), or [bin](http://jsbin.com/?html,output) that demonstrates the issue
61+
- best - A Pull Request that fixes the issue, including test coverage for the issue and the fix
62+
63+
[Github Issues](https://github.com/js-data/js-data-sql/issues).
64+
65+
#### Pull Requests
5666

5767
1. Contribute to the issue that is the reason you'll be developing in the first place
58-
1. Fork js-data-sql
59-
1. `git clone https://github.com/<you>/js-data-sql.git`
60-
1. `cd js-data-sql; npm install; bower install;`
68+
1. Fork js-data-mongodb
69+
1. `git clone https://github.com/<you>/js-data-mongodb.git`
70+
1. `cd js-data-mongodb; npm install; bower install;`
6171
1. `grunt go` (builds and starts a watch)
6272
1. (in another terminal) `grunt karma:dev` (runs the tests)
6373
1. Write your code, including relevant documentation and tests

dist/js-data-sql.js

Lines changed: 159 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,39 @@ module.exports =
4545
/* 0 */
4646
/***/ function(module, exports, __webpack_require__) {
4747

48+
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
49+
4850
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
4951

5052
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
5153

52-
var knex = __webpack_require__(1);
53-
var JSData = __webpack_require__(2);
54-
var map = __webpack_require__(3);
55-
var keys = __webpack_require__(4);
56-
var isEmpty = __webpack_require__(5);
57-
var upperCase = __webpack_require__(6);
58-
var underscore = __webpack_require__(7);
59-
var toString = __webpack_require__(8);
60-
var P = JSData.DSUtils.Promise;
61-
var contains = JSData.DSUtils.contains;
62-
var forOwn = JSData.DSUtils.forOwn;
63-
var deepMixIn = JSData.DSUtils.deepMixIn;
64-
var forEach = JSData.DSUtils.forEach;
65-
var isObject = JSData.DSUtils.isObject;
66-
var isString = JSData.DSUtils.isString;
54+
var knex = _interopRequire(__webpack_require__(1));
55+
56+
var JSData = _interopRequire(__webpack_require__(2));
57+
58+
var map = _interopRequire(__webpack_require__(3));
59+
60+
var keys = _interopRequire(__webpack_require__(4));
61+
62+
var omit = _interopRequire(__webpack_require__(9));
63+
64+
var isEmpty = _interopRequire(__webpack_require__(5));
65+
66+
var upperCase = _interopRequire(__webpack_require__(6));
67+
68+
var underscore = _interopRequire(__webpack_require__(7));
69+
70+
var toString = _interopRequire(__webpack_require__(8));
71+
72+
var DSUtils = JSData.DSUtils;
73+
var P = DSUtils.Promise;
74+
var contains = DSUtils.contains;
75+
var forOwn = DSUtils.forOwn;
76+
var deepMixIn = DSUtils.deepMixIn;
77+
var forEach = DSUtils.forEach;
78+
var isObject = DSUtils.isObject;
79+
var isString = DSUtils.isString;
80+
var removeCircular = DSUtils.removeCircular;
6781

6882
var reserved = ["orderBy", "sort", "limit", "offset", "skip", "where"];
6983

@@ -181,11 +195,12 @@ module.exports =
181195
find: {
182196
value: function find(resourceConfig, id, options) {
183197
var _this = this;
198+
184199
var instance = undefined;
185200
var fields = [];
186201
options = options || {};
187202
options["with"] = options["with"] || [];
188-
return _this.query.select("*").from(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).then(function (rows) {
203+
return this.query.select("*").from(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).then(function (rows) {
189204
if (!rows.length) {
190205
return P.reject(new Error("Not Found!"));
191206
} else {
@@ -251,7 +266,9 @@ module.exports =
251266
create: {
252267
value: function create(resourceConfig, attrs) {
253268
var _this = this;
254-
return _this.query(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs).then(function (ids) {
269+
270+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
271+
return this.query(resourceConfig.table || underscore(resourceConfig.name)).insert(attrs).then(function (ids) {
255272
if (ids.length) {
256273
return _this.find(resourceConfig, ids[0]);
257274
} else {
@@ -263,15 +280,19 @@ module.exports =
263280
update: {
264281
value: function update(resourceConfig, id, attrs) {
265282
var _this = this;
266-
return _this.query(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).update(attrs).then(function () {
283+
284+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
285+
return this.query(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).update(attrs).then(function () {
267286
return _this.find(resourceConfig, id);
268287
});
269288
}
270289
},
271290
updateAll: {
272291
value: function updateAll(resourceConfig, attrs, params, options) {
273292
var _this = this;
274-
return filterQuery.call(_this, resourceConfig, params, options).then(function (items) {
293+
294+
attrs = removeCircular(omit(attrs, resourceConfig.relationFields || []));
295+
return filterQuery.call(this, resourceConfig, params, options).then(function (items) {
275296
return map(items, function (item) {
276297
return item[resourceConfig.idAttribute];
277298
});
@@ -288,8 +309,7 @@ module.exports =
288309
},
289310
destroy: {
290311
value: function destroy(resourceConfig, id) {
291-
var _this = this;
292-
return _this.query(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).del().then(function () {
312+
return this.query(resourceConfig.table || underscore(resourceConfig.name)).where(resourceConfig.idAttribute, toString(id)).del().then(function () {
293313
return undefined;
294314
});
295315
}
@@ -356,5 +376,123 @@ module.exports =
356376

357377
module.exports = require("mout/lang/toString");
358378

379+
/***/ },
380+
/* 9 */
381+
/***/ function(module, exports, __webpack_require__) {
382+
383+
var slice = __webpack_require__(10);
384+
var contains = __webpack_require__(11);
385+
386+
/**
387+
* Return a copy of the object, filtered to only contain properties except the blacklisted keys.
388+
*/
389+
function omit(obj, var_keys){
390+
var keys = typeof arguments[1] !== 'string'? arguments[1] : slice(arguments, 1),
391+
out = {};
392+
393+
for (var property in obj) {
394+
if (obj.hasOwnProperty(property) && !contains(keys, property)) {
395+
out[property] = obj[property];
396+
}
397+
}
398+
return out;
399+
}
400+
401+
module.exports = omit;
402+
403+
404+
405+
406+
/***/ },
407+
/* 10 */
408+
/***/ function(module, exports, __webpack_require__) {
409+
410+
411+
412+
/**
413+
* Create slice of source array or array-like object
414+
*/
415+
function slice(arr, start, end){
416+
var len = arr.length;
417+
418+
if (start == null) {
419+
start = 0;
420+
} else if (start < 0) {
421+
start = Math.max(len + start, 0);
422+
} else {
423+
start = Math.min(start, len);
424+
}
425+
426+
if (end == null) {
427+
end = len;
428+
} else if (end < 0) {
429+
end = Math.max(len + end, 0);
430+
} else {
431+
end = Math.min(end, len);
432+
}
433+
434+
var result = [];
435+
while (start < end) {
436+
result.push(arr[start++]);
437+
}
438+
439+
return result;
440+
}
441+
442+
module.exports = slice;
443+
444+
445+
446+
447+
/***/ },
448+
/* 11 */
449+
/***/ function(module, exports, __webpack_require__) {
450+
451+
var indexOf = __webpack_require__(12);
452+
453+
/**
454+
* If array contains values.
455+
*/
456+
function contains(arr, val) {
457+
return indexOf(arr, val) !== -1;
458+
}
459+
module.exports = contains;
460+
461+
462+
463+
/***/ },
464+
/* 12 */
465+
/***/ function(module, exports, __webpack_require__) {
466+
467+
468+
469+
/**
470+
* Array.indexOf
471+
*/
472+
function indexOf(arr, item, fromIndex) {
473+
fromIndex = fromIndex || 0;
474+
if (arr == null) {
475+
return -1;
476+
}
477+
478+
var len = arr.length,
479+
i = fromIndex < 0 ? len + fromIndex : fromIndex;
480+
while (i < len) {
481+
// we iterate over sparse items since there is no way to make it
482+
// work properly on IE 7-8. see #64
483+
if (arr[i] === item) {
484+
return i;
485+
}
486+
487+
i++;
488+
}
489+
490+
return -1;
491+
}
492+
493+
module.exports = indexOf;
494+
495+
496+
359497
/***/ }
360498
/******/ ]);

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "js-data-sql",
33
"description": "Postgres/MySQL/MariaDB/SQLite3 adapter for js-data.",
4-
"version": "0.3.0",
4+
"version": "0.4.0",
55
"homepage": "http://www.js-data.io/docs/dssqladapter",
66
"repository": {
77
"type": "git",
@@ -31,8 +31,8 @@
3131
"sqlite"
3232
],
3333
"devDependencies": {
34-
"babel-core": "4.7.8",
35-
"babel-loader": "4.1.0",
34+
"babel-core": "4.7.16",
35+
"babel-loader": "4.2.0",
3636
"chai": "2.1.0",
3737
"grunt": "0.4.5",
3838
"grunt-contrib-watch": "0.6.1",
@@ -44,19 +44,21 @@
4444
"jshint-loader": "0.8.3",
4545
"sinon": "1.12.2",
4646
"time-grunt": "1.1.0",
47-
"webpack": "1.7.2",
47+
"webpack": "1.7.3",
4848
"webpack-dev-server": "1.7.0"
4949
},
5050
"scripts": {
5151
"test": "grunt test"
5252
},
5353
"dependencies": {
54-
"js-data": ">=1.2.0",
55-
"knex": "^0.7.4",
56-
"mariasql": "^0.1.21",
57-
"mout": "0.11.0",
58-
"mysql": "^2.5.5",
59-
"pg": "^4.3.0",
60-
"sqlite3": "^3.0.5"
54+
"mout": "0.11.0"
55+
},
56+
"peerDependencies": {
57+
"js-data": ">=1.5.7",
58+
"knex": ">=0.7.4",
59+
"mariasql": ">=0.1.21",
60+
"mysql": ">=2.5.5",
61+
"pg": ">=4.3.0",
62+
"sqlite3": ">=3.0.5"
6163
}
6264
}

0 commit comments

Comments
 (0)