Giter VIP home page Giter VIP logo

nquery's Introduction

nQuery

Generic SQL engine for Web and Big-data.

Install

NodeJS Version 0.8.0+

npm install node-query

Introduction

it could be used in some typical scenarios:

  • As a SQL frontend, do syntax checking and formating.
  • As a SQL engine for your KV databases like HBase or anything like that.
  • Providing a SQL interface for your HTTP/WEB service.
  • Do data merging and intergration among many different data sources like Oracle, MySQL, HBase etc.

Demo & Test

to run the demo, type the command:

node demo/demo.js

for the test , type the command:

make

read the demo carefully and then you could write own loader/adapter, there are also many test cases in test/unit, they would be great helpful to you.

Usage

please read the demo files demo/demo.js

for a KV storage engine ,what you need to do is providing the query interfaces like:

  • singleQuery,
  • rangeQuery,
  • likeQuery

for a SQL storage engine, you should realize a function like :

function query(str, function(err, data) {
  ...  
})

then you could execute SQL like that : (code snippet from demo.js)

var sqls = [
  "SELECT * FROM kv.user WHERE id IN ('01', '03')",
  "SELECT * FROM kv.user WHERE id LIKE '1%'",
  "SELECT type, MAX(age), COUNT(id) FROM kv.user WHERE id BETWEEN '03' AND '10' GROUP BY type ORDER BY MAX(age) DESC",
  "SELECT * from mysql.shop where shop_id > 5"
]

var concurrentJoinSQL = [
  "$a := select * from kv.user where id BETWEEN '03' and '10'",
  "$b := select * from mysql.shop where shop_id > 5",
  "$c := select a.type , a.id ,b.name, b.title from $a INNER JOIN $b ON a.type = b.type WHERE a.id > '04'",
  "return $c"
]

var sequentialJoinSQL = [
  "$a := select * from kv.user where id BETWEEN '03' and '10'",
  //you could also use `unique` do filter firstly
  //"$type := UNIQUE($a.type)",
  //"$b := select * from mysql.shop where type = $type",
  "$b := select * from mysql.shop where type in $a.type",
  "$c := select a.type , a.id ,b.name, b.title from $a INNER JOIN $b ON a.type = b.type WHERE a.id > '04'",
  "return [$b, $c]"
]

As you see ,besides as a SQL computation level built on top of KV storage engine, it could do join operation among kv data source, sql sources, HTTP services now

nSQL Definition

The 'a little strange' sql as you see above, nSQL realize a subset of SQL92, and it also has some procedure features, it supports variables, it addes types of var / array / table, and also keyword return, for the details, please see the specification of peg/nquery.pgejs.

Task Scheduling

As you could see in concurrentJoinSQL ,we know that the tasks $a, $b have no relations, so nQuery would do them concurrently, but for the procedure of sequentialJoinSQL, $b is depending on $a,so task $b would be executed after the time $a completed

KeyWord return

In traditional SQL, the query result is a 2-D table , but In nSQL ,we add types of array / table,so now you could return complicated results like

return [$b, $c, 'hello', [1, 2]]

Just Enjoy It!

Acknowledgements

nquery's People

Contributors

bryant1410 avatar jifeng avatar robertleeplummerjr avatar timwis avatar windyrobin 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  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  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  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  avatar

nquery's Issues

Support for subqueries

I was unable to parse the following query

const Q3 = `
select
 dashboard.name,
 logs_count.ct
from
 dashobard
  join (
   select dashoboard_id,
    count(distinct user_id) as ct
   from time_on_site_logs
   group by dashboard_id
  ) as log_counts
  on log_counts.dashboard_id = dashboard.id
order by logcounts.ct desc
`; // fails

Exception thrown:

throw new this.SyntaxError(
^
SyntaxError: Expected "$", "`", [ \t\n\r] or [A-Za-z_] but "(" found.

I'm running the latest code pull from master

Add support with escaped FROM

If there is an escaped table in the FROM statement it throws an error.

Example:

var parse = require('node-sqlparser').parse;
var stringify = require('node-sqlparser').stringify;

// ERROR
var sql = 'SELECT `id` FROM `Tb`'; // escaped `Tb`
var astObj = parse(sql); // ERROR

// OK
var sqlOK = 'SELECT `id` FROM Tb';
var astObjOK = parse(sql); // OK

Example of the error:

      throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
      ^
SyntaxError: Expected "$", WHITE_SPACE or [A-Za-z_] but "`" found.

SyntaxError as being parsed

SyntaxError: Expected "FROM", "GROUP", "LIMIT", "ORDER", "UNION", "WHERE", WHITE_SPACE, or end of input but "A" found;
e.g. mysql is:
SELECT dd, Max(IF(stat_key = 'yys', stat_us, 0)) AS 'yys_users' FROM waf.t_cpkg WHERE stat_ty = 'waf_ty' GROUP BY dd;
could you please take a look, and update to fix the bug?

Support NOT BETWEEN

node-sqlparser supports BETWEEN but doesn't support NOT BETWEEN

SELECT * WHERE salary not between '40000' and '150000'

yields Expected "CONTAINS", "IN", "LIKE" or WHITE_SPACE but "b" found.

If this isn't expected in standard SQL, feel free to disregard, but I assume it is

Cannot run demo

The demo sql cannot be parsed at my test:
webfan.de/cdn/application/test/nquery.html

"id" in the query throws an error:

module.exports.result.SyntaxError
column
:
29
expected
:
Array[10]
0
:
"",""
1
:
""GROUP""
2
:
""INNER""
3
:
""JOIN""
4
:
""LEFT""
5
:
""LIMIT""
6
:
""ORDER""
7
:
""UNION""
8
:
""WHERE""
9
:
"[ \t\n\r]"
length
:
10
proto
:
Array[0]
found
:
"i"
line
:
1
message
:
"Expected ",", "GROUP", "INNER", "JOIN", "LEFT", "LIMIT", "ORDER", "UNION", "WHERE" or [ \t\n\r] but "i" found."
name
:
"SyntaxError"
offset
:
28

Support for sub-queries?

This fails to parse: select i from (select MAX(i) AS i FROM foo:

module.exports.result.SyntaxError {name: "SyntaxError", expected: Array(3), found: "(", message: "Expected "$", [ \t\n\r] or [A-Za-z_] but "(" found.", offset: 14, …}

Breaking changes from 0.3.3->0.3.4

This package works as expected when you install it through npm(v0.3.3) but when I cloned the repo and tried to run demo.js I get the following error when it tries to evaluate $c := ...

Error: no registered db info found...
    at load (/Users/root/nquery/demo/loader.js:44:8)

The problem seems to be with the AST creation. In the newer version the AST doesn't show the tables a and b used for evaluation as 'var' type. Rolling back to the commit 395487a fixed the issue.

doesn't support upsert-ish behaviour

the following query fails in test, but passes in mysql.

INSERT INTO `user_lauer_testing`
SET `user_id` = '123',
  `username` = 'mike'
ON duplicate KEY
UPDATE `user_id` = '123',
       `username` = 'bob'

Trying to run a basic query and its not working

SELECT MONTH(endTime) FROM table

results in:

/Users/maltepeter/Documents/repos/node-query-api/node_modules/node-sql-parser/pegjs-parser.js:9800
      throw peg$buildException(
      ^
SyntaxError: Expected [A-Za-z0-9_] but end of input found.

Is there a way to get it to support this functionality?

Parser Error

content;
我是一包香烟\u0014\\0\

and parse result below:

message: 'Expected "\'", "\\\\\'", "\\\\/", "\\\\\\"", "\\\\\\\\", "\\\\b", "\\\\f", "\\\\n", "\\\\r", "\\\\t", "\\\\u" or [^\\'\\\\\\\\\\\\0-\\\\x1F�] but "%14" found.',\n offset: 261,\n line: 2,\n column: 52

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.