0.0.1-alpha.15

This commit is contained in:
Kijin-Seija 2024-06-19 20:12:27 +08:00
parent 9e0985b903
commit fa4666273d
4 changed files with 113 additions and 16 deletions

View File

@ -12,7 +12,7 @@
<script type="module"> <script type="module">
const { DtSqlParserSemAnalysePlugin } = await import(/* @vite-ignore */import.meta.env.VITE_ENTRY_PATH) const { DtSqlParserSemAnalysePlugin } = await import(/* @vite-ignore */import.meta.env.VITE_ENTRY_PATH)
const myPlugin = new DtSqlParserSemAnalysePlugin() const myPlugin = new DtSqlParserSemAnalysePlugin()
const sql = 'INSERT INTO |' const sql = 'CREATE TABLE "public"."h1" (c1 int8 not null, c2 int8, c3 int8) with (appendonly = true, orientation = horc) TABLESPACE horc_default DISTRIBUTED BY (|)'
const caretColumn = sql.indexOf('|') + 1 const caretColumn = sql.indexOf('|') + 1
const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn }) const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn })
console.log(result) console.log(result)

13
package-lock.json generated
View File

@ -1,14 +1,14 @@
{ {
"name": "dt-sql-parser-semantic-analyse-plugin", "name": "dt-sql-parser-semantic-analyse-plugin",
"version": "0.0.1-alpha.11", "version": "0.0.1-alpha.14",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "dt-sql-parser-semantic-analyse-plugin", "name": "dt-sql-parser-semantic-analyse-plugin",
"version": "0.0.1-alpha.11", "version": "0.0.1-alpha.14",
"dependencies": { "dependencies": {
"dt-sql-parser": "^4.0.1" "dt-sql-parser": "npm:dt-sql-parser-oushudb@^4.0.2-5"
}, },
"devDependencies": { "devDependencies": {
"@eslint/eslintrc": "^3.0.2", "@eslint/eslintrc": "^3.0.2",
@ -1904,9 +1904,10 @@
} }
}, },
"node_modules/dt-sql-parser": { "node_modules/dt-sql-parser": {
"version": "4.0.1", "name": "dt-sql-parser-oushudb",
"resolved": "http://npm.oushu.com:14837/dt-sql-parser/-/dt-sql-parser-4.0.1.tgz", "version": "4.0.2-5",
"integrity": "sha512-dgRxi/tsS99tjT3vrsyFBJoLd7Q+TVvl419QshFYSPNw75/JLh1Q/KfB3GxZRE/nL8o9fpsaEwyTDBpN4/Wj9A==", "resolved": "http://npm.oushu.com:14837/dt-sql-parser-oushudb/-/dt-sql-parser-oushudb-4.0.2-5.tgz",
"integrity": "sha512-fHu00/+Mk+QtCrS24Uc1vYV3xsy8BxyLyD0Oh4/TJwhBq7U+ZWunjHzcQBMccPyb8JnTYcG/HZ/f5EZ2GqQG4Q==",
"dependencies": { "dependencies": {
"antlr4-c3": "3.3.7", "antlr4-c3": "3.3.7",
"antlr4ng": "2.0.11" "antlr4ng": "2.0.11"

View File

@ -1,6 +1,6 @@
{ {
"name": "dt-sql-parser-semantic-analyse-plugin", "name": "dt-sql-parser-semantic-analyse-plugin",
"version": "0.0.1-alpha.11", "version": "0.0.1-alpha.15",
"description": "an dt-sql-parser plugin with semantic result", "description": "an dt-sql-parser plugin with semantic result",
"type": "module", "type": "module",
"files": [ "files": [
@ -37,6 +37,6 @@
"vite-plugin-node-polyfills": "^0.21.0" "vite-plugin-node-polyfills": "^0.21.0"
}, },
"dependencies": { "dependencies": {
"dt-sql-parser": "^4.0.1" "dt-sql-parser": "npm:dt-sql-parser-oushudb@^4.0.2-5"
} }
} }

View File

@ -2,12 +2,23 @@ import { PostgreSqlParser } from 'dt-sql-parser/dist/lib/postgresql/PostgreSqlPa
export const defaultAlias = { export const defaultAlias = {
selectstmt: 'selectStatement', selectstmt: 'selectStatement',
insertstmt: 'insertStatement',
target_el: 'target_label', target_el: 'target_label',
table_name: 'tableName' table_name: 'tableName',
view_name: 'viewName',
column_name: 'columnName',
schema_name: 'schemaName'
} }
export const defaultStmts = [ export const defaultStmts = [
'selectstmt', 'selectstmt',
'insertstmt',
'updatestmt',
'deletestmt',
'altertablestmt',
'alterfunctionstmt',
'dropstmt',
'createfunctionstmt'
] ]
export const defaultEntities = [ export const defaultEntities = [
@ -15,7 +26,12 @@ export const defaultEntities = [
'colid', 'colid',
'attr_name', 'attr_name',
'collabel', 'collabel',
'table_name' 'table_name',
'view_name',
'function_with_argtypes',
'column_name',
'schema_name',
'anysconst'
] ]
export const defaultRules: Record<string, number[]> = { export const defaultRules: Record<string, number[]> = {
@ -23,6 +39,67 @@ export const defaultRules: Record<string, number[]> = {
PostgreSqlParser.RULE_selectstmt, PostgreSqlParser.RULE_selectstmt,
PostgreSqlParser.RULE_target_el, PostgreSqlParser.RULE_target_el,
], ],
select_from_table: [
PostgreSqlParser.RULE_selectstmt,
PostgreSqlParser.RULE_from_clause,
PostgreSqlParser.RULE_table_name
],
insert_target_table: [
PostgreSqlParser.RULE_insertstmt,
PostgreSqlParser.RULE_insert_target,
PostgreSqlParser.RULE_table_name
],
update_relation_table: [
PostgreSqlParser.RULE_updatestmt,
PostgreSqlParser.RULE_relation_expr,
PostgreSqlParser.RULE_table_name
],
delete_relation_table: [
PostgreSqlParser.RULE_deletestmt,
PostgreSqlParser.RULE_relation_expr,
PostgreSqlParser.RULE_table_name
],
alter_table: [
PostgreSqlParser.RULE_altertablestmt,
PostgreSqlParser.RULE_relation_expr,
PostgreSqlParser.RULE_table_name
],
alter_view: [
PostgreSqlParser.RULE_altertablestmt,
PostgreSqlParser.RULE_view_name
],
alter_function: [
PostgreSqlParser.RULE_alterfunctionstmt,
PostgreSqlParser.RULE_alterFunctionTypeClause,
PostgreSqlParser.RULE_function_with_argtypes
],
alter_table_drop_column: [
PostgreSqlParser.RULE_altertablestmt,
PostgreSqlParser.RULE_alter_table_cmds,
PostgreSqlParser.RULE_column_name
],
drop_table: [
PostgreSqlParser.RULE_dropstmt,
PostgreSqlParser.RULE_table_name_list,
PostgreSqlParser.RULE_table_name
],
drop_view: [
PostgreSqlParser.RULE_dropstmt,
PostgreSqlParser.RULE_view_nameList,
PostgreSqlParser.RULE_view_name
],
drop_schema: [
PostgreSqlParser.RULE_dropstmt,
PostgreSqlParser.RULE_schema_name_list,
PostgreSqlParser.RULE_schema_name
],
create_function_sub_content: [
PostgreSqlParser.RULE_createfunctionstmt,
PostgreSqlParser.RULE_createfunc_opt_list,
PostgreSqlParser.RULE_colid,
PostgreSqlParser.RULE_anysconst,
],
// sub entities
select_target_colid: [ select_target_colid: [
PostgreSqlParser.RULE_target_el, PostgreSqlParser.RULE_target_el,
PostgreSqlParser.RULE_function_name, PostgreSqlParser.RULE_function_name,
@ -38,11 +115,6 @@ export const defaultRules: Record<string, number[]> = {
-PostgreSqlParser.RULE_attr_name, -PostgreSqlParser.RULE_attr_name,
PostgreSqlParser.RULE_collabel PostgreSqlParser.RULE_collabel
], ],
select_from_table: [
PostgreSqlParser.RULE_selectstmt,
PostgreSqlParser.RULE_from_clause,
PostgreSqlParser.RULE_table_name
],
table_name_colid: [ table_name_colid: [
PostgreSqlParser.RULE_table_name, PostgreSqlParser.RULE_table_name,
PostgreSqlParser.RULE_colid PostgreSqlParser.RULE_colid
@ -50,5 +122,29 @@ export const defaultRules: Record<string, number[]> = {
table_name_attr: [ table_name_attr: [
PostgreSqlParser.RULE_table_name, PostgreSqlParser.RULE_table_name,
PostgreSqlParser.RULE_attr_name, PostgreSqlParser.RULE_attr_name,
],
view_name_colid: [
PostgreSqlParser.RULE_view_name,
PostgreSqlParser.RULE_colid
],
view_name_attr: [
PostgreSqlParser.RULE_view_name,
PostgreSqlParser.RULE_attr_name,
],
function_colid: [
PostgreSqlParser.RULE_function_with_argtypes,
PostgreSqlParser.RULE_colid
],
function_attr: [
PostgreSqlParser.RULE_function_with_argtypes,
PostgreSqlParser.RULE_attr_name,
],
column_name_colid: [
PostgreSqlParser.RULE_column_name,
PostgreSqlParser.RULE_colid
],
column_name_attr: [
PostgreSqlParser.RULE_column_name,
PostgreSqlParser.RULE_attr_name,
] ]
} }