entity.template 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // ==========================================================================
  2. // 生成日期:${.table.CreateTime}
  3. // 生成人:${.table.FunctionAuthor}
  4. // ==========================================================================
  5. package ${.table.BusinessName}
  6. import (
  7. "database/sql"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/os/gtime"
  10. )
  11. // Entity is the golang structure for table ${.table.TableName}.
  12. type Entity struct {
  13. ${range $index, $column := .table.Columns}
  14. ${$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}
  15. }
  16. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  17. // the data and where attributes for empty values.
  18. // Deprecated.
  19. func (r *Entity) OmitEmpty() *arModel {
  20. return Model.Data(r).OmitEmpty()
  21. }
  22. // Inserts does "INSERT...INTO..." statement for inserting current object into table.
  23. // Deprecated.
  24. func (r *Entity) Insert() (result sql.Result, err error) {
  25. return Model.Data(r).Insert()
  26. }
  27. // InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
  28. // Deprecated.
  29. func (r *Entity) InsertIgnore() (result sql.Result, err error) {
  30. return Model.Data(r).InsertIgnore()
  31. }
  32. // Replace does "REPLACE...INTO..." statement for inserting current object into table.
  33. // If there's already another same record in the table (it checks using primary key or unique index),
  34. // it deletes it and insert this one.
  35. // Deprecated.
  36. func (r *Entity) Replace() (result sql.Result, err error) {
  37. return Model.Data(r).Replace()
  38. }
  39. // Save does "INSERT...INTO..." statement for inserting/updating current object into table.
  40. // It updates the record if there's already another same record in the table
  41. // (it checks using primary key or unique index).
  42. // Deprecated.
  43. func (r *Entity) Save() (result sql.Result, err error) {
  44. return Model.Data(r).Save()
  45. }
  46. // Update does "UPDATE...WHERE..." statement for updating current object from table.
  47. // It updates the record if there's already another same record in the table
  48. // (it checks using primary key or unique index).
  49. // Deprecated.
  50. func (r *Entity) Update() (result sql.Result, err error) {
  51. where, args, err := gdb.GetWhereConditionOfStruct(r)
  52. if err != nil {
  53. return nil, err
  54. }
  55. return Model.Data(r).Where(where, args).Update()
  56. }
  57. // Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
  58. // Deprecated.
  59. func (r *Entity) Delete() (result sql.Result, err error) {
  60. where, args, err := gdb.GetWhereConditionOfStruct(r)
  61. if err != nil {
  62. return nil, err
  63. }
  64. return Model.Where(where, args).Delete()
  65. }