1.0.8 • Published 5 years ago

jsqldb-debug-client v1.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

jsqldb-debug-client

Synchronous client for jsqldb https://jsqldb.org, for the purpose of debugging. It allows a js debugger, e.g. Visual Studio Code, to step through queries. Performance is lower than the asynchronous client (https://github.com/jsqldb/jsqldb-node-client), because there is much more network traffic to allow the client side debugging to take place, whereas the async client does only one request per query (but queries run on server so can't be stepped through)

Available on npm

npm install jsqldb-debug-client

Usage sample

const jsqldb = require('jsqldb-debug-client')

var client = new jsqldb.Client("127.0.0.1", 7591);
let con = client.connect();

con.dbadmin.createdb("db");

con.db.a = {A:"aaa"}
con.db.b = {B:"bbb"}

console.log(con.db.a.A);

console.log(JSON.stringify(con.db.a));

con.db.dbeach(function(k,o) {
    console.log(k); //<--You can set a break point here for example
});

con.db.testf = function(t) {
    console.log("in testf "+t); //Or here :)
    return t;
}

console.log("con.db.testf('a')="+con.db.testf('a'));

Objects are retured as object JSQLDBSessionQuery, in order that query functions may be chained and lazy loaded. In most cases this just works transpararently, for example

console.log(con.db.a); // logs [object JSQLDBSessionQuery] (normal javascript object would log [object Object]
console.log(JSON.stringify(con.db.a)); //logs { "A":"aaa" } 
console.log(con.db.a.A) //logs 'aaa', because in this case it's a primitive;

console.log(JSON.stringify(con.db.limit(1))); //logs {a : { "A":"aaa" }} 
//The above illustrates why JSQLDBSessionQuery is necessary, it has
//to support query functions, and lasy load only for example one entry from potentially large collections, withour bringing back the
//whole collection

In some cases it may be necessary to render out a JSQLDBSessionQuery to a normal object/array. For that purpose the driver provider the .r() function.

con.db.a.r();

//This creates db.c as a reference to the same object, db.a. Modifiying db.c will modify db.a and vice versa
con.db.c = con.db.a 

//This creates db.d as a new independant copy of db.a, this is equivalent to con.db.d = {A:"aaa"}
con.db.d = con.db.a.r() 

Due to a limitation in v8 wrapping of arrays, in this driver, arrays might be rendered as objects. The .r() function can be used to render them correctly.

con.db.ar = ['a', 'b']
console.log(JSON.stringify(con.db.ar)); //logs { "0" : "a", "1", "b" } 
console.log(JSON.stringify(con.db.ar.r())); //logs ["a", "b" ]
//or equivalent
console.log(JSON.stringify(con.db.r('.ar'))); //logs ["a", "b" ]
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago