parser

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package parser is a library that parses to go structures based on sql and generates the code needed based on the template.

Index

Constants

View Source
const (
	// TableName table name
	TableName = "__table_name__"
	// CodeTypeModel model code
	CodeTypeModel = "model"
	// CodeTypeJSON json code
	CodeTypeJSON = "json"
	// CodeTypeDAO update fields code
	CodeTypeDAO = "dao"
	// CodeTypeHandler handler request and respond code
	CodeTypeHandler = "handler"
	// CodeTypeProto proto file code
	CodeTypeProto = "proto"
	// CodeTypeService grpc service code
	CodeTypeService = "service"

	// DBDriverMysql mysql driver
	DBDriverMysql = "mysql"
	// DBDriverPostgresql postgresql driver
	DBDriverPostgresql = "postgresql"
	// DBDriverTidb tidb driver
	DBDriverTidb = "tidb"
	// DBDriverSqlite sqlite driver
	DBDriverSqlite = "sqlite"
)

Variables

This section is empty.

Functions

func ConvertToMysqlTable added in v1.6.0

func ConvertToMysqlTable(tableName string, fields []*PGField) (string, map[string]string)

ConvertToMysqlTable convert to mysql table ddl

func GetMysqlTableInfo added in v1.6.0

func GetMysqlTableInfo(dsn, tableName string) (string, error)

GetMysqlTableInfo get table info from mysql

func GetSqliteTableInfo added in v1.6.0

func GetSqliteTableInfo(dbFile string, tableName string) (string, error)

GetSqliteTableInfo get table info from sqlite

func GetTableInfo

func GetTableInfo(dsn, tableName string) (string, error)

GetTableInfo get table info from mysql Deprecated: replaced by GetMysqlTableInfo

func ParseSQL

func ParseSQL(sql string, options ...Option) (map[string]string, error)

ParseSQL generate different usage codes based on sql

Types

type Codes

type Codes struct {
	Model         []string // model code
	UpdateFields  []string // update fields code
	ModelJSON     []string // model json code
	HandlerStruct []string // handler request and respond code
}

Codes content

type NullStyle

type NullStyle int

NullStyle null type

const (
	NullDisable NullStyle = iota
	NullInSql
	NullInPointer
)

nolint

type Option

type Option func(*options)

Option function

func WithCharset

func WithCharset(charset string) Option

WithCharset set charset

func WithCollation

func WithCollation(collation string) Option

WithCollation set collation

func WithColumnPrefix

func WithColumnPrefix(p string) Option

WithColumnPrefix set column prefix

func WithDBDriver added in v1.6.0

func WithDBDriver(driver string) Option

WithDBDriver set db driver

func WithEmbed

func WithEmbed() Option

WithEmbed is embed gorm.Model

func WithFieldTypes added in v1.6.0

func WithFieldTypes(fieldTypes map[string]string) Option

WithFieldTypes set field types

func WithForceTableName

func WithForceTableName() Option

WithForceTableName set forceFloats

func WithGormType

func WithGormType() Option

WithGormType will write type in gorm tag

func WithJSONTag

func WithJSONTag(namedType int) Option

WithJSONTag set json tag, 0 for underscore, other values for hump

func WithNoNullType

func WithNoNullType() Option

WithNoNullType set NoNullType

func WithNullStyle

func WithNullStyle(s NullStyle) Option

WithNullStyle set NullType

func WithPackage

func WithPackage(pkg string) Option

WithPackage set package name

func WithTablePrefix

func WithTablePrefix(p string) Option

WithTablePrefix set table prefix

func WithWebProto added in v1.5.0

func WithWebProto() Option

WithWebProto set proto file type

type PGField added in v1.6.0

type PGField struct {
	Name      string `gorm:"column:name;" json:"name"`
	Type      string `gorm:"column:type;" json:"type"`
	Comment   string `gorm:"column:comment;" json:"comment"`
	Length    int    `gorm:"column:length;" json:"length"`
	Lengthvar int    `gorm:"column:lengthvar;" json:"lengthvar"`
	Notnull   bool   `gorm:"column:notnull;" json:"notnull"`
}

PGField postgresql field

func GetPostgresqlTableInfo added in v1.6.0

func GetPostgresqlTableInfo(dsn string, tableName string) ([]*PGField, error)

GetPostgresqlTableInfo get table info from postgres

Jump to

Keyboard shortcuts

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