GithubHelp home page GithubHelp logo

quodatum / basex-node Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 4.0 342 KB

A node.js client for the BaseX server.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%
basex basex-client nodejs xquery

basex-node's People

Contributors

apb2006 avatar bitdeli-chef avatar jesseclark avatar mortonfox avatar salim-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

basex-node's Issues

Assert failure: no null

Some of my execute calls fail at the "no null" assertion at line 128 in index.js. I tried changing the code to take the entire buffer if there is no null but then I get a different bug where it can't find the callback - I'll see what's going on there. Here's what I tried:

    var p = self.buffer.indexOf(CHR0);
    if (p == -1)
        p = self.buffer.length -1;

I was wondering if you had any idea what might be going on "under the hood". Seems the xquery calls work fine in the BaseX client (although there are quite a few and I'll need to test them all).

has no method on

have written a very basic query but when running I ge this error

sayth@:~/Projects$ node test2.js

/home/sayth/Projects/node_modules/basex/index.js:220
this.on("drain", function() {
^
TypeError: Object # has no method 'on'
at Object.Session (/home/sayth/Projects/node_modules/basex/index.js:220:10)
at Object. (/home/sayth/Projects/test2.js:2:19)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
sayth@:~/Projects$

var basex=require("basex");
var session=basex.Session('localhost', 1984,'admin','admin')

var query=session.query('/Meeting/Races/Race/RaceEntries/RaceEntry/Form/ResultsSummaries/ResultsSummary/@Wins>=1')
console.log(session);

Watcher

Hello Andy,

first, thank you for the great basex-node. It works great. And the examples and test are a good starting point.
Secound, I tried to extend the index with a watcher. Eventually, you have implemented the watcher already and you could share it or you could explain how to implement it.

Regards,
Alex

basex-node does not handle server disconnection gracefully

Hi,

when leaving my node process connected to BaseX running over night, it crashed when it lost connection to the database server. It seems that there is currently no way to prevent this, as node-basex does not handle the possible closing of the socket by the database server, and tries to interact with a closed socket, which results in an uncaught exception.

It would be useful if an event would be generated when a Session lost its connection (by making it an EventEmitter and forwarding the 'end' event). Furthermore, session.close() should detect when the socket is already closed and not try to read or write from it in that case.

This would allow application code to set up an event handler that logged the event and performed an automatic reconnection, if desired.

I can come up with a patch if you don't have the time to look into implementing this yourself. Please let me know.

Thanks!
Hans

this.on is not a function

Get this stacktrace when I run the server with the basex.Session(host, port, user, pass) line.

C:\Users\Brendan\workspace\node\letterdb\node_modules\basex\index.js:220
    this.on("drain", function() {
         ^

TypeError: this.on is not a function
    at Object.Session (C:\Users\Brendan\workspace\node\letterdb\node_modules\basex\index.js:220:10)
    at Object.<anonymous> (C:\Users\Brendan\workspace\node\letterdb\app\server.js:31:22)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:141:18)
    at node.js:933:3

Node: 5.7.1 (latest)
npm: 3.6.0

Httpserver terminates unexpectedly

Hi,

I want to use TableExample.js to create my own queries to a BaseX server running on my localhost. I can start the BaseX server and run nodejs TableExample.js, but when I try to navigate to localhost:9000 in the web browser I get a server not found error and on the command line the following happens:

Server running at port:9000

http.js:853
throw new TypeError('first argument must be a string or Buffer');
^
TypeError: first argument must be a string or Buffer
at ServerResponse.OutgoingMessage.write (http.js:853:11)
at Object.callback (/home/werner/Desktop/Nodebin/BaseX/node_modules/basex/examples/TableExample.js:33:7)
at onData (/home/werner/Desktop/Nodebin/BaseX/node_modules/basex/index.js:150:20)
at Socket. (/home/werner/Desktop/Nodebin/BaseX/node_modules/basex/index.js:97:18)
at Socket.EventEmitter.emit (events.js:95:17)
at flow (_stream_readable.js:596:9)
at Socket.pipeOnReadable (stream_readable.js:624:5)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable
(_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
werner@werner-Inspiron-3543:~/Desktop/Nodebin/BaseX/node_modules/basex/examples$

basex-node does not cope with raw data

node.js breaks in:

\node_modules\basex\lib\parser.js:35
+ ":" + buf;
^
expected status marker at2=65533:

When the query is:

session.query("declare option output:method 'raw'; db:retrieve('assets', '"+asset+"')");

basex.Session

Hello,
In
var session=basex.Session(host, port, username, password)
is basex.Session a synchronous function? Can it be assumed that the session was created successfully if no socketError event is emitted?
Thanks.

Hang querying empty result

package.json: "basex": "~0.6.1"

I create a database, insert a document, and then query for something that is not there.

I am using BaseX 7.6 if that makes any difference.

Maybe you can see it. Here's the debug of what goes back and forth during the whole session:

S1<<
'1374588092554420000\u0000'
S1>>
'admin\u0000'
S1>>
'713de454606e785a0666bd57e6554891\u0000'
S1<<
'\u0000'
S1: authorized
S1>>
'create db gumby\u0000'
S1<<
'\u0000Database 'gumby' created in 5.01 ms.\n\u0000\u0000'
response: { result: '',
info: 'Database 'gumby' created in 5.01 ms.\n',
ok: true }
.S1>>
'\t/people.xml\u0000Gumby\nmanelsePokey\nhorse\u0000'
S1<<
'Path "people.xml" added in 1.88 ms.\n\u0000\u0000'
response: { ok: true, result: 'Path "people.xml" added in 1.88 ms.\n' }
.S1>>
'\u0000//somethingNotThere\u0000'
S1<<
'0\u0000\u0000'
response: { ok: true, result: '0' }
S1>>
'\u00040\u0000'
S1<<
'\u0000\u0000'

And then it hangs, since the callback isn't called.

If, instead, I do a query that does give results back I get the first value prefixed with \000b, which I believe is intended to indicate that the result is an "element".

S1<<
'\u000bGumby\nman\u0000\u000bPokey\nhorse\u0000\u0000\u0000'
response: { ok: true,
result:
[ '\u000bGumby\nman',
'Pokey\nhorse' ] }
{"ok":true,"result":["\u000bGumby\nman","Pokey\nhorse"]}

What is required to be able to handle streams in _dbop()?

Hello,

First off thanks for creating these node bindings for BaseX. I think it is going to be a big help on my current project.

I'm building a web api that receives xml files in a post request and adds them to my BaseX db. Currently I am writing the received file to disk then opening it and passing it as string data to the Session.add() method.

It would be nice if I could stream the data directly to add() without having to hit the disk. I have access to the incoming readStream but it looks like stream support has not been added in _dbop().

Did you have a solution for this in mind? If you could give me an overview perhaps I could help implement it.

It looks like the action hinges around line 320 of index.js in sendQueueItem():

self.send(cmd.send);

and in this.send() line 144:

if (typeof s === "function")
            s = s();

so it seems like we would need to modify _dbop() to check if the input is a string or a stream and if it is a stream, instead of passing the command as a string like so (line 219 this._dbop()):

send : op + path + "\0" + input+"\0",

add a reference to the stream and other command components to the command object and make send a reference to a function that will read the stream:

send : this.readStream,
op: op,
path: path,
input: input 

and then this.readStream() could read the input stream and then return the assembled command in the format:

return op + path + "\0" + streamData + "\0";

I'm still a relative beginner with node so I might be a bit off on my proposed solution and would appreciate any feedback or let me know what you were thinking for a solution.

Best,
-Jesse

Use of Buffer(): DeprecationWarning

(node:32036) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

commands.md

Please could commands.md be updated to explain what each of the command parameters mean?

packaging

Unnecessary content included in published module:

  • docs
  • examples
  • test

Authorization failure not properly detected

Hi,

I'm using basex-node with BaseX 7.6 and it appears that authorization rejections are not properly detected. As far as I have determined, the server replies with '\u0001' if the login was incorrect, but the state machine in the Session constructor does not properly interpret that response and carries on as if authorization was successful. I do not quite understand the popByte function as it is, maybe it is something that you can fix easily?

Thanks (and thanks for basex-node anyway!)!
Hans

Socket errors handling

Hello. When I open BaseX session and then restart the server while the session keeps idle, I've got such error if I try to perform a query:

SOCKET ERROR:  { Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:291:12)
    at Session.write (/usr/lib/node_modules/basex/index.js:216:25)
    at Session.sendQueueItem (/usr/lib/node_modules/basex/index.js:395:14)
    at Session.send_command (/usr/lib/node_modules/basex/index.js:369:14)
    at new Query (/usr/lib/node_modules/basex/lib/query.js:243:10)
    at Session.query (/usr/lib/node_modules/basex/index.js:280:16)
    at rpn.then (/root/testscript.js:78:20)
    at propagateAslWrapper (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:421:23)
    at /usr/lib/node_modules/pm2/node_modules/async-listener/index.js:458:70
    at process._tickDomainCallback [as _tickCallback] (internal/process/next_tick.js:129:7) code: 'EPIPE' }

Is it possible to catch such errors in the user code? If not, I guess it's need to implement some error handling features for Session and/or Query constructors.

As I can see at this time there is only console output performed:

function socketError(e) {
    if (e.code == 'ECONNREFUSED') {
        console.log('ECONNREFUSED: connection refused. Check BaseX server is running.');
    } else {
        console.log("SOCKET ERROR: ", e);
    }
}

Next query executed after failed query returns invalid output

Hello. I have following script to perform a test:

const basex = require('basex')
var session = new basex.Session()

function performQuery(q_str) {
    return new Promise(rs => {
        var q = session.query(q_str)
        q.execute((e, r) => {
            console.log("Result: ", r.result, "; Error:", e)
            rs()
        })
    })
}

var invalid_query = '(map {"key": "value"})("missing")("key")'
var correct_query = '(map {"key": "value"})("key")'

If I try to perform two correct queries in turn:

performQuery(correct_query).then(
    performQuery(correct_query)
)

all seem to be work as expected:

Result:  value ; Error: null
Result:  value ; Error: null

But if I put invalid query at first:

performQuery(invalid_query).then(
    performQuery(correct_query)
)

result of the next query also incorrect:

Result:  undefined ; Error:
Result:   ; Error: null

Is it a bug in your library or I simply doing something wrong? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.