Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Create action when record is created Create = Action(0) // RetrieveOne action when a record is retrieved from db RetrieveOne = Action(1) // RetrieveMany action when record(s) are retrieved from db RetrieveMany = Action(2) // Update action when record is updated in db Update = Action(3) // Delete action when record is deleted in db Delete = Action(4) // FetchDDL action when fetching ddl info from db FetchDDL = Action(5) )
Functions ¶
This section is empty.
Types ¶
type ColumnInfo ¶
type ColumnInfo struct { Index int `json:"index"` GoFieldName string `json:"go_field_name"` GoFieldType string `json:"go_field_type"` JSONFieldName string `json:"json_field_name"` ProtobufFieldName string `json:"protobuf_field_name"` ProtobufType string `json:"protobuf_field_type"` ProtobufPos int `json:"protobuf_field_pos"` Comment string `json:"comment"` Notes string `json:"notes"` Name string `json:"name"` Nullable bool `json:"is_nullable"` DatabaseTypeName string `json:"database_type_name"` DatabaseTypePretty string `json:"database_type_pretty"` IsPrimaryKey bool `json:"is_primary_key"` IsAutoIncrement bool `json:"is_auto_increment"` IsArray bool `json:"is_array"` ColumnType string `json:"column_type"` ColumnLength int64 `json:"column_length"` DefaultValue string `json:"default_value"` }
ColumnInfo describes a column in the database table
type MigrationSchema ¶
type MigrationSchema struct { //[ 0] version INT8 null: false primary: true isArray: false auto: false col: INT8 len: -1 default: [] Version int64 `gorm:"primary_key;column:version;type:INT8;" db:"version"` //[ 1] dirty BOOL null: false primary: false isArray: false auto: false col: BOOL len: -1 default: [] Dirty bool `gorm:"column:dirty;type:BOOL;" db:"dirty"` }
MigrationSchema struct is a row record of the migration_schema table in the go_template_test database
func (*MigrationSchema) BeforeSave ¶
func (m *MigrationSchema) BeforeSave(tx *gorm.DB) error
BeforeSave invoked before saving, return an error if field is not populated.
func (*MigrationSchema) Prepare ¶
func (m *MigrationSchema) Prepare()
Prepare invoked before saving, can be used to populate fields etc.
func (*MigrationSchema) TableInfo ¶
func (m *MigrationSchema) TableInfo() *TableInfo
TableInfo return table meta data
func (*MigrationSchema) TableName ¶
func (m *MigrationSchema) TableName() string
TableName sets the insert table name for this struct type
func (*MigrationSchema) Validate ¶
func (m *MigrationSchema) Validate(action Action) error
Validate invoked before performing action, return an error if field is not populated.
type Model ¶
type Model interface { TableName() string BeforeSave() error Prepare() Validate(action Action) error TableInfo() *TableInfo }
Model interface methods for database structs generated
type Sample ¶
type Sample struct { //[ 0] uuid UUID null: false primary: true isArray: false auto: true col: UUID len: -1 default: [md5(((random())] UUID string `gorm:"primary_key;AUTO_INCREMENT;column:uuid;type:UUID;" db:"uuid"` //[ 1] data TEXT null: true primary: false isArray: false auto: false col: TEXT len: -1 default: [] Data null.String `gorm:"column:data;type:TEXT;" db:"data"` //[ 2] create_time TIMESTAMP null: true primary: false isArray: false auto: false col: TIMESTAMP len: -1 default: [now()] CreateTime null.Time `gorm:"column:create_time;type:TIMESTAMP;" db:"create_time"` //[ 3] create_by VARCHAR(20) null: true primary: false isArray: false auto: false col: VARCHAR len: 20 default: [] CreateBy null.String `gorm:"column:create_by;type:VARCHAR;size:20;" db:"create_by"` //[ 4] update_time TIMESTAMP null: true primary: false isArray: false auto: false col: TIMESTAMP len: -1 default: [] UpdateTime null.Time `gorm:"column:update_time;type:TIMESTAMP;" db:"update_time"` //[ 5] update_by VARCHAR(20) null: true primary: false isArray: false auto: false col: VARCHAR len: 20 default: [] UpdateBy null.String `gorm:"column:update_by;type:VARCHAR;size:20;" db:"update_by"` }
Sample struct is a row record of the sample table in the go_template_test database
func (*Sample) BeforeSave ¶
BeforeSave invoked before saving, return an error if field is not populated.
func (*Sample) Prepare ¶
func (s *Sample) Prepare()
Prepare invoked before saving, can be used to populate fields etc.
type TableInfo ¶
type TableInfo struct { Name string `json:"name"` Columns []*ColumnInfo `json:"columns"` }
TableInfo describes a table in the database
func GetTableInfo ¶
GetTableInfo retrieve TableInfo for a table