Comparing version 0.1.4 to 0.1.5
50
lbc.js
@@ -204,30 +204,44 @@ var net = require("net"); | ||
* - name: block name | ||
* - logic: logic | ||
* - inactive: set to true to make inactive block | ||
*/ | ||
addBlock: function(workspace, logic, options, callback) { | ||
if(_.isFunction(options)) { | ||
callback = options; | ||
options = {}; | ||
} | ||
options = options || {}; | ||
addBlock: function(workspace, params, callback) { | ||
defaultApi.request(transaction(workspace, [{ | ||
add_block: { | ||
block_name: options.name, | ||
active: !options.inactive, | ||
logic: logic | ||
block_name: params.name || null, | ||
active: !params.inactive, | ||
logic: params.logic || null | ||
} | ||
}]), callback); | ||
}]), function(err, result) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
callback(null, result.transaction.command[0].add_block.block_name); | ||
}); | ||
}, | ||
exec: function(workspace, logic, args, callback) { | ||
if (_.isFunction(args)) { | ||
callback = args; | ||
args = []; | ||
} | ||
/** | ||
* Params: | ||
* - logic: logic possibly containing placeholder ?'s | ||
* - args: logic arguments | ||
* - name: block to execute | ||
* - returnLocal: local predicates to return | ||
*/ | ||
exec: function(workspace, params, callback) { | ||
defaultApi.request(transaction(workspace, [{ | ||
exec: { | ||
"logic": fillPlaceHolders(logic, args), | ||
"return_local": [] | ||
block_name: params.name || null, | ||
logic: fillPlaceHolders(params.logic, params.args || []), | ||
return_local: params.returnLocal || [] | ||
} | ||
}]), callback); | ||
}]), function(err, result) { | ||
if(err) { | ||
return callback(err); | ||
} | ||
//var slimResult = result.transaction.command[0].exec; | ||
callback(null, result); | ||
}); | ||
}, | ||
/** | ||
* Convenience wrapper around exec | ||
*/ | ||
query: function(workspace, logic, args, callback) { | ||
@@ -234,0 +248,0 @@ if (_.isFunction(args)) { |
{ | ||
"name": "lbc", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"main": "./lbc.js", | ||
@@ -5,0 +5,0 @@ "devDepenencies": { |
@@ -25,3 +25,7 @@ var lbConnect = require('..'); | ||
console.log("Adding block"); | ||
yield conn.addBlock(wsName, "p(a, b, c, d, e, f) -> int(a), decimal(b), float(c), string(d), boolean(e), datetime(f)."); | ||
var result = yield conn.addBlock(wsName, { | ||
name: "myblock", | ||
logic: "p(a, b, c, d, e, f) -> int(a), decimal(b), float(c), string(d), boolean(e), datetime(f)." | ||
}); | ||
assert.equal(result, "myblock"); | ||
@@ -35,5 +39,12 @@ console.log("Inspecting resulting predicate"); | ||
console.log("Inserting some data and verifying it"); | ||
yield conn.exec(wsName, '+p(1, 1.5d, 1.5f, "Zef", true, datetime:now[]).'); | ||
yield conn.exec(wsName, '+p(?, ?d, ?f, ?, ?, datetime:now[]).', [2, 2.5, 2.5, "Zef2", true]); | ||
yield conn.exec(wsName, '+p(2, 2.5d, 2.5f, "Zef2", false, datetime:now[]).'); | ||
yield conn.exec(wsName, { | ||
logic: '+p(1, 1.5d, 1.5f, "Zef", true, datetime:now[]).' | ||
}); | ||
yield conn.exec(wsName, { | ||
logic: '+p(?, ?d, ?f, ?, ?, datetime:now[]).', | ||
args: [2, 2.5, 2.5, "Zef2", true] | ||
}); | ||
yield conn.exec(wsName, { | ||
logic: '+p(2, 2.5d, 2.5f, "Zef2", false, datetime:now[]).' | ||
}); | ||
@@ -75,3 +86,3 @@ function checkResults(results) { | ||
assert.equal(workspaces[0], wsName, "workspace name"); | ||
var statuses = yield conn.getStatus([wsName]); | ||
@@ -78,0 +89,0 @@ assert.equal(statuses.length, 1, "status count"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78318
832