Open
Description
import { parse } from "@joe-re/sql-parser"; // v1.2.1
const testParse = (query) => {
try {
parse(query);
} catch (e) {
// pretty printing error
const { start, end } = e.location;
const highlight = [...query]
.map((char, index) =>
start.offset <= index && index < end.offset ? "^" : " "
)
.join("");
console.log(e.message);
console.log(query);
console.log(highlight);
}
};
// https://www.sqlite.org/stricttables.html
testParse("CREATE TABLE apple(juice TEXT PRIMARY KEY) STRICT");
// https://www.sqlite.org/withoutrowid.html
testParse("CREATE TABLE apple(juice TEXT PRIMARY KEY) WITHOUT ROWID");
Output:
Expected "--", "/*", ";", [ \t\n\r], or end of input but "S" found.
CREATE TABLE apple(juice TEXT PRIMARY KEY) STRICT
^
Expected "--", "/*", ";", [ \t\n\r], or end of input but "W" found.
CREATE TABLE apple(juice TEXT PRIMARY KEY) WITHOUT ROWID
^