Skip to content

Commit 05c8380

Browse files
committed
add typescript definition support
1 parent 301dc15 commit 05c8380

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

index.d.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
declare module 'node-sql-parser' {
2+
enum Type {
3+
SELECT='select',
4+
UPDATE='update',
5+
INSERT='insert',
6+
DELETE='delete',
7+
REPLACE='replace'
8+
}
9+
interface With {
10+
name: string,
11+
stmt: any[],
12+
columns?: any[]
13+
}
14+
enum WhilteListCheckMode {
15+
TABLE='table',
16+
COLUMN='column'
17+
}
18+
export interface TableColumnAst {
19+
tableList: string[],
20+
columnsList: string[],
21+
ast: AST[] | AST
22+
}
23+
interface Select {
24+
with?: With,
25+
type: Type.SELECT | Type.UPDATE | Type.INSERT | Type.DELETE | Type.REPLACE,
26+
options?: any[],
27+
distinct?: 'DISTINCT',
28+
columns: any[] | '*',
29+
from?: [],
30+
where?: any,
31+
groupby?: any[],
32+
having?: any[],
33+
orderby?: any[],
34+
limit?: {type: string, value: number}[]
35+
}
36+
37+
interface Insert {
38+
39+
}
40+
export type AST = Select | Insert
41+
export class Parser {
42+
constructor();
43+
parse(sql: string): TableColumnAst;
44+
astify(sql: string): AST[] | AST;
45+
sqlify(ast: AST[] | AST): string;
46+
whiteListCheck(sql: string, whiteList: string[], type?: WhilteListCheckMode.TABLE | WhilteListCheckMode.COLUMN): Error | undefined;
47+
tableList(sql: string): string[];
48+
columnList(sql: string): string[];
49+
}
50+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "simple node sql parser",
55
"main": "index.js",
6+
"type": "index.d.ts",
67
"scripts": {
78
"build": "mkdir -p build && pegjs -o build/pegjs-parser.js sql.pegjs",
89
"test": "npm run lint && mocha",

0 commit comments

Comments
 (0)