tpl

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DaoHeader = `package %s

import (
	"context"
	"time"
	"errors"
	
	"gorm.io/gorm"
	"%s/%s"
)
`
)
View Source
const (
	DaoIdlHeader = `package %s

import (
	"context"

	"%s/%s"
)
`
)
View Source
const (
	ModelHeader = `// Code generated by gormgen. DO NOT EDIT.
package %s

import (
	"time"
)
`
)
View Source
const (
	ModelOptHeader = `// Code generated by gormgen. DO NOT EDIT.
package %s

import (
	"gorm.io/gorm"
)
`
)

Variables

View Source
var (
	TmplDao = `` /* 319-byte string literal not displayed */

	TmplInsert = `` /* 1173-byte string literal not displayed */

	TmplSave = `` /* 545-byte string literal not displayed */

	TmplFindOne = `` /* 455-byte string literal not displayed */

	TmplFindList = `` /* 640-byte string literal not displayed */

	TmplCount = `` /* 440-byte string literal not displayed */

	TmplUpdate = `` /* 863-byte string literal not displayed */

	TmplDelete = `` /* 1037-byte string literal not displayed */

	DaoTemplate = TmplDao + TmplInsert + TmplSave + TmplFindOne + TmplFindList + TmplCount + TmplUpdate + TmplDelete
)
View Source
var DBTableInfo []TableInfo
View Source
var (
	DaoIdlTemplate = `` /* 968-byte string literal not displayed */

)
View Source
var (
	ModelOptTemplate = `` /* 2095-byte string literal not displayed */

)
View Source
var (
	ModelTemplate = `
// {{.StructName.UpperS}} table model
type {{.StructName.UpperS}} struct { {{range $item := .Columns}}
	{{$item.FieldName}}	{{$item.FieldType}}	` + "`" + `gorm:"column:{{$item.GormName}}{{$item.PrimaryKey}}" json:"{{$item.JsonName}}"` + "`" + ` // {{$item.Comment}} {{end}}
}

func ({{.StructName.LowerS}} *{{.StructName.UpperS}}) TableName() string {
	return {{.StructName.UpperS}}TableName
}

`
)

Functions

func GetAllTables

func GetAllTables(db *sql.DB) ([]string, error)

func GetTableMatcher

func GetTableMatcher() map[string]TableInfo

Types

type ArgInfo

type ArgInfo struct {
	Name string
	Type string
}

type FieldLevel

type FieldLevel struct {
	FieldName  string
	FieldType  string
	PrimaryKey string
	// gorm tag for field
	GormName string
	// json tag for field
	JsonName string
	// comment from create table sql
	Comment string
}

type StructLevel

type StructLevel struct {
	// table -> struct
	TableName string

	StructName StructName

	// table column -> struct field
	Columns []FieldLevel

	// create time
	TableCreateTime string
	FieldCreateTime string

	// update time
	TableUpdateTime string
	FieldUpdateTime string

	// soft delete
	TableSoftDeleteKey   string
	TableSoftDeleteValue int
	FieldSoftDeleteKey   string
}

func Generate

func Generate(db *sql.DB, table string, matchInfo TableInfo) (StructLevel, error)

type StructName

type StructName struct {
	// first letter upper/lower
	UpperS, UpperP string // Order,Orders
	LowerS, LowerP string // order,orders
}

复数Plural 单数Singular

type TableInfo

type TableInfo struct {
	Name            string `yaml:"name"`
	GoStruct        string `yaml:"goStruct"`
	CreateTime      string `yaml:"createTime"`
	UpdateTime      string `yaml:"updateTime"`
	SoftDeleteKey   string `yaml:"softDeleteKey"`
	SoftDeleteValue int    `yaml:"softDeleteValue"`
}

Jump to

Keyboard shortcuts

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