Documentation ¶
Index ¶
- Constants
- Variables
- func BigSerialPrimaryKeyModifier(tb *gosql.Table)
- func BigSerialSoftTable(name string) *gosql.Table
- func BigSerialTable(name string) *gosql.Table
- func CreateDictionaryTable(q godb.Queryer) error
- func CreateFile(name, path string) (*os.File, string, error)
- func CreateModelFile(schema string, table string, path string) (*os.File, string, error)
- func Delete(q godb.Queryer, model IModel) porterr.IError
- func Do(q godb.Queryer, isql gosql.ISQL) (e porterr.IError)
- func GenerateDictionaryMapping(path string, q godb.Queryer) error
- func GetColumn(model IModel, field any) string
- func GetColumns(model IModel, field ...any) []string
- func GetDeleteSQL(model IModel) (iSQL gosql.ISQL)
- func GetInsertSQL(model IModel, fields ...any) gosql.ISQL
- func GetLoadSQL(model IModel) gosql.ISQL
- func GetSaveSQL(model IModel) gosql.ISQL
- func GetUpdateSQL(model IModel, fields ...any) gosql.ISQL
- func GetValues(model IModel, columns ...string) (values []any)
- func Load(q godb.Queryer, model IModel) porterr.IError
- func Save(q godb.Queryer, model IModel) porterr.IError
- func SerialPrimaryKeyModifier(tb *gosql.Table)
- func SerialSoftTable(name string) *gosql.Table
- func SerialTable(name string) *gosql.Table
- func SoftModifier(tb *gosql.Table)
- func TimestampModifier(tb *gosql.Table)
- type CRUDGenerator
- func (c CRUDGenerator) AddToGlobalRoute(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) Generate(q godb.Queryer, schema, table, version string, num CrudNumber) (err error)
- func (c *CRUDGenerator) GetColumns(q godb.Queryer, schema, table string) (*Columns, error)
- func (c *CRUDGenerator) GetPackage(path string) string
- func (c CRUDGenerator) MakeAPIClient(logger gocli.Logger, schema, table, version string, num CrudNumber) (err error)
- func (c CRUDGenerator) MakeAPICreate(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) MakeAPIDelete(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) MakeAPIRead(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) MakeAPIRoute(logger gocli.Logger, schema, table, version string, num CrudNumber) (err error)
- func (c CRUDGenerator) MakeAPISearch(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) MakeAPIUpdate(logger gocli.Logger, schema, table, version string) (err error)
- func (c CRUDGenerator) MakeCoreCrud(logger gocli.Logger, schema, table string) (err error)
- func (c CRUDGenerator) MakeSearchForm(logger gocli.Logger, schema, table string) (err error)
- func (c CRUDGenerator) UpdateAPIClient(logger gocli.Logger, path string, content []byte, schema, table string, ...) (err error)
- type Collection
- func (c *Collection[T]) AddCountOver()
- func (c *Collection[T]) AddItem(item ...*T)
- func (c *Collection[T]) Clear()
- func (c *Collection[T]) Delete(q godb.Queryer) (e porterr.IError)
- func (c *Collection[T]) Filter(callback func(*T) bool)
- func (c *Collection[T]) First() *T
- func (c *Collection[T]) Item() *T
- func (c *Collection[T]) Items() []*T
- func (c *Collection[T]) Last() *T
- func (c *Collection[T]) Load(q godb.Queryer) porterr.IError
- func (c *Collection[T]) Map(callback func(*T))
- func (c *Collection[T]) RemoveCountOver()
- func (c *Collection[T]) Save(q godb.Queryer) (e porterr.IError)
- type Column
- type Columns
- type CrudNumber
- type DictionaryItems
- type DictionaryModel
- type IModel
- type MetaModel
- type ModelFiledTag
- type ModelFiledTagList
- type PossibleCrudMethods
- type SystemColumns
Constants ¶
const (
// DefaultSchema default database schema
DefaultSchema = "public"
)
Variables ¶
var ApiClientTemplate string
var ApiCreateTemplate string
var ApiDeleteTemplate string
var ApiReadTemplate string
var ApiRouteTemplate string
var ApiSearchTemplate string
var ApiUpdateTemplate string
var CrudTemplate string
var DefaultDictionaryTemplate string
var DefaultModelTemplate string
var DefaultSystemColumns = SystemColumns{Created: "created_at", Updated: "updated_at"}
var DefaultSystemColumnsSoft = SystemColumns{Created: "created_at", Updated: "updated_at", Deleted: "deleted_at"}
var SearchFormTemplate string
Functions ¶
func BigSerialPrimaryKeyModifier ¶ added in v0.4.5
BigSerialPrimaryKeyModifier create id bigserial primary key column
func BigSerialSoftTable ¶ added in v0.4.5
BigSerialSoftTable init table for soft control model
func BigSerialTable ¶ added in v0.4.5
BigSerialTable init table for control model
func CreateDictionaryTable ¶ added in v0.2.0
func CreateDictionaryTable(q godb.Queryer) error
Create Table
func CreateFile ¶ added in v0.3.0
CreateFile Create File
func CreateModelFile ¶ added in v0.2.0
CreateModelFile Create file in os
func GenerateDictionaryMapping ¶ added in v0.2.0
Create or update dictionary mapping
func GetColumns ¶
GetColumns model columns by fields
func GetDeleteSQL ¶
GetDeleteSQL model delete query model - target model
func GetInsertSQL ¶
GetInsertSQL model insert query
func GetLoadSQL ¶
GetLoadSQL return sql query fot load model
func GetSaveSQL ¶
GetSaveSQL prepare save query it can be insert or update or upsert some popular scenario was implemented. not all
func GetUpdateSQL ¶
GetUpdateSQL model update query model - target model fields - list of fields that you want to update
func SerialPrimaryKeyModifier ¶ added in v0.4.5
SerialPrimaryKeyModifier create id serial primary key column
func SerialSoftTable ¶ added in v0.4.5
SerialSoftTable init table for soft control model
func SerialTable ¶ added in v0.4.5
SerialTable init table for control model
func SoftModifier ¶ added in v0.4.5
SoftModifier create soft deleted_at column
func TimestampModifier ¶ added in v0.4.5
TimestampModifier create timestamps
Types ¶
type CRUDGenerator ¶ added in v0.3.0
type CRUDGenerator struct { // Path for crud folder CRUDPath string // Path for client folder ClientPath string // Path for api folder APIPath string // Path for project ProjectPath string // contains filtered or unexported fields }
CRUDGenerator struct for crud generation
func NewCRUDGenerator ¶ added in v0.3.0
func NewCRUDGenerator(CRUDPath, ClientPath, APIPath, ProjectPath string) *CRUDGenerator
NewCRUDGenerator init crud generator
func (CRUDGenerator) AddToGlobalRoute ¶ added in v0.4.0
func (c CRUDGenerator) AddToGlobalRoute(logger gocli.Logger, schema, table, version string) (err error)
AddToGlobalRoute add global route for target entity
func (CRUDGenerator) Generate ¶ added in v0.3.0
func (c CRUDGenerator) Generate(q godb.Queryer, schema, table, version string, num CrudNumber) (err error)
Generate generate crud, client, api q - database connection schema - db schema (table namespace) table - name of table num - crud scenario (1 - create, 2 - read, 4 - update, 8 - delete, 16 - list)
func (*CRUDGenerator) GetColumns ¶ added in v0.4.2
func (c *CRUDGenerator) GetColumns(q godb.Queryer, schema, table string) (*Columns, error)
GetColumns lazy load for columns
func (*CRUDGenerator) GetPackage ¶ added in v0.4.2
func (c *CRUDGenerator) GetPackage(path string) string
GetPackage get package name
func (CRUDGenerator) MakeAPIClient ¶ added in v0.3.9
func (c CRUDGenerator) MakeAPIClient(logger gocli.Logger, schema, table, version string, num CrudNumber) (err error)
MakeAPIClient generate qpi search
func (CRUDGenerator) MakeAPICreate ¶ added in v0.3.0
func (c CRUDGenerator) MakeAPICreate(logger gocli.Logger, schema, table, version string) (err error)
MakeAPICreate generate qpi create
func (CRUDGenerator) MakeAPIDelete ¶ added in v0.3.0
func (c CRUDGenerator) MakeAPIDelete(logger gocli.Logger, schema, table, version string) (err error)
MakeAPIDelete generate qpi delete
func (CRUDGenerator) MakeAPIRead ¶ added in v0.3.0
func (c CRUDGenerator) MakeAPIRead(logger gocli.Logger, schema, table, version string) (err error)
MakeAPIRead generate qpi read
func (CRUDGenerator) MakeAPIRoute ¶ added in v0.3.6
func (c CRUDGenerator) MakeAPIRoute(logger gocli.Logger, schema, table, version string, num CrudNumber) (err error)
MakeAPIRoute generate qpi route
func (CRUDGenerator) MakeAPISearch ¶ added in v0.3.4
func (c CRUDGenerator) MakeAPISearch(logger gocli.Logger, schema, table, version string) (err error)
MakeAPISearch generate qpi search
func (CRUDGenerator) MakeAPIUpdate ¶ added in v0.3.0
func (c CRUDGenerator) MakeAPIUpdate(logger gocli.Logger, schema, table, version string) (err error)
MakeAPIUpdate generate api update
func (CRUDGenerator) MakeCoreCrud ¶ added in v0.3.0
func (c CRUDGenerator) MakeCoreCrud(logger gocli.Logger, schema, table string) (err error)
MakeCoreCrud generate core file
func (CRUDGenerator) MakeSearchForm ¶ added in v0.3.4
func (c CRUDGenerator) MakeSearchForm(logger gocli.Logger, schema, table string) (err error)
MakeSearchForm generate search form
func (CRUDGenerator) UpdateAPIClient ¶ added in v0.3.9
func (c CRUDGenerator) UpdateAPIClient(logger gocli.Logger, path string, content []byte, schema, table string, num CrudNumber) (err error)
UpdateAPIClient update client api callbacks
type Collection ¶
type Collection[T any] struct { // Iterator *gohelp.Iterator // Query builder *gosql.Select // Count CountOver int // contains filtered or unexported fields }
Collection struct contain items and collection common methods
func NewCollection ¶
func NewCollection[T any]() *Collection[T]
NewCollection Create new model collection
func (*Collection[T]) AddCountOver ¶
func (c *Collection[T]) AddCountOver()
AddCountOver add count column to SQL
func (*Collection[T]) AddItem ¶
func (c *Collection[T]) AddItem(item ...*T)
AddItem Add item to collection
func (*Collection[T]) Delete ¶
func (c *Collection[T]) Delete(q godb.Queryer) (e porterr.IError)
Delete delete items in collection
func (*Collection[T]) Filter ¶
func (c *Collection[T]) Filter(callback func(*T) bool)
Filter collection
func (*Collection[T]) Load ¶
func (c *Collection[T]) Load(q godb.Queryer) porterr.IError
Load collection
func (*Collection[T]) RemoveCountOver ¶
func (c *Collection[T]) RemoveCountOver()
RemoveCountOver remove count column from SQL
func (*Collection[T]) Save ¶
func (c *Collection[T]) Save(q godb.Queryer) (e porterr.IError)
Save Create or Update collection items
type Column ¶ added in v0.2.0
type Column struct { Name string // DB column name ModelName string // Model name Default *string // DB default value IsNullable bool // DB is nullable IsByteArray bool // Do not need type pointer for []byte DataType string // DB column type ModelType string // Model type Schema string // DB Schema Table string // DB table Sequence *string // DB sequence ForeignSchema *string // DB foreign schema name ForeignTable *string // DB foreign table name ForeignColumnName *string // DB foreign column name ForeignIsSoft bool // DB foreign table is soft Description *string // DB column description IsPrimaryKey bool // DB is primary key Tags string // Model Tags name Import string // Model Import custom lib IsArray bool // Array column IsCreated bool // Is created at column IsUpdated bool // Is updated at column IsDeleted bool // Is deleted at column HasUniqueIndex bool // If column is a part of unique index UniqueIndexName *string // Unique index name TableDescription *string // Table description DefaultTypeValue *string // Default value for type }
Column information
func (Column) GetModelFieldTag ¶ added in v0.2.0
func (c Column) GetModelFieldTag() (field ModelFiledTag)
GetModelFieldTag Prepare ModelFiledTag by Column
func (Column) PrepareValidTag ¶ added in v0.2.0
func (c Column) PrepareValidTag(dictionary DictionaryItems) string
PrepareValidTag if dictionary item
type Columns ¶ added in v0.2.0
type Columns []Column
Array of columns
func GetTableColumns ¶ added in v0.2.0
func GetTableColumns(dbo godb.Queryer, schema string, table string, sysCols SystemColumns, dictionary DictionaryItems) (*Columns, error)
Get table columns from db
func MakeModel ¶ added in v0.2.0
func MakeModel(db godb.Queryer, dir string, schema string, table string, templatePath string, systemColumns SystemColumns) (modelName string, columns *Columns, err error)
MakeModel Create model
func (Columns) GetTableDescription ¶ added in v0.2.0
GetTableDescription get table comment
type CrudNumber ¶ added in v0.3.9
type CrudNumber uint8
CrudNumber calculate for type of crud method
func (CrudNumber) GetPossibleMethods ¶ added in v0.3.9
func (n CrudNumber) GetPossibleMethods() PossibleCrudMethods
GetPossibleMethods Calculate possible methods
func (CrudNumber) GetPossibleMethodsArray ¶ added in v0.3.9
func (n CrudNumber) GetPossibleMethodsArray() []string
GetPossibleMethodsArray return list of crud method based on num
type DictionaryItems ¶ added in v0.2.0
type DictionaryItems []*DictionaryModel
DictionaryItems dictionary collection items
func (DictionaryItems) GetTypeEnum ¶ added in v0.2.0
func (i DictionaryItems) GetTypeEnum(dictionaryType string) string
GetTypeEnum get enum type for validation
func (DictionaryItems) HasType ¶ added in v0.2.0
func (i DictionaryItems) HasType(dictionaryType string) bool
HasType check if type in collection
func (DictionaryItems) IsDictionaryColumn ¶ added in v0.2.0
func (i DictionaryItems) IsDictionaryColumn(name string) (string, bool)
IsDictionaryColumn check if column name has dictionary reference
type DictionaryModel ¶ added in v0.2.0
type DictionaryModel struct { // Dictionary row identifier Id *int32 `json:"id"` // Dictionary row type Type *string `json:"type"` // Dictionary row code Code *string `json:"code"` // Dictionary row value label Label *string `json:"label"` // Dictionary row created time CreatedAt *time.Time `json:"createdAt"` // Dictionary row updated time UpdatedAt *time.Time `json:"updatedAt"` // Dictionary row deleted time DeletedAt *time.Time `json:"deletedAt"` }
func (*DictionaryModel) Columns ¶ added in v0.2.0
func (m *DictionaryModel) Columns() []string
Model columns
func (*DictionaryModel) Table ¶ added in v0.2.0
func (m *DictionaryModel) Table() string
Model columns
func (*DictionaryModel) Values ¶ added in v0.2.0
func (m *DictionaryModel) Values() (values []interface{})
Model values
type IModel ¶
type IModel interface { // Table Returns table name Table() string // Columns returns all columns Columns() []string // Values returns all model values Values() []any }
IModel DB model interface
type MetaModel ¶
type MetaModel struct { // Table name TableName string // Fields Fields ModelFiledTagList }
MetaModel Meta model contain full information about model and fields
func PrepareMetaModel ¶
PrepareMetaModel Prepare Meta Model definition
type ModelFiledTag ¶
type ModelFiledTag struct { // DB column name Column string `tag:"col"` // Foreign key definition ForeignKey string `tag:"frk"` // Has sequence IsSequence bool `tag:"seq"` // Is primary key IsPrimaryKey bool `tag:"prk"` // Is not null IsRequired bool `tag:"req"` // Is unique IsUnique bool `tag:"unq"` // Is created at column IsCreatedAt bool `tag:"cat"` // Is updated at column IsUpdatedAt bool `tag:"uat"` // Is deleted at column IsDeletedAt bool `tag:"dat"` // Is ignored column IsIgnored bool `tag:"ign"` // Is array value IsArray bool `tag:"arr"` // Interface to value Value any }
ModelFiledTag All possible model field tag properties tag must have 3 symbol length
func ParseModelFiledTag ¶
func ParseModelFiledTag(tag string) (field ModelFiledTag)
ParseModelFiledTag parse validation tag for rule and arguments Example db:"col~created_at;seq;sys;prk;frk~master.table(id,name);req;unq'"
type ModelFiledTagList ¶
type ModelFiledTagList []ModelFiledTag
ModelFiledTagList list of ModelFiledTag
func (ModelFiledTagList) HasPrimary ¶
func (l ModelFiledTagList) HasPrimary() bool
HasPrimary check if primary key exists
func (ModelFiledTagList) HasUnique ¶
func (l ModelFiledTagList) HasUnique() bool
HasUnique check if unique key exists
func (ModelFiledTagList) IsSoft ¶
func (l ModelFiledTagList) IsSoft() bool
IsSoft check if model possible to soft delete
type PossibleCrudMethods ¶ added in v0.3.9
type PossibleCrudMethods struct { // Create method Create bool // Read method Read bool // Update method Update bool // Delete method Delete bool // Search method Search bool }
PossibleCrudMethods All possible crud methods