Skip to content

Commit 3d724c4

Browse files
authored
Merge pull request #385 from dolthub/taylor/sql-parser-up
utils: Up node-sql-parser, fix and add tests
2 parents 9798808 + 60ab5fe commit 3d724c4

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"url": "https://github.com/dolthub/react-library/issues"
6060
},
6161
"dependencies": {
62-
"node-sql-parser": "^5.3.5",
62+
"node-sql-parser": "^5.3.10",
6363
"timeago.js": "^4.0.2"
6464
}
6565
}

packages/utils/src/__tests__/helpers/mutationExamples.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ export const mutationExamples = [
7575
"SET GLOBAL slow_query_log = 1",
7676
"SET SESSION slow_query_log = 1",
7777
"FLUSH PRIVILEGES",
78+
`REPLACE INTO dolt_docs VALUES ("README.md", "This is a README with a \\"quote\\".")`,
7879
];

packages/utils/src/__tests__/parseSqlQuery.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,31 @@ function getParserCol(
537537
column: name,
538538
table: table ?? null,
539539
type: "column_ref",
540+
// TODO: Remove type cast when this issue is fixed https://github.com/taozhi8833998/node-sql-parser/issues/2522
541+
collate: null as any,
540542
},
541543
as: null,
542544
type: includeType ? "expr" : undefined,
543545
};
544546
}
545547

548+
function getParserStarCol(): Column {
549+
return {
550+
expr: {
551+
column: "*",
552+
table: null,
553+
type: "column_ref",
554+
},
555+
as: null,
556+
};
557+
}
558+
546559
describe("test getColumns", () => {
547560
const tests = [
548561
{
549562
desc: "select *",
550563
query: "select * from `test`",
551-
expected: [getParserCol("*")],
564+
expected: [getParserStarCol()],
552565
},
553566
{
554567
desc: "select one column",

packages/utils/src/parseSqlQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export function isMutation(q?: string): boolean {
336336
lower.startsWith("revoke") ||
337337
lower.startsWith("grant") ||
338338
lower.startsWith("flush") ||
339+
// lower.startsWith("replace into") ||
339340
(lower.startsWith("with") &&
340341
((lower.includes("update") && lower.includes("set")) ||
341342
lower.includes("delete from")))

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ __metadata:
25432543
babel-jest: "npm:^30.0.2"
25442544
eslint: "npm:^8.57.0"
25452545
jest: "npm:^29.7.0"
2546-
node-sql-parser: "npm:^5.3.5"
2546+
node-sql-parser: "npm:^5.3.10"
25472547
prettier: "npm:^3.6.2"
25482548
rollup: "npm:^4.46.2"
25492549
rollup-plugin-dts: "npm:^6.2.1"
@@ -12697,13 +12697,13 @@ __metadata:
1269712697
languageName: node
1269812698
linkType: hard
1269912699

12700-
"node-sql-parser@npm:^5.3.5":
12701-
version: 5.3.5
12702-
resolution: "node-sql-parser@npm:5.3.5"
12700+
"node-sql-parser@npm:^5.3.10":
12701+
version: 5.3.10
12702+
resolution: "node-sql-parser@npm:5.3.10"
1270312703
dependencies:
1270412704
"@types/pegjs": "npm:^0.10.0"
1270512705
big-integer: "npm:^1.6.48"
12706-
checksum: 221c0e5d582adf9e87a4357cc437f6f66e925eaefa889f05b8e93375274b0246edbca11a673e7d44a29888ca0ec6005b5614ac08361b0e9171d11c66ce17e91a
12706+
checksum: a4c417a429d4d438548f858e62be091148a52256c39b419c0e0eb259af5feb6fa555928a98e2fe3a07a974a2ce065ea12df04ac18f5a01bfa918df32cebc6a2a
1270712707
languageName: node
1270812708
linkType: hard
1270912709

0 commit comments

Comments
 (0)