Go to file
Kijin-Seija 645a73d6af 0.0.1-alpha.6:
1. 修改 `package.json` 中的项目名称和版本号。
2. 更新 `node_modules` 中的依赖包版本。
3. 修改 `src/index.ts` 中的 SQL 语句和 `caretColumn` 的计算方式。
4. 修改 `src/parse/default-rules.ts` 中的规则和导入语句。
5. 修改 `src/parse/visitor.ts` 中的访问者和规则。
6. 修改 `src/preprocess/default-preprocessor.ts` 中的预处理逻辑。
7. 修改 `src/types.ts` 中的导入语句。
2024-04-15 17:48:24 +08:00
src 0.0.1-alpha.6: 2024-04-15 17:48:24 +08:00
.env init 2024-04-07 19:10:38 +08:00
.env.preview-es init 2024-04-07 19:10:38 +08:00
.env.preview-umd init 2024-04-07 19:10:38 +08:00
.eslintignore init 2024-04-07 19:10:38 +08:00
.eslintrc.yml 0.0.1-alpha.3 2024-04-09 16:10:52 +08:00
.gitignore init 2024-04-07 19:10:38 +08:00
.nvmrc init 2024-04-07 19:10:38 +08:00
index.html 0.0.1-alpha.6: 2024-04-15 17:48:24 +08:00
package-lock.json 0.0.1-alpha.6: 2024-04-15 17:48:24 +08:00
package.json 0.0.1-alpha.6: 2024-04-15 17:48:24 +08:00
README.md init 2024-04-07 19:10:38 +08:00
tsconfig.json 0.0.1-alpha.4 2024-04-09 16:19:59 +08:00
tsconfig.node.json init 2024-04-07 19:10:38 +08:00
vite.config.ts init 2024-04-07 19:10:38 +08:00

dt-sql-parser-semantic-analyse-plugin

A dt-sql-parser plugin with semantic result. Theory.

Installation

npm install dt-sql-parser-semantic-analyse-plugin

Quick Usage

const myPlugin = new DtSqlParserSemAnalysePlugin()
const sql = 'SELECT a| FROM t'
const caretColumn = sql.indexOf('|') + 1
const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn })
console.log(result)

This will use a postgresql Parser and build-in rules/preprocessors

Add a Rule Chain

import { PostgresSQL } from 'dt-sql-parser'
import { PostgreSQLParser } from 'dt-sql-parser/dist/lib/pgsql/PostgreSQLParser'

const myPlugin = new DtSqlParserSemAnalysePlugin({
  parse: {
    parser: new PostgresSQL()
    stmts: [
      'selectstmt'
    ],
    entities: [
      'column_name'
    ],
    rules: {
      'select_columns': [
        PostgreSQLParser.RULE_insertstmt,
        PostgreSQLParser.RULE_column_name
      ]      
    }
  }
})
const sql = 'SELECT a| FROM t'
const caretColumn = sql.indexOf('|') + 1
const result = myPlugin.parse(sql.replace('|', ''), { lineNumber: 1, columnNumber: caretColumn })
console.log(result)

Notice: A rule must start with a/an statement/entity and stop with an entity. You should add a node keywords(keyword is in your parser with format: RULE_[keyword]) into stmts/entities before using it.

Add a preprocessor

const myPlugin = new DtSqlParserSemAnalysePlugin({
  preprocessor: [
    (sql) => sql.toUpperCase()
})