collection.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 `collection` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `contract_address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  21. `owner_address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  22. `network` enum('eth','bsc','mr') COLLATE utf8mb4_bin NOT NULL DEFAULT 'eth',
  23. `symbol` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  24. `is_official` tinyint(4) NOT NULL DEFAULT '0',
  25. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  26. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  27. `deleted_at` timestamp NULL DEFAULT NULL,
  28. `curating_number` int(10) unsigned DEFAULT NULL,
  29. `status` enum('visible','invisible') COLLATE utf8mb4_bin NOT NULL DEFAULT 'visible',
  30. `type` enum('erc721','erc1155') COLLATE utf8mb4_bin NOT NULL DEFAULT 'erc721',
  31. PRIMARY KEY (`id`),
  32. UNIQUE KEY `id_UNIQUE` (`id`)
  33. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='삭제하는 케이스가 없기 때문에 상태 값이 invisible로 바뀌면 로그에는 burn으로 남긴다.'
  34. JSON Sample
  35. -------------------------------------
  36. { "id": 79, "contract_address": "ysNXAZoApFBnnjQFxAjORtqJN", "owner_address": "EXeaFJWTPSgSluAJfmoXeDPMb", "network": "vfBkrnYyTOOWPphHPASmtuifG", "symbol": "ScDyxLFbxTJKetOuZRIODhRQN", "is_official": 76, "created_at": "2117-11-23T16:07:05.493163554+09:00", "updated_at": "2105-02-21T07:13:07.571526828+09:00", "deleted_at": "2296-02-12T01:57:37.014082293+09:00", "curating_number": 54, "status": "AsGHGEntGgGWpvEUOnMVuIAlw", "type": "mlVxMeZYaUyBcRGTtRbHAtByu"}
  37. Comments
  38. -------------------------------------
  39. [ 0] column is set for unsigned
  40. [ 9] column is set for unsigned
  41. */
  42. // Collection struct is a row record of the collection table in the metarare database
  43. type Collection struct {
  44. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  45. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  46. //[ 1] contract_address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  47. ContractAddress string `gorm:"column:contract_address;type:varchar;size:256;" json:"contract_address"`
  48. //[ 2] owner_address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  49. OwnerAddress string `gorm:"column:owner_address;type:varchar;size:256;" json:"owner_address"`
  50. //[ 3] network char(3) null: false primary: false isArray: false auto: false col: char len: 3 default: [eth]
  51. Network string `gorm:"column:network;type:char;size:3;default:eth;" json:"network"`
  52. //[ 4] symbol varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  53. Symbol string `gorm:"column:symbol;type:varchar;size:256;" json:"symbol"`
  54. //[ 5] is_official tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  55. IsOfficial int32 `gorm:"column:is_official;type:tinyint;default:0;" json:"is_official"`
  56. //[ 6] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  57. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  58. //[ 7] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  59. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  60. //[ 8] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  61. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  62. //[ 9] curating_number uint null: true primary: false isArray: false auto: false col: uint len: -1 default: []
  63. CuratingNumber null.Int `gorm:"column:curating_number;type:uint;" json:"curating_number"`
  64. //[10] status char(9) null: false primary: false isArray: false auto: false col: char len: 9 default: [visible]
  65. Status string `gorm:"column:status;type:char;size:9;default:visible;" json:"status"`
  66. //[11] type char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: [erc721]
  67. Type string `gorm:"column:type;type:char;size:7;default:erc721;" json:"type"`
  68. }
  69. var collectionTableInfo = &TableInfo{
  70. Name: "collection",
  71. Columns: []*ColumnInfo{
  72. &ColumnInfo{
  73. Index: 0,
  74. Name: "id",
  75. Comment: ``,
  76. Notes: `column is set for unsigned`,
  77. Nullable: false,
  78. DatabaseTypeName: "ubigint",
  79. DatabaseTypePretty: "ubigint",
  80. IsPrimaryKey: true,
  81. IsAutoIncrement: true,
  82. IsArray: false,
  83. ColumnType: "ubigint",
  84. ColumnLength: -1,
  85. GoFieldName: "ID",
  86. GoFieldType: "uint64",
  87. JSONFieldName: "id",
  88. ProtobufFieldName: "id",
  89. ProtobufType: "uint64",
  90. ProtobufPos: 1,
  91. },
  92. &ColumnInfo{
  93. Index: 1,
  94. Name: "contract_address",
  95. Comment: ``,
  96. Notes: ``,
  97. Nullable: false,
  98. DatabaseTypeName: "varchar",
  99. DatabaseTypePretty: "varchar(256)",
  100. IsPrimaryKey: false,
  101. IsAutoIncrement: false,
  102. IsArray: false,
  103. ColumnType: "varchar",
  104. ColumnLength: 256,
  105. GoFieldName: "ContractAddress",
  106. GoFieldType: "string",
  107. JSONFieldName: "contract_address",
  108. ProtobufFieldName: "contract_address",
  109. ProtobufType: "string",
  110. ProtobufPos: 2,
  111. },
  112. &ColumnInfo{
  113. Index: 2,
  114. Name: "owner_address",
  115. Comment: ``,
  116. Notes: ``,
  117. Nullable: false,
  118. DatabaseTypeName: "varchar",
  119. DatabaseTypePretty: "varchar(256)",
  120. IsPrimaryKey: false,
  121. IsAutoIncrement: false,
  122. IsArray: false,
  123. ColumnType: "varchar",
  124. ColumnLength: 256,
  125. GoFieldName: "OwnerAddress",
  126. GoFieldType: "string",
  127. JSONFieldName: "owner_address",
  128. ProtobufFieldName: "owner_address",
  129. ProtobufType: "string",
  130. ProtobufPos: 3,
  131. },
  132. &ColumnInfo{
  133. Index: 3,
  134. Name: "network",
  135. Comment: ``,
  136. Notes: ``,
  137. Nullable: false,
  138. DatabaseTypeName: "char",
  139. DatabaseTypePretty: "char(3)",
  140. IsPrimaryKey: false,
  141. IsAutoIncrement: false,
  142. IsArray: false,
  143. ColumnType: "char",
  144. ColumnLength: 3,
  145. GoFieldName: "Network",
  146. GoFieldType: "string",
  147. JSONFieldName: "network",
  148. ProtobufFieldName: "network",
  149. ProtobufType: "string",
  150. ProtobufPos: 4,
  151. },
  152. &ColumnInfo{
  153. Index: 4,
  154. Name: "symbol",
  155. Comment: ``,
  156. Notes: ``,
  157. Nullable: false,
  158. DatabaseTypeName: "varchar",
  159. DatabaseTypePretty: "varchar(256)",
  160. IsPrimaryKey: false,
  161. IsAutoIncrement: false,
  162. IsArray: false,
  163. ColumnType: "varchar",
  164. ColumnLength: 256,
  165. GoFieldName: "Symbol",
  166. GoFieldType: "string",
  167. JSONFieldName: "symbol",
  168. ProtobufFieldName: "symbol",
  169. ProtobufType: "string",
  170. ProtobufPos: 5,
  171. },
  172. &ColumnInfo{
  173. Index: 5,
  174. Name: "is_official",
  175. Comment: ``,
  176. Notes: ``,
  177. Nullable: false,
  178. DatabaseTypeName: "tinyint",
  179. DatabaseTypePretty: "tinyint",
  180. IsPrimaryKey: false,
  181. IsAutoIncrement: false,
  182. IsArray: false,
  183. ColumnType: "tinyint",
  184. ColumnLength: -1,
  185. GoFieldName: "IsOfficial",
  186. GoFieldType: "int32",
  187. JSONFieldName: "is_official",
  188. ProtobufFieldName: "is_official",
  189. ProtobufType: "int32",
  190. ProtobufPos: 6,
  191. },
  192. &ColumnInfo{
  193. Index: 6,
  194. Name: "created_at",
  195. Comment: ``,
  196. Notes: ``,
  197. Nullable: false,
  198. DatabaseTypeName: "timestamp",
  199. DatabaseTypePretty: "timestamp",
  200. IsPrimaryKey: false,
  201. IsAutoIncrement: false,
  202. IsArray: false,
  203. ColumnType: "timestamp",
  204. ColumnLength: -1,
  205. GoFieldName: "CreatedAt",
  206. GoFieldType: "time.Time",
  207. JSONFieldName: "created_at",
  208. ProtobufFieldName: "created_at",
  209. ProtobufType: "uint64",
  210. ProtobufPos: 7,
  211. },
  212. &ColumnInfo{
  213. Index: 7,
  214. Name: "updated_at",
  215. Comment: ``,
  216. Notes: ``,
  217. Nullable: false,
  218. DatabaseTypeName: "timestamp",
  219. DatabaseTypePretty: "timestamp",
  220. IsPrimaryKey: false,
  221. IsAutoIncrement: false,
  222. IsArray: false,
  223. ColumnType: "timestamp",
  224. ColumnLength: -1,
  225. GoFieldName: "UpdatedAt",
  226. GoFieldType: "time.Time",
  227. JSONFieldName: "updated_at",
  228. ProtobufFieldName: "updated_at",
  229. ProtobufType: "uint64",
  230. ProtobufPos: 8,
  231. },
  232. &ColumnInfo{
  233. Index: 8,
  234. Name: "deleted_at",
  235. Comment: ``,
  236. Notes: ``,
  237. Nullable: true,
  238. DatabaseTypeName: "timestamp",
  239. DatabaseTypePretty: "timestamp",
  240. IsPrimaryKey: false,
  241. IsAutoIncrement: false,
  242. IsArray: false,
  243. ColumnType: "timestamp",
  244. ColumnLength: -1,
  245. GoFieldName: "DeletedAt",
  246. GoFieldType: "null.Time",
  247. JSONFieldName: "deleted_at",
  248. ProtobufFieldName: "deleted_at",
  249. ProtobufType: "uint64",
  250. ProtobufPos: 9,
  251. },
  252. &ColumnInfo{
  253. Index: 9,
  254. Name: "curating_number",
  255. Comment: ``,
  256. Notes: `column is set for unsigned`,
  257. Nullable: true,
  258. DatabaseTypeName: "uint",
  259. DatabaseTypePretty: "uint",
  260. IsPrimaryKey: false,
  261. IsAutoIncrement: false,
  262. IsArray: false,
  263. ColumnType: "uint",
  264. ColumnLength: -1,
  265. GoFieldName: "CuratingNumber",
  266. GoFieldType: "null.Int",
  267. JSONFieldName: "curating_number",
  268. ProtobufFieldName: "curating_number",
  269. ProtobufType: "uint32",
  270. ProtobufPos: 10,
  271. },
  272. &ColumnInfo{
  273. Index: 10,
  274. Name: "status",
  275. Comment: ``,
  276. Notes: ``,
  277. Nullable: false,
  278. DatabaseTypeName: "char",
  279. DatabaseTypePretty: "char(9)",
  280. IsPrimaryKey: false,
  281. IsAutoIncrement: false,
  282. IsArray: false,
  283. ColumnType: "char",
  284. ColumnLength: 9,
  285. GoFieldName: "Status",
  286. GoFieldType: "string",
  287. JSONFieldName: "status",
  288. ProtobufFieldName: "status",
  289. ProtobufType: "string",
  290. ProtobufPos: 11,
  291. },
  292. &ColumnInfo{
  293. Index: 11,
  294. Name: "type",
  295. Comment: ``,
  296. Notes: ``,
  297. Nullable: false,
  298. DatabaseTypeName: "char",
  299. DatabaseTypePretty: "char(7)",
  300. IsPrimaryKey: false,
  301. IsAutoIncrement: false,
  302. IsArray: false,
  303. ColumnType: "char",
  304. ColumnLength: 7,
  305. GoFieldName: "Type",
  306. GoFieldType: "string",
  307. JSONFieldName: "type",
  308. ProtobufFieldName: "type",
  309. ProtobufType: "string",
  310. ProtobufPos: 12,
  311. },
  312. },
  313. }
  314. // TableName sets the insert table name for this struct type
  315. func (c *Collection) TableName() string {
  316. return "collection"
  317. }
  318. // BeforeSave invoked before saving, return an error if field is not populated.
  319. func (c *Collection) BeforeSave(*gorm.DB) error {
  320. return nil
  321. }
  322. // Prepare invoked before saving, can be used to populate fields etc.
  323. func (c *Collection) Prepare() {
  324. }
  325. // Validate invoked before performing action, return an error if field is not populated.
  326. func (c *Collection) Validate(action Action) error {
  327. return nil
  328. }
  329. // TableInfo return table meta data
  330. func (c *Collection) TableInfo() *TableInfo {
  331. return collectionTableInfo
  332. }