Skip to content

Commit

Permalink
BREAKING! Move ReindexStmt from AllSqliteNodes to AllIndexNodes
Browse files Browse the repository at this point in the history
Also rename ReindexStmt.table field to ReindexStmt.name
  • Loading branch information
nene committed Feb 5, 2024
1 parent ab6eed7 commit 79b68c2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/cst/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export type AllIndexStatements =
| CreateIndexStmt
| DropIndexStmt
| AlterIndexStmt
| AlterIndexAllInTablespaceStmt;
| AlterIndexAllInTablespaceStmt
| ReindexStmt;

// CREATE INDEX
export interface CreateIndexStmt extends BaseNode {
Expand Down Expand Up @@ -119,3 +120,10 @@ export interface AlterIndexAllInTablespaceStmt extends BaseNode {
ownedBy?: OwnedByClause;
action: AlterActionSetTablespace;
}

// PostgreSQL, SQLite
export interface ReindexStmt extends BaseNode {
type: "reindex_stmt";
reindexKw: Keyword<"REINDEX">;
name?: EntityName;
}
7 changes: 0 additions & 7 deletions src/cst/dialects/Sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type AllSqliteStatements =
| AttachDatabaseStmt
| DetachDatabaseStmt
| VacuumStmt
| ReindexStmt
| PragmaStmt;

export interface AttachDatabaseStmt extends BaseNode {
Expand All @@ -39,12 +38,6 @@ export interface VacuumStmt extends BaseNode {
file?: StringLiteral;
}

export interface ReindexStmt extends BaseNode {
type: "reindex_stmt";
reindexKw: Keyword<"REINDEX">;
table?: EntityName;
}

export interface PragmaStmt extends BaseNode {
type: "pragma_stmt";
pragmaKw: Keyword<"PRAGMA">;
Expand Down
12 changes: 6 additions & 6 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ ddl_statement
/ drop_index_stmt
/ &postgres x:alter_index_stmt { return x; }
/ &postgres x:alter_index_all_in_tablespace_stmt { return x; }
/ (&postgres / &sqlite) x:reindex_stmt { return x; }
/ &sqlite x:ddl_statement_sqlite { return x; }
/ &mysql x:ddl_statement_mysql { return x; }
/ &bigquery x:ddl_statement_bigquery { return x; }
Expand Down Expand Up @@ -2139,6 +2140,11 @@ alter_index_all_in_tablespace_stmt
});
}

reindex_stmt
= kw:REINDEX name:(__ entity_name)? {
return loc({ type: "reindex_stmt", reindexKw: kw, name: read(name) });
}

/**
* ------------------------------------------------------------------------------------ *
* *
Expand Down Expand Up @@ -4410,7 +4416,6 @@ sqlite_statement
= attach_database_stmt
/ detach_database_stmt
/ vacuum_stmt
/ reindex_stmt
/ pragma_stmt

attach_database_stmt
Expand Down Expand Up @@ -4453,11 +4458,6 @@ vacuum_stmt
});
}

reindex_stmt
= kw:REINDEX table:(__ entity_name)? {
return loc({ type: "reindex_stmt", reindexKw: kw, table: read(table) });
}

pragma_stmt
= kw:(PRAGMA __) pragma:(pragma_assignment / pragma_func_call / entity_name) {
return loc({
Expand Down
1 change: 0 additions & 1 deletion src/showNode/dialects/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const sqliteMap: FullTransformMap<string, AllSqliteNodes> = {
show([node.detachKw, node.databaseKw, node.schema]),
vacuum_stmt: (node) =>
show([node.vacuumKw, node.schema, node.intoKw, node.file]),
reindex_stmt: (node) => show([node.reindexKw, node.table]),
pragma_stmt: (node) => show([node.pragmaKw, node.pragma]),
pragma_assignment: (node) => show([node.name, "=", node.value]),
pragma_func_call: (node) => show([node.name, node.args]),
Expand Down
2 changes: 2 additions & 0 deletions src/showNode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ export const indexMap: FullTransformMap<string, AllIndexNodes> = {
node.ownedBy,
node.action,
]),

reindex_stmt: (node) => show([node.reindexKw, node.name]),
};
10 changes: 10 additions & 0 deletions test/ddl/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,14 @@ describe("index", () => {
});
});
});

describe("reindex", () => {
dialect("sqlite", () => {
it("supports simple REINDEX", () => {
testWc("REINDEX");
testWc("REINDEX tbl");
testWc("REINDEX my_schema.tbl");
});
});
});
});
8 changes: 0 additions & 8 deletions test/sqlite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ describe("SQLite specific statements", () => {
});
});

describe("REINDEX", () => {
it("supports REINDEX statement", () => {
testWc("REINDEX");
testWc("REINDEX tbl");
testWc("REINDEX my_schema.tbl");
});
});

describe("PRAGMA", () => {
it("supports quering PRAGMA name", () => {
testWc("PRAGMA function_list");
Expand Down

0 comments on commit 79b68c2

Please sign in to comment.