Skip to content

Commit

Permalink
events (but notworking)
Browse files Browse the repository at this point in the history
  • Loading branch information
apb2006 committed Jun 2, 2012
1 parent 2ae4bf1 commit 403bbf9
Show file tree
Hide file tree
Showing 23 changed files with 455 additions and 757 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.5.0 - 2012-06-04

- Support for BaseX events
- Rewrite of parser

## v0.4.1 - 2011-11-09

- err set in callbacks
Expand Down
19 changes: 19 additions & 0 deletions debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* example functions for use as test callbacks
* andy bunce 2011-2012
*/
function print(err, reply) {
if (err) {
console.log("Error: " + err);
} else {
console.dir(reply);
}
};
// show supplied msg then basex server response
function printMsg(msg) {
return function(err, reply){
console.log("printMsg: ",msg);
if(arguments.length==2) print(err, reply)
}
};
exports.print = print;
exports.printMsg = printMsg;
19 changes: 11 additions & 8 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The second `reply` will hold the reply. The reply is often an object with
{ result: '1 2 3 4 5 6 7 8 9 10',
info: '\nQuery executed in 0.38 ms.\n' }

The utility function `print` shows the syntax:
The utility function `print` in the debug module shows the syntax:

function print(err, reply) {
if (err) {
Expand All @@ -21,16 +21,17 @@ The utility function `print` shows the syntax:
## Create a Client Session
var basex=require("basex");
var session=basex.Session(host, port, username, password)
hostname (default="localhost")
port (default=1984)
username (default="admin")
password (default= "admin")
The default values are:
hostname (default="localhost")
port (default=1984)
username (default="admin")
password (default= "admin")

## Session commands
//Executes a command and returns the result:
session.execute(command,callback)

//Returns a query object for the specified query:
//Returns a query object for the specified query, see below for more detail:
var query=session.query(query)

//Creates a database from an input stream:
Expand All @@ -46,7 +47,7 @@ password (default= "admin")
session.store( path, in,callback)

//Watches the specified event:
session.watch( name, callback)
session.watch( name, notification,callback)

//Unwatches the specified event:
session.unwatch( name,callback)
Expand All @@ -55,7 +56,7 @@ password (default= "admin")
session.info(callback)

//Closes the session:
session.close()
session.close(callback)


## The query object
Expand All @@ -64,6 +65,8 @@ password (default= "admin")

query.close();

query.results(callback);

query.execute(callback);

query.info(callback);
Expand Down
13 changes: 7 additions & 6 deletions examples/AddExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
*
*/
var basex = require("../index");
var log = require("../debug");
// create session
var client = new basex.Session("localhost", 1984, "admin", "admin");
basex.debug_mode = true;
basex.debug_mode = false;
// create new database
client.execute("create db database", basex.print);
client.execute("create db database", log.print);

// add document
client.add("/world/World.xml", "<x>Hello World!</x>", basex.print);
client.add("/world/World.xml", "<x>Hello World!</x>", log.print);

// add document
client.add("Universe.xml", "<x>Hello Universe!</x>", basex.print);
client.add("Universe.xml", "<x>Hello Universe!</x>", log.print);

// run query on database
client.execute("xquery /", basex.print);
client.execute("xquery /", log.print);

// drop database
client.execute("drop db database", basex.print);
client.execute("drop db database", log.print);

// close session
client.close();
9 changes: 5 additions & 4 deletions examples/BadExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
*
*/
var basex = require("../index");
var log = require("../debug");
// create session
var client = new basex.Session("localhost", 1984, "admin", "admin");
basex.debug_mode = true;
// create new database
client.execute("create db database", basex.print);
client.execute("create db database", log.print);

//run query on database
client.execute("xquery 2+2", basex.print);
client.execute("xquery 2+2", log.print);
// run query on database
client.execute("xquery 2+", basex.print);
client.execute("xquery 2+", log.print);

// drop database
client.execute("drop db database", basex.print);
client.execute("drop db database", log.print);

// close session
client.close();
7 changes: 4 additions & 3 deletions examples/CreateExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
*
*/
var basex = require("../index");
var log = require("../debug");
//basex.debug_mode = true;
// create session
var client = new basex.Session("localhost", 1984, "admin", "admin");

// create new database
client.create("database", "<x>Hello World!</x>", basex.print);
client.create("database", "<x>Hello World!</x>", log.print);

// run query on database
client.execute("xquery /", basex.print);
client.execute("xquery /", log.print);

// drop database
client.execute("drop db database", basex.print);
client.execute("drop db database", log.print);

// close session
client.close();
38 changes: 38 additions & 0 deletions examples/EventExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This example shows how to use the event feature.
*
*/
var basex = require("../index");
var d = require("../debug");

// create sessions
var session1 = new basex.Session("localhost", 1984, "admin", "admin");
var session2 = new basex.Session("localhost", 1984, "admin", "admin");
basex.debug_mode = false;

function watchCallback(name,msg){
console.log("watch update-----> ",msg)
session2.unwatch("messenger",function(){
session1.execute("drop event messenger",d.printMsg("S1:drop event"));
// close session
session1.close(d.printMsg("S1:close"));
session2.close(d.printMsg("S2:close"));
});

};

function afterEvent(err, reply){
if (err) {
console.log("Error: " + err);
//return;
}
console.dir(reply);
session2.watch("messenger",watchCallback,d.printMsg("S2:watching messenger"));
var xq="for $i in 1 to 1000000 where $i=3 return $i"
session2.query(xq).execute(d.printMsg("S2:execute"));
session1.query("db:event('messenger', 'Hello World!')").execute(d.printMsg("S1:event"));

};

session1.execute("create event messenger",afterEvent);

9 changes: 6 additions & 3 deletions examples/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ function print(err, reply) {
console.log("Error: " + err);
} else {
var t2=new Date();
console.log("Commands completed in ",t2-t0," milliseconds.");
console.log("Execution completed in ",t2-t0," milliseconds.");
}
};
var t0=new Date();
client.execute("xquery 1 to 10",basex.print);
client.close(print);
client.execute("xquery 1 to 10",print);
client.close(function(){
var t2=new Date();
console.log("Closed in ",t2-t0," milliseconds.");
});
var t1=new Date();
// not a true time because basex commands not yet done.
console.log("Commands send in ",t1-t0," milliseconds.");
11 changes: 6 additions & 5 deletions examples/QueryBindExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

var basex = require("../index");
var log = require("../debug");
//basex.debug_mode = true;
var session = new basex.Session("localhost", 1984, "admin", "admin");

Expand All @@ -12,14 +13,14 @@ var input = "declare variable $name external; for $i in 1 to 10 return element {
var query = session.query(input);

// bind variable
query.bind("name", "nodex","",basex.print);
query.bind("name", "nodex","",log.print);

// print results
query.execute(basex.print);
query.execute(log.print);
// do it again
query.bind("name", "again","",basex.print);
query.execute(basex.print);
query.info(basex.print);
query.bind("name", "again","",log.print);
query.execute(log.print);
query.info(log.print);

// close query instance
query.close();
Expand Down
5 changes: 3 additions & 2 deletions examples/QueryExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
*
*/
var basex = require("../index");
basex.debug_mode = true;
var log = require("../debug");
basex.debug_mode = false;
// create session
var session = new basex.Session("localhost", 1984, "admin", "admin");

// create query instance
var input = 'for $i in 1 to 10 return <xml>Text { $i }</xml>';
var query = session.query(input);

query.iter(basex.print);
query.results(log.print);
//query.info(basex.print);
//query.options(basex.print);
// loop through all results
Expand Down
58 changes: 0 additions & 58 deletions examples/buffer_bench.js

This file was deleted.

22 changes: 22 additions & 0 deletions examples/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
info it worked if it ends with ok
verbose cli [ 'node', '/usr/bin/npm', 'test' ]
info using npm@1.0.105
info using node@v0.6.10
verbose /usr/bin/node node symlink
verbose config file /home/andy/.npmrc
verbose config file /usr/etc/npmrc
verbose config file /usr/lib/node_modules/npm/npmrc
ERR! Error: ENOENT, no such file or directory '/home/andy/workspace/basex-node/examples/package.json'
ERR! Report this *entire* log at:
ERR! <http://github.com/isaacs/npm/issues>
ERR! or email it to:
ERR! <npm-@googlegroups.com>
ERR!
ERR! System Linux 3.0.0-19-generic
ERR! command "node" "/usr/bin/npm" "test"
ERR! cwd /home/andy/workspace/basex-node/examples
ERR! node -v v0.6.10
ERR! npm -v 1.0.105
ERR! path /home/andy/workspace/basex-node/examples/package.json
ERR! code ENOENT
verbose exit [ 1, true ]
11 changes: 6 additions & 5 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// standalone basex test
var basex =require("../index");
var log = require("../debug");
basex.debug_mode = true;

var s=new basex.Session();
s.execute("info",basex.print);
s.execute("list",basex.print);
s.execute("OPEN factbook",basex.print);
s.execute("XQUERY 1 to 5",basex.print);
s.execute("XQUERY count(//*)",basex.print);
s.execute("info",log.print);
s.execute("list",log.print);
s.execute("OPEN factbook",log.print);
s.execute("XQUERY 1 to 5",log.print);
s.execute("XQUERY count(//*)",log.print);
s.close();


Expand Down
Loading

0 comments on commit 403bbf9

Please sign in to comment.