mirror of
https://github.com/tiger1103/gfast.git
synced 2026-10-07 22:59:56 +00:00
77 lines
2.7 KiB
Plaintext
77 lines
2.7 KiB
Plaintext
// ==========================================================================
|
|
// 生成日期:${.table.CreateTime}
|
|
// 生成人:${.table.FunctionAuthor}
|
|
// ==========================================================================
|
|
|
|
package ${.table.BusinessName}
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/gogf/gf/database/gdb"
|
|
"github.com/gogf/gf/os/gtime"
|
|
)
|
|
|
|
// Entity is the golang structure for table ${.table.TableName}.
|
|
type Entity struct {
|
|
${range $index, $column := .table.Columns}
|
|
${$column.GoField} ${if eq $column.GoType "Time"}*gtime.Time${else}${$column.GoType}${end} `orm:"${$column.ColumnName}${if eq $column.IsPk "1"},primary${end}" json:"${$column.ColumnName}"` // ${$column.ColumnComment} ${end}
|
|
}
|
|
|
|
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
|
// the data and where attributes for empty values.
|
|
// Deprecated.
|
|
func (r *Entity) OmitEmpty() *arModel {
|
|
return Model.Data(r).OmitEmpty()
|
|
}
|
|
|
|
// Inserts does "INSERT...INTO..." statement for inserting current object into table.
|
|
// Deprecated.
|
|
func (r *Entity) Insert() (result sql.Result, err error) {
|
|
return Model.Data(r).Insert()
|
|
}
|
|
|
|
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
|
// Deprecated.
|
|
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
|
return Model.Data(r).InsertIgnore()
|
|
}
|
|
|
|
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
|
// If there's already another same record in the table (it checks using primary key or unique index),
|
|
// it deletes it and insert this one.
|
|
// Deprecated.
|
|
func (r *Entity) Replace() (result sql.Result, err error) {
|
|
return Model.Data(r).Replace()
|
|
}
|
|
|
|
// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
|
|
// It updates the record if there's already another same record in the table
|
|
// (it checks using primary key or unique index).
|
|
// Deprecated.
|
|
func (r *Entity) Save() (result sql.Result, err error) {
|
|
return Model.Data(r).Save()
|
|
}
|
|
|
|
// Update does "UPDATE...WHERE..." statement for updating current object from table.
|
|
// It updates the record if there's already another same record in the table
|
|
// (it checks using primary key or unique index).
|
|
// Deprecated.
|
|
func (r *Entity) Update() (result sql.Result, err error) {
|
|
where, args, err := gdb.GetWhereConditionOfStruct(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return Model.Data(r).Where(where, args).Update()
|
|
}
|
|
|
|
// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
|
|
// Deprecated.
|
|
func (r *Entity) Delete() (result sql.Result, err error) {
|
|
where, args, err := gdb.GetWhereConditionOfStruct(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return Model.Where(where, args).Delete()
|
|
}
|