Skip to content

@joe-re/sql-parser does not understand STRICT or WITHOUT ROWID #131

Open
@xnuk

Description

@xnuk
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
                                           ^

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions