parser

package
v0.0.0-...-52c304b Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotReadOnly    = coreErrors.New(coreErrors.ErrNL2SQLValidateFailed, "SQL语句不是只读操作")
	ErrInvalidSQL     = coreErrors.New(coreErrors.ErrNL2SQLValidateFailed, "无效的SQL语句")
	ErrUnsafeKeywords = coreErrors.New(coreErrors.ErrNL2SQLValidateFailed, "SQL包含危险关键字")
	ErrNoFromClause   = coreErrors.New(coreErrors.ErrNL2SQLValidateFailed, "缺少FROM子句")
)

Functions

This section is empty.

Types

type Column

type Column struct {
	Name     string
	DataType string // TEXT, INTEGER, FLOAT, BOOLEAN, TIMESTAMP
	Nullable bool
}

Column 列定义

type FileParser

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

FileParser CSV/Excel文件解析器

func NewFileParser

func NewFileParser(db *gorm.DB) *FileParser

NewFileParser 创建文件解析器

func (*FileParser) ParseFile

func (p *FileParser) ParseFile(ctx context.Context, filePath string) (*ParsedTable, error)

ParseFile 解析CSV或Excel文件

type ParsedTable

type ParsedTable struct {
	TableName string
	Columns   []Column
	Rows      [][]interface{}
}

ParsedTable 解析后的表结构

type SQLValidator

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

SQLValidator SQL校验器

func NewSQLValidator

func NewSQLValidator() *SQLValidator

NewSQLValidator 创建SQL校验器

func (*SQLValidator) AddLimitIfMissing

func (v *SQLValidator) AddLimitIfMissing(sql string, defaultLimit int) (string, error)

AddLimitIfMissing 如果SQL没有LIMIT子句,添加默认LIMIT

func (*SQLValidator) ExtractColumns

func (v *SQLValidator) ExtractColumns(sql string) ([]string, error)

ExtractColumns 提取SQL中使用的所有列名

func (*SQLValidator) ExtractTables

func (v *SQLValidator) ExtractTables(sql string) ([]string, error)

ExtractTables 提取SQL中使用的所有表名

func (*SQLValidator) ParseSQL

func (v *SQLValidator) ParseSQL(sql string) (*sqlparser.Select, error)

ParseSQL 解析SQL并返回AST

func (*SQLValidator) Validate

func (v *SQLValidator) Validate(sql string) error

Validate 校验SQL(默认方法,调用ValidateReadOnly)

func (*SQLValidator) ValidateReadOnly

func (v *SQLValidator) ValidateReadOnly(sql string) error

ValidateReadOnly 校验SQL是否只读

type TableImporter

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

TableImporter 表导入器

func NewTableImporter

func NewTableImporter(db *gorm.DB, dbType string) *TableImporter

NewTableImporter 创建表导入器

func (*TableImporter) DropTable

func (t *TableImporter) DropTable(ctx context.Context, tableName string) error

DropTable 删除表(用于清理)

func (*TableImporter) ImportTable

func (t *TableImporter) ImportTable(ctx context.Context, table *ParsedTable) error

ImportTable 将解析的表导入到nl2sql schema/database

func (*TableImporter) TableExists

func (t *TableImporter) TableExists(ctx context.Context, tableName string) (bool, error)

TableExists 检查表是否存在

Jump to

Keyboard shortcuts

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