Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
apb2006 committed Mar 7, 2015
1 parent 87f9bf8 commit d21b15d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
66 changes: 57 additions & 9 deletions docs/commands.md
Expand Up @@ -20,8 +20,10 @@ The utility function `print` in the debug module shows the syntax:
};

# Create a Client Session
````
var basex=require("basex");
var session=basex.Session(host, port, username, password)
````
The default values are:
hostname (default="localhost")
port (default=1984)
Expand All @@ -31,36 +33,73 @@ The default values are:
# Session commands

##execute
````
session.execute(command,callback)
````
Executes a command on the server calls `callback` with the result.

Example
````
client.execute("create db test_db", log.print);
````
##query
````
var query=session.query(query)
````
Returns a query object for the specified query, see below for more detail.

Example
````
var input = 'for $i in 1 to 100 return <xml>Text { $i }</xml>';
var query = session.query(input);
````
##create
````
session.create(name,in,callback)
````
Creates a database from an input stream.
````
// create new database
client.create("test_db", "<x>Hello World!</x>", log.print);
````

##add
````
session.add(name,target,in,callback)
Adds a document to the current database from an input stream.

````
Adds a document to the current database from an input stream or a string.
Example
````
// add document from stream
var s=fs.createReadStream(__dirname+ "/books.xml");
client.add("/world/World.xml", s, log.print);
````
##replace
````
session.replace(path,in,callback)
````
Replaces a document with the specified input stream.

##store
````
session.store(path,in,callback)
````
Stores raw data at the specified path.

##watch
````
session.watch(name,notification,callback)
````
Request notifications for event with `name`. The function `notification` is called
each time an event with the name is received. The signature is `notification(name,data)`.

````
function watchCallback(name,msg){
console.log("watch update-----> ",msg)
};
session1.watch("testevent",watchCallback, log.print);
````
##unwatch
````
session.unwatch(name,callback)
````
Unwatches the specified event.

##info
Expand All @@ -72,19 +111,28 @@ Returns process information.
Closes the session.

# The query object

Create a query object `session.query(query)`, then `bind` any external variables, finally
##bind
````
query.bind(name,value,type,callback);
````
Binds a `name` to a `value`. Currently `type` is ignored.

````
query.bind("name", "nodex","",log.print);
````
##close
query.close();
##results
query.results(callback);
Returns results as an array.

##execute
````
query.results(log.print);
````
##execute
````
query.execute(callback);
````
Executes the query and returns all results as a single string.

##info
query.info(callback);
Expand Down
3 changes: 2 additions & 1 deletion examples/Example.js
Expand Up @@ -3,7 +3,7 @@
* This example shows how database commands can be executed.
*/
var basex = require("../index");
var client = new basex.Session("127.0.0.1", 1984, "admin", "admin");
var client = new basex.Session("localhost", 1984, "admin", "admin");
basex.debug_mode = false;
/**
* Description
Expand All @@ -18,6 +18,7 @@ function print(err, reply) {
} else {
var t2=new Date();
console.log("Execution completed in ",t2-t0," milliseconds.");
console.dir(reply);
}
};
var t0=new Date();
Expand Down
16 changes: 16 additions & 0 deletions examples/issue17.js
@@ -0,0 +1,16 @@
/*
* This example shows how new databases can be created.
*
*/
var basex = require("../index");
var log = require("../debug");

// create session
var session = new basex.Session("localhost", 1984, "admin", "admin");
//create new database
//session.create("test_db", "<x>Hello World!</x>", log.print);
basex.debug_mode = false;
var query=session.query('/Meeting/Races/Race/RaceEntries/RaceEntry/Form/ResultsSummaries/ResultsSummary/@Wins>=1')
query.results(log.print);
console.log(session);
session.close()
2 changes: 1 addition & 1 deletion lib/query.js
Expand Up @@ -70,7 +70,7 @@ function Query(session, query) {
* requests query results
* @method results
* @param {} callback
* @return
* @return null until result avialable, then {ok:..,result:,info:}
*/
this.results = function(callback) {
self.session.send_command({
Expand Down

0 comments on commit d21b15d

Please sign in to comment.