Skip to content

Stable Version 0.11.4 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions dist/js-data-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ module.exports =
return resourceConfig.table || underscore(resourceConfig.name);
}

function filterQuery(resourceConfig, params) {
function filterQuery(resourceConfig, params, options) {
var table = getTable(resourceConfig);
var query = this.query.select(table + '.*').from(table);
var query = options && options.transaction || this.query;
query = query.select(table + '.*').from(table);
params = params || {};
params.where = params.where || {};
params.orderBy = params.orderBy || params.sort;
Expand Down Expand Up @@ -378,7 +379,8 @@ module.exports =
var instance = undefined;
options = options || {};
options['with'] = options['with'] || [];
return this.query.select('*').from(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).then(function (rows) {
var query = options && options.transaction || this.query;
return query.select('*').from(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).then(function (rows) {
if (!rows.length) {
return DSUtils.Promise.reject(new Error('Not Found!'));
} else {
Expand Down Expand Up @@ -410,7 +412,8 @@ module.exports =
var _this4 = this;

attrs = DSUtils.removeCircular(DSUtils.omit(attrs, resourceConfig.relationFields || []));
return this.query(getTable(resourceConfig)).insert(attrs, resourceConfig.idAttribute).then(function (ids) {
var query = options && options.transaction || this.query;
return query(getTable(resourceConfig)).insert(attrs, resourceConfig.idAttribute).then(function (ids) {
if (attrs[resourceConfig.idAttribute]) {
return _this4.find(resourceConfig, attrs[resourceConfig.idAttribute], options);
} else if (ids.length) {
Expand All @@ -426,7 +429,8 @@ module.exports =
var _this5 = this;

attrs = DSUtils.removeCircular(DSUtils.omit(attrs, resourceConfig.relationFields || []));
return this.query(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).update(attrs).then(function () {
var query = options && options.transaction || this.query;
return query(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).update(attrs).then(function () {
return _this5.find(resourceConfig, id, options);
});
}
Expand All @@ -452,8 +456,9 @@ module.exports =
}
}, {
key: 'destroy',
value: function destroy(resourceConfig, id) {
return this.query(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).del().then(function () {
value: function destroy(resourceConfig, id, options) {
var query = options && options.transaction || this.query;
return query(getTable(resourceConfig)).where(resourceConfig.idAttribute, toString(id)).del().then(function () {
return undefined;
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-data-sql",
"description": "Postgres/MySQL/MariaDB/SQLite3 adapter for js-data.",
"version": "0.11.3",
"version": "0.11.4",
"homepage": "http://www.js-data.io/docs/dssqladapter",
"repository": {
"type": "git",
Expand Down