user.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package models
  2. import (
  3. "database/sql"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/guregu/null"
  7. "gorm.io/gorm"
  8. )
  9. var (
  10. _ = time.Second
  11. _ = sql.LevelDefault
  12. _ = null.Bool{}
  13. _ = uuid.UUID{}
  14. )
  15. /*
  16. DB Table Details
  17. -------------------------------------
  18. CREATE TABLE `user` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `uid` varchar(256) COLLATE utf8mb4_bin NOT NULL COMMENT 'USER_HEX_20\n',
  21. `status` enum('stable','blocked','withdrawal') COLLATE utf8mb4_bin NOT NULL DEFAULT 'stable',
  22. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  23. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  24. `deleted_at` timestamp NULL DEFAULT NULL,
  25. PRIMARY KEY (`id`),
  26. UNIQUE KEY `id_UNIQUE` (`id`)
  27. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  28. JSON Sample
  29. -------------------------------------
  30. { "id": 62, "uid": "OvQpucxnuQSdfLYEmxZBaLkPI", "status": "vcBngwSFdGApxBWFhbCsTlDLp", "created_at": "2152-11-01T14:52:49.513042248+09:00", "updated_at": "2305-11-23T17:58:04.134789125+09:00", "deleted_at": "2029-12-30T11:06:58.578732473+09:00"}
  31. Comments
  32. -------------------------------------
  33. [ 0] column is set for unsigned
  34. */
  35. // User_ struct is a row record of the user table in the metarare database
  36. type User struct {
  37. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  38. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  39. //[ 1] uid varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  40. UID string `gorm:"column:uid;type:varchar;size:256;" json:"uid"` // USER_HEX_20\n
  41. //[ 2] status char(10) null: false primary: false isArray: false auto: false col: char len: 10 default: [stable]
  42. Status string `gorm:"column:status;type:char;size:10;default:stable;" json:"status"`
  43. //[ 3] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  44. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  45. //[ 4] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  46. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  47. //[ 5] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  48. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  49. UserProfile UserProfile
  50. UserWallet UserWallet
  51. }
  52. var userTableInfo = &TableInfo{
  53. Name: "user",
  54. Columns: []*ColumnInfo{
  55. &ColumnInfo{
  56. Index: 0,
  57. Name: "id",
  58. Comment: ``,
  59. Notes: `column is set for unsigned`,
  60. Nullable: false,
  61. DatabaseTypeName: "ubigint",
  62. DatabaseTypePretty: "ubigint",
  63. IsPrimaryKey: true,
  64. IsAutoIncrement: true,
  65. IsArray: false,
  66. ColumnType: "ubigint",
  67. ColumnLength: -1,
  68. GoFieldName: "ID",
  69. GoFieldType: "uint64",
  70. JSONFieldName: "id",
  71. ProtobufFieldName: "id",
  72. ProtobufType: "uint64",
  73. ProtobufPos: 1,
  74. },
  75. &ColumnInfo{
  76. Index: 1,
  77. Name: "uid",
  78. Comment: `USER_HEX_20\n`,
  79. Notes: ``,
  80. Nullable: false,
  81. DatabaseTypeName: "varchar",
  82. DatabaseTypePretty: "varchar(256)",
  83. IsPrimaryKey: false,
  84. IsAutoIncrement: false,
  85. IsArray: false,
  86. ColumnType: "varchar",
  87. ColumnLength: 256,
  88. GoFieldName: "UID",
  89. GoFieldType: "string",
  90. JSONFieldName: "uid",
  91. ProtobufFieldName: "uid",
  92. ProtobufType: "string",
  93. ProtobufPos: 2,
  94. },
  95. &ColumnInfo{
  96. Index: 2,
  97. Name: "status",
  98. Comment: ``,
  99. Notes: ``,
  100. Nullable: false,
  101. DatabaseTypeName: "char",
  102. DatabaseTypePretty: "char(10)",
  103. IsPrimaryKey: false,
  104. IsAutoIncrement: false,
  105. IsArray: false,
  106. ColumnType: "char",
  107. ColumnLength: 10,
  108. GoFieldName: "Status",
  109. GoFieldType: "string",
  110. JSONFieldName: "status",
  111. ProtobufFieldName: "status",
  112. ProtobufType: "string",
  113. ProtobufPos: 3,
  114. },
  115. &ColumnInfo{
  116. Index: 3,
  117. Name: "created_at",
  118. Comment: ``,
  119. Notes: ``,
  120. Nullable: false,
  121. DatabaseTypeName: "timestamp",
  122. DatabaseTypePretty: "timestamp",
  123. IsPrimaryKey: false,
  124. IsAutoIncrement: false,
  125. IsArray: false,
  126. ColumnType: "timestamp",
  127. ColumnLength: -1,
  128. GoFieldName: "CreatedAt",
  129. GoFieldType: "time.Time",
  130. JSONFieldName: "created_at",
  131. ProtobufFieldName: "created_at",
  132. ProtobufType: "uint64",
  133. ProtobufPos: 4,
  134. },
  135. &ColumnInfo{
  136. Index: 4,
  137. Name: "updated_at",
  138. Comment: ``,
  139. Notes: ``,
  140. Nullable: false,
  141. DatabaseTypeName: "timestamp",
  142. DatabaseTypePretty: "timestamp",
  143. IsPrimaryKey: false,
  144. IsAutoIncrement: false,
  145. IsArray: false,
  146. ColumnType: "timestamp",
  147. ColumnLength: -1,
  148. GoFieldName: "UpdatedAt",
  149. GoFieldType: "time.Time",
  150. JSONFieldName: "updated_at",
  151. ProtobufFieldName: "updated_at",
  152. ProtobufType: "uint64",
  153. ProtobufPos: 5,
  154. },
  155. &ColumnInfo{
  156. Index: 5,
  157. Name: "deleted_at",
  158. Comment: ``,
  159. Notes: ``,
  160. Nullable: true,
  161. DatabaseTypeName: "timestamp",
  162. DatabaseTypePretty: "timestamp",
  163. IsPrimaryKey: false,
  164. IsAutoIncrement: false,
  165. IsArray: false,
  166. ColumnType: "timestamp",
  167. ColumnLength: -1,
  168. GoFieldName: "DeletedAt",
  169. GoFieldType: "null.Time",
  170. JSONFieldName: "deleted_at",
  171. ProtobufFieldName: "deleted_at",
  172. ProtobufType: "uint64",
  173. ProtobufPos: 6,
  174. },
  175. },
  176. }
  177. // TableName sets the insert table name for this struct type
  178. func (u *User) TableName() string {
  179. return "user"
  180. }
  181. // BeforeSave invoked before saving, return an error if field is not populated.
  182. func (u *User) BeforeSave(*gorm.DB) error {
  183. return nil
  184. }
  185. // Prepare invoked before saving, can be used to populate fields etc.
  186. func (u *User) Prepare() {
  187. }
  188. // Validate invoked before performing action, return an error if field is not populated.
  189. func (u *User) Validate(action Action) error {
  190. return nil
  191. }
  192. // TableInfo return table meta data
  193. func (u *User) TableInfo() *TableInfo {
  194. return userTableInfo
  195. }