gen_mysql

package
v0.0.0-...-2c606a2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright 2024 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2024 aggronmagi <czy463@163.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var Config = &GenerateEnv{
	SvcPkg:   "github.com/walleframe/svc_db",
	UtilPkg:  "github.com/walleframe/walle/util",
	CodePath: "pkg/gen/mysqlop/",
	Charset:  "utf8mb4",
	Collate:  "utf8mb4_general_ci",
}

Functions

func Generate

func Generate(tbl *SqlTable) (out []*tpl.BuildOutput, err error)

func InitTemplate

func InitTemplate() (err error)

func ParseConfigFromEnv

func ParseConfigFromEnv()

Types

type GenerateEnv

type GenerateEnv struct {
	SvcPkg    string
	UtilPkg   string
	CodePath  string
	Charset   string
	Collate   string
	DisableEx bool
}

type SqlColumn

type SqlColumn struct {
	Name      string       // column name
	GoType    string       // golang type
	SqlType   string       // mysql type define. eg: varchar(64) not null default ”
	Marshal   string       // Marshal Function, use for not base type
	Unmarshal string       // Unmarshal Function, use for not base type
	Doc       *tpl.Commets // column doc
}

func (*SqlColumn) Cond

func (col *SqlColumn) Cond(name string) string

func (*SqlColumn) CondV2

func (col *SqlColumn) CondV2(name string) string

func (*SqlColumn) SqlName

func (col *SqlColumn) SqlName() string

type SqlIndex

type SqlIndex struct {
	Name     string       // index name
	IdxName  string       // index name
	Columns  []*SqlColumn // index columns
	IsUnique bool         // unique index
}

func (*SqlIndex) Unique

func (idx *SqlIndex) Unique() string

type SqlTable

type SqlTable struct {
	tpl.GoObject
	SvcDB           string       // service package. not set outside
	Charset         string       // charset
	Collate         string       // collate
	Engine          string       // mysql engine
	DB              string       // generate mysql db name
	SqlTable        string       // generate mysql table name
	Name            string       // generate mysql operation name prefix
	Struct          string       // import struct name, need with package name. eg: pkg.struct
	InnerAllColumns []*SqlColumn // all columns
	AutoIncr        *SqlColumn   // auto increment column
	PrimaryKey      []*SqlColumn // primary key columns
	Columns         []*SqlColumn // normal columns
	Index           []*SqlIndex  // index columns
	GenEx           bool         // generate extra method(contain time info)
	GenUpdate       bool         // generate update method when have primary key
	GenUpsert       bool         // generate upsert method when have primary key
	CustomOptions   string       // custom mysql options
}

func (*SqlTable) AllColumns

func (tbl *SqlTable) AllColumns(ignoreAutoID bool) []*SqlColumn

func (*SqlTable) Clone

func (tbl *SqlTable) Clone() *SqlTable

func (*SqlTable) Placeholder

func (tbl *SqlTable) Placeholder(ignoreAutoID bool) string

Jump to

Keyboard shortcuts

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