@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseData } from "../../src/core/data";
|
||||
import { runQuery } from "../../src/core/query";
|
||||
import { parsePathQuery, parseSqlQuery, runQuery } from "../../src/core/query";
|
||||
describe("query engine", () => {
|
||||
const root = parseData(
|
||||
'[{"team":"a","n":2},{"team":"a","n":4},{"team":"b","n":9}]',
|
||||
@@ -32,4 +32,31 @@ describe("query engine", () => {
|
||||
/Unsupported path/iu,
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes parsed SQL and path ASTs", () => {
|
||||
expect(
|
||||
parseSqlQuery(
|
||||
"SELECT team AS group_name WHERE n >= 2 ORDER BY n DESC LIMIT 4",
|
||||
),
|
||||
).toMatchObject({
|
||||
type: "sql-query",
|
||||
select: [{ type: "field", path: ["team"], alias: "group_name" }],
|
||||
where: [{ type: "condition", path: ["n"], operator: ">=", value: 2 }],
|
||||
orderBy: { path: ["n"], direction: "DESC" },
|
||||
limit: 4,
|
||||
});
|
||||
expect(parsePathQuery("$[*][?(@.n >= 4)].team").segments).toEqual([
|
||||
{ type: "wildcard" },
|
||||
{
|
||||
type: "filter",
|
||||
condition: {
|
||||
type: "condition",
|
||||
path: ["n"],
|
||||
operator: ">=",
|
||||
value: 4,
|
||||
},
|
||||
},
|
||||
{ type: "property", key: "team", quoted: false },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user