Permalink
Browse files

Made RowKey optional, minor bugfixes

  • Loading branch information...
1 parent f198e98 commit 469df1a42ebe0599a3071a4d0ca730b5e20572ba @pofallon committed Apr 29, 2012
Showing with 62 additions and 13 deletions.
  1. +1 −1 lib/bluesky.js
  2. +45 −9 lib/table.js
  3. +1 −1 package.json
  4. +15 −2 test/storage-table.js
View
@@ -4,6 +4,6 @@
* MIT Licensed
*/
-exports.version = '0.5.0alpha';
+exports.version = '0.5.1';
exports.storage = require('./storage');
View
@@ -9,6 +9,7 @@ var TableQuery = require("azure/lib/services/table/tablequery");
var ISO8061Date = require("azure/lib/util/iso8061date");
var EventEmitter = require('events').EventEmitter;
var skyutil = require('./util');
+var uuid = require('node-uuid');
function Table (t,options) {
this.options = options;
@@ -144,6 +145,12 @@ Table.prototype.insert = function(partition,row,elem,callback) {
var entity = {};
+ if ((typeof row === "object") || (typeof row === "function")) {
+ callback = elem;
+ elem = row;
+ row = null;
+ }
+
switch (typeof elem) {
case "function":
callback = elem;
@@ -157,30 +164,30 @@ Table.prototype.insert = function(partition,row,elem,callback) {
callback = skyutil.safeCallback(callback);
entity.PartitionKey = partition;
- entity.RowKey = row;
+ entity.RowKey = row || getRowKey(this.options.rowKey,elem);
this.options.tableService.insertEntity(this.name, formatEntity(entity), function(err) {
if (err) {
callback(err);
} else {
- callback(null,true);
+ callback(null,entity.RowKey);
}
});
};
Table.prototype.select = function() {
- this._query = TableQuery.select.apply(this._query, arguments).from(this.name);
+ this._query = TableQuery.select.apply(this._query, Array.prototype.slice.call(arguments)).from(this.name);
return this;
}
Table.prototype.whereKeys = function() {
- this._query.whereKeys.apply(this._query, arguments);
+ this._query.whereKeys.apply(this._query, Array.prototype.slice.call(arguments));
return this;
}
Table.prototype.where = function() {
- this._query.where.apply(this._query, arguments);
+ this._query.where.apply(this._query, Array.prototype.slice.call(arguments));
return this;
}
@@ -207,17 +214,17 @@ Table.prototype.filter = function(criteria) {
}
Table.prototype.and = function() {
- this._query.and.apply(this._query, arguments);
+ this._query.and.apply(this._query, Array.prototype.slice.call(arguments));
return this;
}
Table.prototype.or = function() {
- this._query.or.apply(this._query, arguments);
+ this._query.or.apply(this._query, Array.prototype.slice.call(arguments));
return this;
}
-Table.prototype.top = function() {
- this._query.top.apply(this._query, arguments);
+Table.prototype.top = function(count) {
+ this._query.top.apply(this._query, Array.prototype.slice.call(arguments));
return this;
}
@@ -301,4 +308,33 @@ function formatEntity(entity) {
}
+function getRowKey(keyPref,elem) {
+
+ var rowKey = null;
+
+ switch(typeof keyPref) {
+ case 'function':
+ rowKey = keyPref(elem);
+ break;
+ case 'string':
+ switch(rowType) {
+ case 'timestamp':
+ rowKey = (new Date()).toISOString();
+ break;
+ case 'epoch':
+ rowKey = Date.now();
+ break;
+ case 'uuid':
+ rowKey = uuid.v4();
+ default:
+ rowKey = uuid.v4();
+ }
+ default:
+ rowKey = uuid.v4();
+ }
+
+ return(rowKey);
+
+}
+
module.exports = Table;
View
@@ -23,7 +23,7 @@
"loremipstream" : "0.0.x"
},
"engine": "node >= 0.6.0",
- "version": "0.5.0",
+ "version": "0.5.1",
"files": [
"index.js",
"lib",
View
@@ -226,15 +226,28 @@ module.exports = testCase({
});
},
- /* tableTopRows: function(test) {
+ tableTopRows: function(test) {
var t = storage.table(this.tableName);
t.top(2).rows(function(err,rows) {
test.equals(err,null);
test.notEqual(rows,null);
test.strictEqual(rows.length,2);
test.done();
});
- }, */
+ },
+
+ tableInsertNoRowKey: function (test) {
+ var that = this;
+ var t = storage.table(this.tableName);
+ t.insert(this.partitionKey,{'test':'uuidtest'}, function(err, rowKey) {
+ test.equals(err,null);
+ test.notEqual(rowKey,null);
+ t.whereKeys(that.partitionKey,rowKey).rows(function(err, rows) {
+ test.equals(rows.length,1);
+ test.done();
+ });
+ });
+ },
tableDeleteRow: function (test) {
var t = storage.table(this.tableName);

0 comments on commit 469df1a

Please sign in to comment.