Comparing version 1.4.10 to 1.4.12
{ | ||
"name": "xql", | ||
"version": "1.4.10", | ||
"version": "1.4.12", | ||
"license": "Unlicense", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -57,3 +57,3 @@ xql.js | ||
// Use context to compile the query. | ||
console.log(query.compileQuery(ctx)); | ||
console.log(query.compileStatement(ctx)); | ||
// SELECT * FROM "cities" WHERE "population" >= 1000000 AND "capital" = TRUE; | ||
@@ -76,3 +76,3 @@ ``` | ||
console.log(query.compileQuery(ctx)); | ||
console.log(query.compileStatement(ctx)); | ||
// SELECT | ||
@@ -125,9 +125,10 @@ // * | ||
`xql.node.Sort` | SQL `ORDER BY` construct | ||
`xql.node.Statement` | Base class representing a single SQL statement | ||
`xql.node.Query` | Base class used by `SELECT`, `INSERT`, `UPDATE`, and `DELETE` statements. | ||
`xql.node.SelectQuery` | SQL `SELECT` query | ||
`xql.node.InsertQuery` | SQL `INSERT` query | ||
`xql.node.UpdateQuery` | SQL `UPDATE` query | ||
`xql.node.DeleteQuery` | SQL `DELETE` query | ||
`xql.node.CompoundQuery` | SQL `UNION`, `INTERSECT`, and `EXCEPT` operators that can be used to combine multiple queries | ||
`xql.node.With` | Expression representing `"identifier" AS (SELECT ...)` part of WITH clause. | ||
`xql.node.Statement` | Base class representing a single SQL statement, which should end with semicolon | ||
`xql.node.QueryStatement` | Base class used by `SELECT`, `INSERT`, `UPDATE`, and `DELETE` statements | ||
`xql.node.SelectStatement` | SQL `SELECT` statement | ||
`xql.node.InsertStatement` | SQL `INSERT` statement | ||
`xql.node.UpdateStatement` | SQL `UPDATE` statement | ||
`xql.node.DeleteStatement` | SQL `DELETE` statement | ||
`xql.node.CompoundStatement`| SQL `UNION`, `INTERSECT`, and `EXCEPT` operators that can be used to combine multiple query statements | ||
@@ -171,12 +172,12 @@ High-level SQL builder concepts: | ||
`xql.OR(...)` | Create a `xql.node.Logical` expression describing `OR` expression | ||
`xql.SELECT(...)` | Create a `xql.node.SelectQuery` and pass optional arguments to the `SelectQuery.FIELD(...)` method | ||
`xql.INSERT(...)` | Create a `xql.node.InsertQuery` and use an optional first argument as a table name (`FROM` clause) if it's a string or an identifier, and pass all other arguments to `SelectQuery.FIELD(...)` method | ||
`xql.UPDATE(...)` | Create a `xql.node.UpdateQuery` and use an optional first argument as a table name (`UPDATE ...` clause) if it's a string or an identifier, and pass all other arguments to `UpdateQuery.FIELD(...)` method | ||
`xql.DELETE(...)` | Create a `xql.node.DeleteQuery` and use an optional first argument as a table name | ||
`xql.EXCEPT(...)` | Create a `xql.node.CompoundQuery` describing `EXCEPT` expression | ||
`xql.EXCEPT_ALL(...)` | Create a `xql.node.CompoundQuery` describing `EXCEPT ALL` query | ||
`xql.INTERSECT(...)` | Create a `xql.node.CompoundQuery` describing `INTERSECT` query | ||
`xql.INTERSECT_ALL(...)` | Create a `xql.node.CompoundQuery` describing `INTERSECT ALL` query | ||
`xql.UNION(...)` | Create a `xql.node.CompoundQuery` describing `UNION` query | ||
`xql.UNION_ALL(...)` | Create a `xql.node.CompoundQuery` describing `UNION ALL` query | ||
`xql.SELECT(...)` | Create a `xql.node.SelectStatement` and pass optional arguments to the `SelectStatement.FIELD(...)` method | ||
`xql.INSERT(...)` | Create a `xql.node.InsertStatement` and use an optional first argument as a table name (`FROM` clause) if it's a string or an identifier, and pass all other arguments to `SelectStatement.FIELD(...)` method | ||
`xql.UPDATE(...)` | Create a `xql.node.UpdateStatement` and use an optional first argument as a table name (`UPDATE ...` clause) if it's a string or an identifier, and pass all other arguments to `UpdateStatement.FIELD(...)` method | ||
`xql.DELETE(...)` | Create a `xql.node.DeleteStatement` and use an optional first argument as a table name | ||
`xql.EXCEPT(...)` | Create a `xql.node.CompoundStatement` describing `EXCEPT` expression | ||
`xql.EXCEPT_ALL(...)` | Create a `xql.node.CompoundStatement` describing `EXCEPT ALL` query | ||
`xql.INTERSECT(...)` | Create a `xql.node.CompoundStatement` describing `INTERSECT` query | ||
`xql.INTERSECT_ALL(...)` | Create a `xql.node.CompoundStatement` describing `INTERSECT ALL` query | ||
`xql.UNION(...)` | Create a `xql.node.CompoundStatement` describing `UNION` query | ||
`xql.UNION_ALL(...)` | Create a `xql.node.CompoundStatement` describing `UNION ALL` query | ||
`xql.SORT(c, sort, nulls)` | Create a `xql.node.Sort` node wrapping an `ORDER BY` clause | ||
@@ -191,3 +192,3 @@ | ||
:------------------------- | :------------------------------------ | ||
`.getType()` | Get the node type {String}. For example a `xql.node.SelectQuery` is a `SELECT` type, logical operator is `AND` or `OR` type, etc... | ||
`.getType()` | Get the node type {String}. For example a `xql.node.SelectStatement` is a `SELECT` type, logical operator is `AND` or `OR` type, etc... | ||
`.setType(type)` | Set the node type (used internally) | ||
@@ -198,3 +199,3 @@ `.getLabel()` | Get the node label that is rendered as `AS "label"` in SQL | ||
`.compileNode(ctx)` | Compile the node into a string. The `ctx` argument is currently not used, but it's designed in a way to pass an additional information to the compiler so multiple dialects can be used in the future. | ||
`.compileQuery(ctx?)` | Compile the query, it's basically a `compileNode()` call with semicolon `";"` at the end. This method should be used to return the query to be executed by your DB engine. It's provided by all query nodes. | ||
`.compileStatement(ctx?)` | Compile the query, it's basically a `compileNode()` call with semicolon `";"` at the end. This method should be used to return the query to be executed by your DB engine. It's provided by all query nodes. | ||
`.AS(label)` | Alias to `setLabel()`. | ||
@@ -233,7 +234,7 @@ `.EQ(b)` | Returns `this = b` expression. | ||
Select query is described by `xql.node.SelectQuery` node and wrapped by `xql.SELECT(...)`. It accepts arguments that are passed to the `FIELD()` method making the `SELECT(...)`, `SELECT([...])` and `SELECT().FIELD(...)` constructs equivalent. | ||
Select query is described by `xql.node.SelectStatement` node and wrapped by `xql.SELECT(...)`. It accepts arguments that are passed to the `FIELD()` method making the `SELECT(...)`, `SELECT([...])` and `SELECT().FIELD(...)` constructs equivalent. | ||
The `xql.node.SelectQuery` implements the following interface: | ||
The `xql.node.SelectStatement` implements the following interface: | ||
xql.node.SelectQuery | Description | ||
xql.node.SelectStatement | Description | ||
:------------------------- | :------------------------------------ | ||
@@ -327,7 +328,7 @@ `.FIELD(...)` | | ||
Insert query is described by `xql.node.InsertQuery` node and wrapped by `xql.INSERT(...)`. Note that `INSERT(...)` accepts parameters that can describe a target table and data to be inserted. | ||
Insert query is described by `xql.node.InsertStatement` node and wrapped by `xql.INSERT(...)`. Note that `INSERT(...)` accepts parameters that can describe a target table and data to be inserted. | ||
The `xql.node.InsertQuery` implements the following interface: | ||
The `xql.node.InsertStatement` implements the following interface: | ||
xql.node.InsertQuery | Description | ||
xql.node.InsertStatement | Description | ||
:------------------------- | :------------------------------------ | ||
@@ -366,7 +367,7 @@ `.TABLE(table)` | | ||
Update query is described by `xql.node.UpdateQuery` node and wrapped by `xql.UPDATE(...)`. Please note that `UPDATE(...)` accepts parameters that can describe a target table and data to be updated. | ||
Update query is described by `xql.node.UpdateStatement` node and wrapped by `xql.UPDATE(...)`. Please note that `UPDATE(...)` accepts parameters that can describe a target table and data to be updated. | ||
The `xql.node.UpdateQuery` implements the following interface: | ||
The `xql.node.UpdateStatement` implements the following interface: | ||
xql.node.UpdateQuery | Description | ||
xql.node.UpdateStatement | Description | ||
:------------------------- | :------------------------------------ | ||
@@ -409,7 +410,7 @@ `.TABLE(table)` | Specify a target `table` | ||
Delete query is described by `xql.node.DeleteQuery` node and wrapped by `xql.DELETE(...)`. | ||
Delete query is described by `xql.node.DeleteStatement` node and wrapped by `xql.DELETE(...)`. | ||
The `xql.node.DeleteQuery` implements the following interface: | ||
The `xql.node.DeleteStatement` implements the following interface: | ||
xql.node.DeleteQuery | Description | ||
xql.node.DeleteStatement | Description | ||
:------------------------- | :------------------------------------ | ||
@@ -465,4 +466,4 @@ `.TABLE(table)` | | ||
SET | ||
"tagsArray" = ARRAY['accounting', 'customer support'], -- Using PG ARRAY syntax. | ||
"tagsJson" = '["accounting", "customer support"]' -- Using PG JSON syntax. | ||
"tagsArray" = ARRAY['accounting', 'customer support'], -- Using PG ARRAY syntax. | ||
"tagsJson" = '["accounting", "customer support"]'::json -- Using PG JSON syntax. | ||
WHERE | ||
@@ -469,0 +470,0 @@ "userId" = 1; |
14
TODO.md
@@ -5,14 +5,14 @@ [ ] IDENTIFIER ESCAPING: http://www.postgresql.org/docs/9.3/static/sql-syntax-lexical.html | ||
[ ] ORDER_BY in aggregate function. | ||
[ ] PG ARRAY SYNTAX is harmful (empty array issue). | ||
[ ] UNKNOWN (special values in general) | ||
[ ] ORDER_BY (aggregate functions). | ||
[ ] EXPRESSION - IF / ELSE | ||
[ ] UNKNOWN (special values in general) | ||
[ ] IIF function in MSSQL dialect, and possibly MySQL dialect | ||
[ ] SELECT - [WITH [RECURSIVE] with_query ...] | ||
[ ] INSERT - [WITH [RECURSIVE] with_query ...] | ||
[ ] UPDATE - [WITH [RECURSIVE] with_query ...] | ||
[ ] DELETE - [WITH [RECURSIVE] with_query ...] | ||
[ ] WITH [RECURSIVE] | ||
[ ] INSERT ON CONFLICT DO NOTHING | ||
[ ] INSERT ON CONFLICT DO UPDATE SET ... WHERE ... | ||
[ ] INSERT ON CONFLICT ON CONSTRAINT ... | ||
[ ] UPDATE - [WHERE CURRENT OF cursor_name] | ||
[ ] DELETE - [WHERE CURRENT OF cursor_name] |
@@ -86,3 +86,6 @@ // xql.js <https://github.com/jsstuff/xql> | ||
describe("xql", function() { | ||
// Escape. | ||
// -------------------------------------------------------------------------- | ||
// [Escape] | ||
// -------------------------------------------------------------------------- | ||
it("should escape identifier.", function() { | ||
@@ -175,3 +178,6 @@ // Proper identifiers. | ||
// Substitute. | ||
// -------------------------------------------------------------------------- | ||
// [Substitute] | ||
// -------------------------------------------------------------------------- | ||
it("should substitute expression.", function() { | ||
@@ -211,3 +217,6 @@ shouldMatch( | ||
// OPERATORS. | ||
// -------------------------------------------------------------------------- | ||
// [Operators] | ||
// -------------------------------------------------------------------------- | ||
it("should test common operators", function() { | ||
@@ -238,3 +247,6 @@ shouldMatch(ADD(0, 1), '0 + 1'); | ||
// DATETIME. | ||
// -------------------------------------------------------------------------- | ||
// [DateTime] | ||
// -------------------------------------------------------------------------- | ||
it("should test common datetime functions", function() { | ||
@@ -246,3 +258,6 @@ shouldMatch(xql.NOW(), 'NOW()'); | ||
// SELECT. | ||
// -------------------------------------------------------------------------- | ||
// [Select] | ||
// -------------------------------------------------------------------------- | ||
it("should test SELECT(*).", function() { | ||
@@ -446,3 +461,6 @@ shouldMatch( | ||
// INSERT. | ||
// -------------------------------------------------------------------------- | ||
// [Insert] | ||
// -------------------------------------------------------------------------- | ||
it("should test INSERT INTO ... () VALUES (...)", function() { | ||
@@ -464,3 +482,13 @@ shouldMatch( | ||
// UPDATE. | ||
// INSERT DEFAULT VALUES. | ||
it("should test INSERT INTO ... () DEFAULT VALUES", function() { | ||
shouldMatch( | ||
INSERT("x").VALUES({}), | ||
'INSERT INTO "x" DEFAULT VALUES'); | ||
}); | ||
// -------------------------------------------------------------------------- | ||
// [Update] | ||
// -------------------------------------------------------------------------- | ||
it("should test UPDATE ... SET ...", function() { | ||
@@ -496,3 +524,6 @@ shouldMatch( | ||
// DELETE. | ||
// -------------------------------------------------------------------------- | ||
// [Delete] | ||
// -------------------------------------------------------------------------- | ||
it("should test DELETE ... ", function() { | ||
@@ -510,3 +541,7 @@ shouldMatch( | ||
// Combined query (UNION, INTERSECT, EXCEPT). | ||
// -------------------------------------------------------------------------- | ||
// [Compound] | ||
// -------------------------------------------------------------------------- | ||
// Compound (UNION, INTERSECT, EXCEPT). | ||
it("should test ... UNION ...", function() { | ||
@@ -548,3 +583,3 @@ shouldMatch( | ||
// Combined query with ORDER BY and/or OFFSET/LIMIT. | ||
// Compound with ORDER BY and/or OFFSET/LIMIT. | ||
it("should test ... UNION ... ORDER BY ... LIMIT ... OFFSET ...", function() { | ||
@@ -556,3 +591,3 @@ shouldMatch( | ||
// Multiple combined queries. | ||
// Multiple compound queries. | ||
it("should test ... UNION ... UNION ...", function() { | ||
@@ -585,3 +620,3 @@ shouldMatch( | ||
// Multiple combined queries of different kinds | ||
// Multiple compound queries of different kinds | ||
it("should test ... UNION ... INTERSECT ...", function() { | ||
@@ -588,0 +623,0 @@ shouldMatch( |
Sorry, the diff of this file is too big to display
213826
5403
466
8