traits.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 `traits` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `token_id` bigint(20) unsigned NOT NULL,
  21. `key` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  22. `value` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  23. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  24. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  25. `deleted_at` timestamp NULL DEFAULT NULL,
  26. PRIMARY KEY (`id`),
  27. KEY `fk_traits_token1_idx` (`token_id`),
  28. CONSTRAINT `fk_traits_token1` FOREIGN KEY (`token_id`) REFERENCES `token` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  29. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  30. JSON Sample
  31. -------------------------------------
  32. { "id": 59, "token_id": 17, "key": "skWGwSxYbGHJTWdhEnmXoTsgE", "value": "wWjTrYWQdKhMSLxkuTLfdkYZi", "created_at": "2095-10-29T23:28:44.604800689+09:00", "updated_at": "2215-12-03T21:21:47.343700838+09:00", "deleted_at": "2047-08-06T18:04:25.485684032+09:00"}
  33. Comments
  34. -------------------------------------
  35. [ 0] column is set for unsigned
  36. [ 1] column is set for unsigned
  37. */
  38. // Traits struct is a row record of the traits table in the metarare database
  39. type Traits struct {
  40. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  41. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  42. //[ 1] token_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  43. TokenID uint64 `gorm:"column:token_id;type:ubigint;" json:"token_id"`
  44. //[ 2] key varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  45. Key string `gorm:"column:key;type:varchar;size:256;" json:"key"`
  46. //[ 3] value varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  47. Value string `gorm:"column:value;type:varchar;size:256;" json:"value"`
  48. //[ 4] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  49. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  50. //[ 5] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  51. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  52. //[ 6] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  53. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  54. }
  55. var traitsTableInfo = &TableInfo{
  56. Name: "traits",
  57. Columns: []*ColumnInfo{
  58. &ColumnInfo{
  59. Index: 0,
  60. Name: "id",
  61. Comment: ``,
  62. Notes: `column is set for unsigned`,
  63. Nullable: false,
  64. DatabaseTypeName: "ubigint",
  65. DatabaseTypePretty: "ubigint",
  66. IsPrimaryKey: true,
  67. IsAutoIncrement: true,
  68. IsArray: false,
  69. ColumnType: "ubigint",
  70. ColumnLength: -1,
  71. GoFieldName: "ID",
  72. GoFieldType: "uint64",
  73. JSONFieldName: "id",
  74. ProtobufFieldName: "id",
  75. ProtobufType: "uint64",
  76. ProtobufPos: 1,
  77. },
  78. &ColumnInfo{
  79. Index: 1,
  80. Name: "token_id",
  81. Comment: ``,
  82. Notes: `column is set for unsigned`,
  83. Nullable: false,
  84. DatabaseTypeName: "ubigint",
  85. DatabaseTypePretty: "ubigint",
  86. IsPrimaryKey: false,
  87. IsAutoIncrement: false,
  88. IsArray: false,
  89. ColumnType: "ubigint",
  90. ColumnLength: -1,
  91. GoFieldName: "TokenID",
  92. GoFieldType: "uint64",
  93. JSONFieldName: "token_id",
  94. ProtobufFieldName: "token_id",
  95. ProtobufType: "uint64",
  96. ProtobufPos: 2,
  97. },
  98. &ColumnInfo{
  99. Index: 2,
  100. Name: "key",
  101. Comment: ``,
  102. Notes: ``,
  103. Nullable: false,
  104. DatabaseTypeName: "varchar",
  105. DatabaseTypePretty: "varchar(256)",
  106. IsPrimaryKey: false,
  107. IsAutoIncrement: false,
  108. IsArray: false,
  109. ColumnType: "varchar",
  110. ColumnLength: 256,
  111. GoFieldName: "Key",
  112. GoFieldType: "string",
  113. JSONFieldName: "key",
  114. ProtobufFieldName: "key",
  115. ProtobufType: "string",
  116. ProtobufPos: 3,
  117. },
  118. &ColumnInfo{
  119. Index: 3,
  120. Name: "value",
  121. Comment: ``,
  122. Notes: ``,
  123. Nullable: false,
  124. DatabaseTypeName: "varchar",
  125. DatabaseTypePretty: "varchar(256)",
  126. IsPrimaryKey: false,
  127. IsAutoIncrement: false,
  128. IsArray: false,
  129. ColumnType: "varchar",
  130. ColumnLength: 256,
  131. GoFieldName: "Value",
  132. GoFieldType: "string",
  133. JSONFieldName: "value",
  134. ProtobufFieldName: "value",
  135. ProtobufType: "string",
  136. ProtobufPos: 4,
  137. },
  138. &ColumnInfo{
  139. Index: 4,
  140. Name: "created_at",
  141. Comment: ``,
  142. Notes: ``,
  143. Nullable: false,
  144. DatabaseTypeName: "timestamp",
  145. DatabaseTypePretty: "timestamp",
  146. IsPrimaryKey: false,
  147. IsAutoIncrement: false,
  148. IsArray: false,
  149. ColumnType: "timestamp",
  150. ColumnLength: -1,
  151. GoFieldName: "CreatedAt",
  152. GoFieldType: "time.Time",
  153. JSONFieldName: "created_at",
  154. ProtobufFieldName: "created_at",
  155. ProtobufType: "uint64",
  156. ProtobufPos: 5,
  157. },
  158. &ColumnInfo{
  159. Index: 5,
  160. Name: "updated_at",
  161. Comment: ``,
  162. Notes: ``,
  163. Nullable: false,
  164. DatabaseTypeName: "timestamp",
  165. DatabaseTypePretty: "timestamp",
  166. IsPrimaryKey: false,
  167. IsAutoIncrement: false,
  168. IsArray: false,
  169. ColumnType: "timestamp",
  170. ColumnLength: -1,
  171. GoFieldName: "UpdatedAt",
  172. GoFieldType: "time.Time",
  173. JSONFieldName: "updated_at",
  174. ProtobufFieldName: "updated_at",
  175. ProtobufType: "uint64",
  176. ProtobufPos: 6,
  177. },
  178. &ColumnInfo{
  179. Index: 6,
  180. Name: "deleted_at",
  181. Comment: ``,
  182. Notes: ``,
  183. Nullable: true,
  184. DatabaseTypeName: "timestamp",
  185. DatabaseTypePretty: "timestamp",
  186. IsPrimaryKey: false,
  187. IsAutoIncrement: false,
  188. IsArray: false,
  189. ColumnType: "timestamp",
  190. ColumnLength: -1,
  191. GoFieldName: "DeletedAt",
  192. GoFieldType: "null.Time",
  193. JSONFieldName: "deleted_at",
  194. ProtobufFieldName: "deleted_at",
  195. ProtobufType: "uint64",
  196. ProtobufPos: 7,
  197. },
  198. },
  199. }
  200. // TableName sets the insert table name for this struct type
  201. func (t *Traits) TableName() string {
  202. return "traits"
  203. }
  204. // BeforeSave invoked before saving, return an error if field is not populated.
  205. func (t *Traits) BeforeSave(*gorm.DB) error {
  206. return nil
  207. }
  208. // Prepare invoked before saving, can be used to populate fields etc.
  209. func (t *Traits) Prepare() {
  210. }
  211. // Validate invoked before performing action, return an error if field is not populated.
  212. func (t *Traits) Validate(action Action) error {
  213. return nil
  214. }
  215. // TableInfo return table meta data
  216. func (t *Traits) TableInfo() *TableInfo {
  217. return traitsTableInfo
  218. }