Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #215 from avoidwork/edge
Browse files Browse the repository at this point in the history
API change
  • Loading branch information
avoidwork committed Feb 23, 2013
2 parents dfa356e + 86a2300 commit f1803b5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
41 changes: 34 additions & 7 deletions lib/abaaso.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license BSD-3 <https://raw.github.com/avoidwork/abaaso/master/LICENSE>
* @link http://abaaso.com
* @module abaaso
* @version 3.4.26
* @version 3.4.27
*/

(function (global) {
Expand Down Expand Up @@ -2532,6 +2532,30 @@ var data = {
return this.storage(arg || this, "set");
},

/**
* Selects records based on an explcit description
*
* @param {Object} where Object describing the WHERE clause
* @return {Array} Array of records
*/
select : function (where) {
var result;

if (!(where instanceof Object)) throw Error(label.error.invalidArguments);

result = this.get().filter(function (rec) {
var match = true;

utility.iterate(where, function (v, k) {
if (rec.data[k] !== v) return (match = false);
});

return match;
});

return result;
},

/**
* Creates or updates an existing record
*
Expand Down Expand Up @@ -2785,9 +2809,10 @@ var data = {
* @param {String} query SQL (style) order by
* @param {String} create [Optional, default behavior is true, value is false] Boolean determines whether to recreate a view if it exists
* @param {String} sensitivity [Optional] Sort sensitivity, defaults to "ci" (insensitive = "ci", sensitive = "cs", mixed = "ms")
* @return {Array} View of data
* @param {Object} where Object describing the WHERE clause
* @return {Array} View of data
*/
sort : function (query, create, sensitivity) {
sort : function (query, create, sensitivity, where) {
if (query === undefined || String(query).isEmpty()) throw Error(label.error.invalidArguments);
if (!regex.sensitivity_types.test(sensitivity)) sensitivity = "ci";

Expand Down Expand Up @@ -2886,7 +2911,7 @@ var data = {
return sorted;
};

result = crawl(queries, this.records);
result = crawl(queries, where === undefined ? this.records : this.select(where));
this.views[view] = result;
return result;
},
Expand Down Expand Up @@ -3333,7 +3358,8 @@ var datalist = {
};

// Consuming records based on sort
consumed = this.order.isEmpty() ? this.store.get() : this.store.sort(this.order, false, this.sensitivity);
if (this.where === null) consumed = this.order.isEmpty() ? this.store.get() : this.store.sort(this.order, false, this.sensitivity);
else consumed = this.order.isEmpty() ? this.store.select(this.where) : this.store.sort(this.order, false, this.sensitivity, this.where);

// Processing (filtering) records & generating templates
array.each(consumed, function (i) {
Expand Down Expand Up @@ -3526,6 +3552,7 @@ function DataList (element, store, template) {
this.total = 0;
this.sensitivity = "ci";
this.store = store;
this.where = null;
};

// Setting prototype & constructor loop
Expand Down Expand Up @@ -6940,7 +6967,7 @@ var xhr = function () {
XMLHttpRequest, headers, handler, handlerError, state;

headers = {
"User-Agent" : "abaaso/3.4.26 node.js/" + process.versions.node.replace(/^v/, "") + " (" + string.capitalize(process.platform) + " V8/" + process.versions.v8 + ")",
"User-Agent" : "abaaso/3.4.27 node.js/" + process.versions.node.replace(/^v/, "") + " (" + string.capitalize(process.platform) + " V8/" + process.versions.v8 + ")",
"Content-Type" : "text/plain",
"Accept" : "*/*"
};
Expand Down Expand Up @@ -7871,7 +7898,7 @@ return {
update : element.update,
uuid : utility.uuid,
validate : validate.test,
version : "3.4.26",
version : "3.4.27",
walk : utility.walk
};

Expand Down
4 changes: 2 additions & 2 deletions lib/abaaso.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "abaaso",
"description": "abaaso is a modern, lightweight Enterprise class RESTful JavaScript application framework.",
"version": "3.4.26",
"version": "3.4.27",
"homepage": "http://abaaso.com",
"author": {
"name": "Jason Mulligan",
Expand Down
31 changes: 28 additions & 3 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,30 @@ var data = {
return this.storage(arg || this, "set");
},

/**
* Selects records based on an explcit description
*
* @param {Object} where Object describing the WHERE clause
* @return {Array} Array of records
*/
select : function (where) {
var result;

if (!(where instanceof Object)) throw Error(label.error.invalidArguments);

result = this.get().filter(function (rec) {
var match = true;

utility.iterate(where, function (v, k) {
if (rec.data[k] !== v) return (match = false);
});

return match;
});

return result;
},

/**
* Creates or updates an existing record
*
Expand Down Expand Up @@ -1091,9 +1115,10 @@ var data = {
* @param {String} query SQL (style) order by
* @param {String} create [Optional, default behavior is true, value is false] Boolean determines whether to recreate a view if it exists
* @param {String} sensitivity [Optional] Sort sensitivity, defaults to "ci" (insensitive = "ci", sensitive = "cs", mixed = "ms")
* @return {Array} View of data
* @param {Object} where Object describing the WHERE clause
* @return {Array} View of data
*/
sort : function (query, create, sensitivity) {
sort : function (query, create, sensitivity, where) {
if (query === undefined || String(query).isEmpty()) throw Error(label.error.invalidArguments);
if (!regex.sensitivity_types.test(sensitivity)) sensitivity = "ci";

Expand Down Expand Up @@ -1192,7 +1217,7 @@ var data = {
return sorted;
};

result = crawl(queries, this.records);
result = crawl(queries, where === undefined ? this.records : this.select(where));
this.views[view] = result;
return result;
},
Expand Down
4 changes: 3 additions & 1 deletion src/datalist.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ var datalist = {
};

// Consuming records based on sort
consumed = this.order.isEmpty() ? this.store.get() : this.store.sort(this.order, false, this.sensitivity);
if (this.where === null) consumed = this.order.isEmpty() ? this.store.get() : this.store.sort(this.order, false, this.sensitivity);
else consumed = this.order.isEmpty() ? this.store.select(this.where) : this.store.sort(this.order, false, this.sensitivity, this.where);

// Processing (filtering) records & generating templates
array.each(consumed, function (i) {
Expand Down Expand Up @@ -432,6 +433,7 @@ function DataList (element, store, template) {
this.total = 0;
this.sensitivity = "ci";
this.store = store;
this.where = null;
};

// Setting prototype & constructor loop
Expand Down

0 comments on commit f1803b5

Please sign in to comment.