parser

package
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package parser 封装 TiDB SQL 解析器,提供 VDS SQL 层使用的 AST 类型。

M1 只支持单语句解析,不支持多语句批量解析。 底层使用 github.com/pingcap/tidb/pkg/parser(ADR-004)。

SQL 重写机制:

parser 包实现了 SQL 方言转换层,通过正则表达式重写将非标准 SQL 语法 转换为 TiDB Parser 可接受的形式。当前支持的重写规则:

  • ON CONFLICT DO UPDATE → ON DUPLICATE KEY UPDATE(PostgreSQL → MySQL)
  • ON CONFLICT DO NOTHING → INSERT IGNORE INTO
  • DROP CONSTRAINT → DROP FOREIGN KEY
  • ALTER COLUMN SET DEFAULT <time_func> → sentinel 字符串(绕过 TiDB Parser 限制)

重写后的 SQL 由 builder 层识别 sentinel 前缀并转换回正确的表达式类型。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser SQL 解析器封装

func New

func New() *Parser

New 创建 Parser 实例

func (*Parser) Parse

func (p *Parser) Parse(sql string) (Statement, error)

Parse 解析单条 SQL 语句,返回 AST 节点。 空语句或多语句输入返回错误。 支持将 PostgreSQL ON CONFLICT ... DO UPDATE SET 语法透明转换为 MySQL ON DUPLICATE KEY UPDATE 语法。

type Statement

type Statement = ast.StmtNode

Statement TiDB AST 节点别名(上层包直接使用,无需引入 tidb/parser)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL