sqlparser

package
v0.0.0-...-717370b Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultToJSONObjectTmpl = `` /* 140-byte string literal not displayed */

)
View Source
const (
	SqlInsertTmpl = `` /* 360-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Enum

type Enum struct {
	EnumName  string
	EnumValue string
}

type EnumField

type EnumField struct {
	StructField
	EnumFieldValues []EnumFieldValue
}

type EnumFieldValue

type EnumFieldValue struct {
	StructField
	EnumName         string
	EnumValue        string
	EnumValueProcess string // 如果是字符串类型,需要在EnumValue基础上添加双引号
	EnumComment      string
}

type Field

type Field struct {
	Name    string
	Type    string
	Tag     string
	DBField string
	Ref     Ref
	Comment string
	Enums   []Enum
}

type InsertField

type InsertField struct {
	Name  string
	NoDot bool
}

type InsertFieldValue

type InsertFieldValue struct {
	FieldValue string
	NoDot      bool
}

type InsertParam

type InsertParam struct {
	Ignore bool
	Table  string
	Fields []InsertField
	Values []InsertValue
}

func InsertParamFromStruct

func InsertParamFromStruct(s *Struct, opt *Option) *InsertParam

type InsertValue

type InsertValue struct {
	FieldValues []InsertFieldValue
	NoDot       bool
}

type Option

type Option struct {
	StructNameMapper       func(string) string         // 名称映射
	IgnoreField            []string                    // 忽略字段
	FieldNameMapper        func(string) string         // 字段名称映射
	FieldTypeMapper        func(string) string         // 字段类型映射
	FieldTagMapper         func(string, string) string // 可根据名称和类型自行决定字段tag
	RandomFieldValueByType func(string) any            // 根据字段类型生成随机值
	TrimTablePrefix        string                      // 表名前缀,若有则在转为结构体名前去掉

	Amount int // 数据条数
}

type ParseOption

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

type ParseSetter

type ParseSetter func(*ParseOption)

func WithTablePrefix

func WithTablePrefix(tablePrefix string) ParseSetter

type Ref

type Ref struct {
	Table string
	Field string
}

type ResultToJSONObject

type ResultToJSONObject struct {
	Fields []ResultToJSONObjectField
}

func FromStructForTmpl

func FromStructForTmpl(s *StructForTmpl) *ResultToJSONObject

type ResultToJSONObjectField

type ResultToJSONObjectField struct {
	JSONName   string
	ColumnName string
	NoComma    bool
}

type Struct

type Struct struct {
	PkgName   string
	Name      string
	TableName string
	Comment   string
	Fields    []Field

	HaveEnum bool
	// contains filtered or unexported fields
}

func ParseCreateSQL

func ParseCreateSQL(sql string) *Struct

func ParseCreateSQLBatch

func ParseCreateSQLBatch(sql string, opts ...ParseSetter) []*Struct

func (*Struct) Enter

func (v *Struct) Enter(in ast.Node) (ast.Node, bool)

func (*Struct) Gen

func (s *Struct) Gen(w io.Writer, opt Option) error

func (*Struct) GenData

func (s *Struct) GenData(w io.Writer, n int64, opt Option) error

func (*Struct) Leave

func (v *Struct) Leave(in ast.Node) (ast.Node, bool)

type StructField

type StructField struct {
	FieldName    string
	FieldType    string
	FieldTag     string
	FieldComment string
	DBField      string
}

type StructForTmpl

type StructForTmpl struct {
	PkgName       string
	Imports       []string
	TableName     string
	StructName    string
	StructComment string
	Fields        []StructField
	EnumFields    []EnumField
	HaveEnum      bool
}

func FromStruct

func FromStruct(s *Struct, opt Option) StructForTmpl

Jump to

Keyboard shortcuts

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