{"modulePath":"github.com/18721889353/sunshine","version":"v1.4.67","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package parser\n\nPackage parser is a library that parses to go structures based on sql and generates the code needed based on the template.\n\n## Constants\n\n```go\nconst (\n\t// TableName table name\n\tTableName = \"__table_name__\"\n\t// CodeTypeModel model code\n\tCodeTypeModel = \"model\"\n\t// CodeTypeJSON json code\n\tCodeTypeJSON = \"json\"\n\t// CodeTypeDAO update fields code\n\tCodeTypeDAO = \"dao\"\n\t// CodeTypeHandler handler request and respond code\n\tCodeTypeHandler = \"handler\"\n\t// CodeTypeProto proto file code\n\tCodeTypeProto = \"proto\"\n\t// CodeTypeService grpc service code\n\tCodeTypeService = \"service\"\n\t// CodeTypeCrudInfo crud info json data\n\tCodeTypeCrudInfo = \"crud_info\"\n\t// CodeTypeTableInfo table info json data\n\tCodeTypeTableInfo = \"table_info\"\n\n\t// DBDriverMysql mysql driver\n\tDBDriverMysql = \"mysql\"\n)\n```\n\n```go\nconst (\n\t// SubStructKey sub struct key for model\n\tSubStructKey = \"__sub_struct__\"\n\t// ProtoSubStructKey sub struct key for protobuf\n\tProtoSubStructKey = \"__proto_sub_struct__\"\n)\n```\n\n## Functions\n\n```go\nfunc GetMysqlTableInfo(dsn, tableName string) (string, error)\n```\nGetMysqlTableInfo 从 MySQL 数据库中获取表的创建信息\n\n```go\nfunc ParseSQL(sql string, options ...Option) (map[string]string, error)\n```\nParseSQL generate different usage codes based on sql\n\n```go\nfunc UnMarshalTableInfo(data string) (map[string]interface{}, error)\n```\nUnMarshalTableInfo unmarshal the json data to TableInfo struct\n\n## Types\n\n```go\ntype Codes struct {\n\tModel         []string // model code\n\tUpdateFields  []string // update fields code\n\tModelJSON     []string // model json code\n\tHandlerStruct []string // handler request and respond code\n}\n```\nCodes content\n\n```go\ntype CrudInfo struct {\n\tTableNameCamel          string `json:\"tableNameCamel\"`          // camel case, example: FooBar\n\tTableNameCamelFCL       string `json:\"tableNameCamelFCL\"`       // camel case and first character lower, example: fooBar\n\tTableNamePluralCamel    string `json:\"tableNamePluralCamel\"`    // plural, camel case, example: FooBars\n\tTableNamePluralCamelFCL string `json:\"tableNamePluralCamelFCL\"` // plural, camel case, example: fooBars\n\n\tColumnName               string `json:\"columnName\"`               // column name, example: first_name\n\tColumnNameCamel          string `json:\"columnNameCamel\"`          // column name, camel case, example: FirstName\n\tColumnNameCamelFCL       string `json:\"columnNameCamelFCL\"`       // column name, camel case and first character lower, example: firstName\n\tColumnNamePluralCamel    string `json:\"columnNamePluralCamel\"`    // column name, plural, camel case, example: FirstNames\n\tColumnNamePluralCamelFCL string `json:\"columnNamePluralCamelFCL\"` // column name, plural, camel case and first character lower, example: firstNames\n\n\tGoType       string `json:\"goType\"`       // go type, example: string, uint64\n\tGoTypeFCU    string `json:\"goTypeFCU\"`    // go type, first character upper, example: String, Uint64\n\tProtoType    string `json:\"protoType\"`    // proto type, example: string, uint64\n\tIsStringType bool   `json:\"isStringType\"` // go type is string or not\n\n\tPrimaryKeyColumnName string `json:\"PrimaryKeyColumnName\"` // primary key, example: id\n\tIsCommonType         bool   `json:\"isCommonType\"`         // custom primary key name and type\n\tIsStandardPrimaryKey bool   `json:\"isStandardPrimaryKey\"` // standard primary key id\n}\n```\nCrudInfo crud info for cache, dao, handler, service, protobuf, error\n\n```go\nfunc (info *CrudInfo) CheckCommonType() bool\n```\nCheckCommonType 检查是否为通用类型\n\n```go\nfunc (info *CrudInfo) GetGRPCProtoValidation() string\n```\nGetGRPCProtoValidation 获取gRPC Proto验证规则\n\n```go\nfunc (info *CrudInfo) GetWebProtoValidation() string\n```\nGetWebProtoValidation 获取Web Proto验证规则\n\n```go\ntype Field struct {\n\tColumnName         string // original column name, example: foo_bar\n\tColumnNameCamel    string // first character lower, example: FooBar\n\tColumnNameCamelFCL string // first character lower, example: fooBar\n\n\tColumnComment string // column comment\n\tIsPrimaryKey  bool   // is primary key\n\n\tGoType string // convert to go type\n\tTag    string // tag for model struct field, default gorm tag\n}\n```\nField is the struct for column information\n\n```go\ntype NullStyle int\n```\nNullStyle 定义了处理 SQL 中 NULL 值的不同风格\n\n```go\nconst (\n\tNullDisable   NullStyle = iota // 不处理 NULL 值\n\tNullInSql                      // 在 SQL 语句中使用 NULL\n\tNullInPointer                  // 使用指针来表示 NULL 值\n)\n```\nnolint 忽略某些 linter 规则\n\n```go\ntype Option func(*options)\n```\nOption 是一个函数类型，用于设置选项\n\n```go\nfunc WithCharset(charset string) Option\n```\nWithCharset 设置字符集\n\n```go\nfunc WithCollation(collation string) Option\n```\nWithCollation 设置排序规则\n\n```go\nfunc WithColumnPrefix(p string) Option\n```\nWithColumnPrefix 设置列名前缀\n\n```go\nfunc WithCustomTemplate() Option\n```\nWithCustomTemplate 设置是否使用自定义扩展模板\n\n```go\nfunc WithDBDriver(driver string) Option\n```\nWithDBDriver 设置数据库驱动\n\n```go\nfunc WithEmbed() Option\n```\nWithEmbed 设置是否嵌入 gorm.Model\n\n```go\nfunc WithExtendedAPI() Option\n```\nWithExtendedAPI 设置是否生成扩展 API\n\n```go\nfunc WithFieldTypes(fieldTypes map[string]string) Option\n```\nWithFieldTypes 设置字段类型映射\n\n```go\nfunc WithForceTableName() Option\n```\nWithForceTableName 设置是否强制使用表名\n\n```go\nfunc WithGormType() Option\n```\nWithGormType 设置是否在 GORM 标签中写入类型\n\n```go\nfunc WithJSONTag(namedType int) Option\n```\nWithJSONTag 设置是否生成 JSON 标签以及命名类型\n\n```go\nfunc WithNoNullType() Option\n```\nWithNoNullType 设置是否禁用 NULL 类型处理\n\n```go\nfunc WithNullStyle(s NullStyle) Option\n```\nWithNullStyle 设置处理 NULL 值的风格\n\n```go\nfunc WithPackage(pkg string) Option\n```\nWithPackage 设置生成代码的包名\n\n```go\nfunc WithTablePrefix(p string) Option\n```\nWithTablePrefix 设置表名前缀\n\n```go\nfunc WithWebProto() Option\n```\nWithWebProto 设置是否生成包含路由路径和 Swagger 信息的 proto 文件\n\n```go\ntype PrimaryKey struct {\n\tName               string // primary key name, example: foo_bar\n\tNameCamel          string // primary key name, camel case, example: FooBar\n\tNameCamelFCL       string // primary key name, camel case and first character lower, example: fooBar\n\tNamePluralCamel    string // primary key name, plural, camel case, example: FooBars\n\tNamePluralCamelFCL string // primary key name, plural, camel case and first character lower, example: fooBars\n\n\tGoType    string // go type, example:  int, string\n\tGoTypeFCU string // go type, first character upper, example: Int64, String\n\n\tIsStringType bool // go type is string or not\n}\n```\nPrimaryKey is the struct for primary key information, it used for generate CRUD code\n\n```go\ntype TableInfo struct {\n\tTableNamePrefix string // table name prefix, example: t_\n\n\tTableName               string // original table name, example: foo_bar\n\tTableNameCamel          string // camel case, example: FooBar\n\tTableNameCamelFCL       string // camel case and first character lower, example: fooBar\n\tTableNamePluralCamel    string // plural, camel case, example: FooBars\n\tTableNamePluralCamelFCL string // plural, camel case and first character lower, example: fooBars\n\tTableNameSnake          string // snake case, example: foo_bar\n\n\tTableComment string // table comment\n\n\tColumns    []Field     // columns of the table\n\tPrimaryKey *PrimaryKey // primary key information\n\n\tDBDriver string // database driver, example: mysql\n\n\tColumnSubStructure string // column sub structure for model\n\tColumnSubMessage   string // sub message for protobuf\n}\n```\nTableInfo is the struct for extend template\n\n","path":"github.com/18721889353/sunshine/pkg/sql2code/parser","name":"parser","synopsis":"Package parser is a library that parses to go structures based on sql and generates the code needed based on the template.","isRedistributable":true}
