sdblueprint

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package sdblueprint Blueprint 代码生成框架

Index

Constants

View Source
const (
	QueryForCreate  = QueryKind("CREATE")
	QueryForUpdate  = QueryKind("UPDATE")
	QueryForExec    = QueryKind("EXEC")
	QueryForRecord  = QueryKind("RECORD")
	QueryForRecords = QueryKind("RECORDS")
	QueryForScalar  = QueryKind("SCALAR")
)
View Source
const (
	IndexSimple = IndexKind("Simple")
	IndexPK     = IndexKind("PK")
	IndexFK     = IndexKind("FK")
	IndexUnique = IndexKind("UNIQUE")
)
View Source
const (
	IndexASC  = IndexOrder("ASC")
	IndexDESC = IndexOrder("DESC")
)

Variables

This section is empty.

Functions

func MustMapper

func MustMapper[PROTO any](asPrimitive bool) func(sdjson.Object) (PROTO, error)

func NewMapper

func NewMapper[PROTO any](asPrimitive bool) (func(sdjson.Object) (PROTO, error), error)

Types

type AttributeValue

type AttributeValue string

func (AttributeValue) AsBool

func (v AttributeValue) AsBool(def bool) bool

func (AttributeValue) AsFloat64

func (v AttributeValue) AsFloat64(def float64) float64

func (AttributeValue) AsInt

func (v AttributeValue) AsInt(def int) int

func (AttributeValue) AsInt64

func (v AttributeValue) AsInt64(def int64) int64

func (AttributeValue) AsSlice

func (v AttributeValue) AsSlice(sep string) []string

func (AttributeValue) AsStr

func (v AttributeValue) AsStr() string

func (AttributeValue) AsUint

func (v AttributeValue) AsUint(def uint) uint

func (AttributeValue) AsUint64

func (v AttributeValue) AsUint64(def uint64) uint64

func (AttributeValue) IfPresented

func (v AttributeValue) IfPresented(f func(v string))

type Attributes

type Attributes interface {
	Has(k string) bool
	Lookup(k string) (AttributeValue, bool)
	Get(k string) AttributeValue
	First(keys []string) AttributeValue
}

type Blueprint

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

func New

func New(session any) *Blueprint

func (*Blueprint) Add

func (bp *Blueprint) Add(protos ...any) *Blueprint

func (*Blueprint) CreateTableForMysql

func (bp *Blueprint) CreateTableForMysql(tx *gorm.DB, opts *CreateTableOptions) error

func (*Blueprint) Dump

func (bp *Blueprint) Dump(w io.Writer)

func (*Blueprint) FillDummyData

func (bp *Blueprint) FillDummyData(tx *gorm.DB, opts *FillDummyDataOptions) error

func (*Blueprint) Finalize

func (bp *Blueprint) Finalize() error

func (*Blueprint) Generate

func (bp *Blueprint) Generate(generators ...Generator) (*sdcodegen.Buffers, error)

func (*Blueprint) GenerateTo

func (bp *Blueprint) GenerateTo(buffs *sdcodegen.Buffers, generators ...Generator) error

func (*Blueprint) IsFinalized

func (bp *Blueprint) IsFinalized() bool

func (*Blueprint) MockDB

func (bp *Blueprint) MockDB(addr sdgorm.Address) error

func (*Blueprint) Module

func (bp *Blueprint) Module(id string) Module

func (*Blueprint) ModuleIds

func (bp *Blueprint) ModuleIds() []string

func (*Blueprint) Modules

func (bp *Blueprint) Modules() []Module

func (*Blueprint) MustFinalize

func (bp *Blueprint) MustFinalize() *Blueprint

func (*Blueprint) Queries

func (bp *Blueprint) Queries() []Query

func (*Blueprint) Query

func (bp *Blueprint) Query(id string) Query

func (*Blueprint) QueryIds

func (bp *Blueprint) QueryIds() []string

func (*Blueprint) RunCli

func (bp *Blueprint) RunCli()

func (*Blueprint) Sub

func (bp *Blueprint) Sub(groups ...string) *Blueprint

func (*Blueprint) Table

func (bp *Blueprint) Table(id string) Table

func (*Blueprint) TableIds

func (bp *Blueprint) TableIds() []string

func (*Blueprint) Tables

func (bp *Blueprint) Tables() []Table

func (*Blueprint) ToJsonObject

func (bp *Blueprint) ToJsonObject() sdjson.Object

type Column

type Column interface {
	Field
	Jsonable
	NameForTable
	NameForJson() string
	IsPrimaryKey() bool
	IsAutoIncrement() bool
	IsAllowNull() bool
	Default() any
}

type CreateTableOptions

type CreateTableOptions struct {
	TableIds  []string
	Drop      bool
	DisableFK bool
}

type DummyRecord

type DummyRecord map[string]any

func (DummyRecord) Get

func (record DummyRecord) Get(colId string) any

func (DummyRecord) Has

func (record DummyRecord) Has(colId string) bool

func (DummyRecord) Lookup

func (record DummyRecord) Lookup(colId string) (any, bool)

func (DummyRecord) ToDB

func (record DummyRecord) ToDB(t Table) DummyRecord

type Field

type Field interface {
	Id() string
	Comment() string
	Jsonable
	Type() reflect.Type
	Attributes
}

type FillDummyDataOptions

type FillDummyDataOptions struct {
	TableIds []string
}

type ForModule

type ForModule struct {
	Ids []string
}

func (ForModule) GenerateTo

func (g ForModule) GenerateTo(buffs *sdcodegen.Buffers, bp *Blueprint) error

type Generator

type Generator interface {
	GenerateTo(buffs *sdcodegen.Buffers, bp *Blueprint) error
}

type GormModel

type GormModel struct {
	// tables
	TableIds     []string
	FileForModel string

	// queries
	WithQuery        bool
	QueryIds         []string
	FileForQuery     string
	QueryWithContext bool

	// callback
	OnHeader func(w sdcodegen.Writer, g *GormModel, bp *Blueprint)
	OnModel  func(w sdcodegen.Writer, g *GormModel, bp *Blueprint, t Table)
	OnQuery  func(w sdcodegen.Writer, g *GormModel, bp *Blueprint, q Query)

	// options
	Package string
}

func (GormModel) GenerateTo

func (g GormModel) GenerateTo(buffs *sdcodegen.Buffers, bp *Blueprint) error

type Index

type Index interface {
	Name() string
	Comment() string
	Jsonable
	Kind() IndexKind
	Columns() []string
	ReferenceTable() string
	ReferenceColumns() []string
	Order() IndexOrder
}

type IndexKind

type IndexKind string

type IndexOrder

type IndexOrder string

type Jsonable

type Jsonable interface {
	ToJsonObject() sdjson.Object
}

type MarkAsForeignKey

type MarkAsForeignKey int

type MarkAsGenerateGormModel

type MarkAsGenerateGormModel int

type MarkAsGenerateMysqlDDL

type MarkAsGenerateMysqlDDL int

type MarkAsGenerateSkeleton

type MarkAsGenerateSkeleton int

type MarkAsInlineQuery

type MarkAsInlineQuery int

type MarkAsModule

type MarkAsModule int

type MarkAsPrimaryKey

type MarkAsPrimaryKey int

type MarkAsQuery

type MarkAsQuery int

type MarkAsSimpleIndex

type MarkAsSimpleIndex int

type MarkAsTable

type MarkAsTable int

type MarkAsUniqueIndex

type MarkAsUniqueIndex int

type Method

type Method interface {
	Id() string
	Code() MethodCode
}

type MethodCode

type MethodCode string

type Module

type Module interface {
	Id() string
	Comment() string
	Tasks() []any
	Jsonable
}

type ModuleTaskGenerateGormModel

type ModuleTaskGenerateGormModel struct {
	Dirname          string   `json:"dir,omitempty"`
	Groups           []string `json:"groups,omitempty"`
	QueryWithContext bool     `json:"query_with_context,omitempty"`
}

func (*ModuleTaskGenerateGormModel) ToJsonObject

func (t *ModuleTaskGenerateGormModel) ToJsonObject() sdjson.Object

type ModuleTaskGenerateMysqlDDL

type ModuleTaskGenerateMysqlDDL struct {
	Dirname string   `json:"dir,omitempty"`
	Groups  []string `json:"groups,omitempty"`
}

func (*ModuleTaskGenerateMysqlDDL) ToJsonObject

func (t *ModuleTaskGenerateMysqlDDL) ToJsonObject() sdjson.Object

type ModuleTaskGenerateSkeleton

type ModuleTaskGenerateSkeleton struct {
	Template string `json:"template"`
	Dirname  string `json:"dir"`
}

func (*ModuleTaskGenerateSkeleton) ToJsonObject

func (t *ModuleTaskGenerateSkeleton) ToJsonObject() sdjson.Object

type MysqlDDL

type MysqlDDL struct {
	TableIds      []string
	FileForCreate string
	FileForDrop   string

	// callbacks
	OnHeader func(w sdcodegen.Writer, g *MysqlDDL, bp *Blueprint)
	OnCreate func(w sdcodegen.Writer, g *MysqlDDL, bp *Blueprint, t Table)
	OnDrop   func(w sdcodegen.Writer, g *MysqlDDL, bp *Blueprint, t Table)

	// options
	Charset       string
	Collation     string
	Engine        string
	DisableFK     bool
	WithDrop      bool
	WithoutCreate bool
}

func (MysqlDDL) GenerateTo

func (g MysqlDDL) GenerateTo(buffs *sdcodegen.Buffers, bp *Blueprint) error

type NameForTable

type NameForTable interface {
	NameForGo() string
	NameForDB() string
}

type Query

type Query interface {
	Id() string
	Comment() string
	Group() string
	Jsonable
	Attributes
	Kind() QueryKind
	SQL() string
	Table() string
	Params() []QueryParam
	ParamByName(name string) QueryParam
	ParamByIndex(index int) QueryParam
	Result() QueryResult
	ReturnRowAffected() bool
}

type QueryKind

type QueryKind string

type QueryParam

type QueryParam interface {
	Name() string
	Type() string
	Table() string
	IsList() bool
	Jsonable
}

type QueryResult

type QueryResult interface {
	Type() string
	Table() string
	IsList() bool
	Jsonable
}

type Table

type Table interface {
	Id() string
	Comment() string
	Group() string
	Attributes
	Jsonable
	DummyData() []DummyRecord
	NameForTable
	Columns() []Column
	Column(id string) Column
	Members() []Field
	Member(id string) Field
	Indexes() []Index
	PrimaryKey() Index
	Methods() []Method
	Method(id string) Method
}

Jump to

Keyboard shortcuts

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