token.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 `token` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `collection_id` bigint(20) unsigned NOT NULL,
  21. `name` varchar(128) COLLATE utf8mb4_bin NOT NULL,
  22. `description` text COLLATE utf8mb4_bin NOT NULL,
  23. `type` enum('erc721','erc1155') COLLATE utf8mb4_bin NOT NULL DEFAULT 'erc721',
  24. `total_count` int(10) unsigned DEFAULT NULL,
  25. `index` int(10) unsigned DEFAULT NULL,
  26. `content_url` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  27. `assets_image_url` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  28. `lastest_price` double DEFAULT NULL,
  29. `royalties` int(10) unsigned NOT NULL DEFAULT '0',
  30. `creator_address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  31. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  32. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  33. `deleted_at` timestamp NULL DEFAULT NULL,
  34. `lastest_currency` enum('eth','mr','mf') COLLATE utf8mb4_bin DEFAULT NULL,
  35. `owner_address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  36. `like_count` int(10) unsigned NOT NULL DEFAULT '0',
  37. `uid` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  38. PRIMARY KEY (`id`),
  39. UNIQUE KEY `id_UNIQUE` (`id`),
  40. KEY `fk_token_collection1_idx` (`collection_id`),
  41. CONSTRAINT `fk_token_collection1` FOREIGN KEY (`collection_id`) REFERENCES `collection` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  42. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  43. JSON Sample
  44. -------------------------------------
  45. { "id": 50, "collection_id": 6, "name": "HdhEKCwKryeydaXVThoFxpKiG", "description": "PAJBLrfkkwOhXBJBnCApUiDwN", "type": "vBtnugXUabKKxTlHbjaCCkqyg", "total_count": 21, "index": 67, "content_url": "fsiXuUmoxMfMCjlYqJKmDPUEx", "assets_image_url": "syfFdawPpltvDvlhqLsqjWHHj", "lastest_price": 0.08218025651900168, "royalties": 1, "creator_address": "uXxWHgBjuXHElZnBreaBwbOur", "created_at": "2264-08-09T16:32:26.762845536+09:00", "updated_at": "2193-05-17T21:18:15.393715445+09:00", "deleted_at": "2166-08-03T12:57:01.298461162+09:00", "lastest_currency": "KtayejtZlmiAcTJlPESQqYFDQ", "owner_address": "oOXTparpmNBArVulnPTetflql", "like_count": 86, "uid": "kkAXiJeKcDBJEbyXuhHuvcwPj"}
  46. Comments
  47. -------------------------------------
  48. [ 0] column is set for unsigned
  49. [ 1] column is set for unsigned
  50. [ 5] column is set for unsigned
  51. [ 6] column is set for unsigned
  52. [10] column is set for unsigned
  53. [17] column is set for unsigned
  54. */
  55. // Token struct is a row record of the token table in the metarare database
  56. type Token struct {
  57. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  58. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  59. //[ 1] collection_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  60. CollectionID uint64 `gorm:"column:collection_id;type:ubigint;" json:"collection_id"`
  61. //[ 2] name varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  62. Name string `gorm:"column:name;type:varchar;size:128;" json:"name"`
  63. //[ 3] description text(65535) null: false primary: false isArray: false auto: false col: text len: 65535 default: []
  64. Description string `gorm:"column:description;type:text;size:65535;" json:"description"`
  65. //[ 4] type char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: [erc721]
  66. Type string `gorm:"column:type;type:char;size:7;default:erc721;" json:"type"`
  67. //[ 5] total_count uint null: true primary: false isArray: false auto: false col: uint len: -1 default: []
  68. TotalCount null.Int `gorm:"column:total_count;type:uint;" json:"total_count"`
  69. //[ 6] index uint null: true primary: false isArray: false auto: false col: uint len: -1 default: []
  70. Index null.Int `gorm:"column:index;type:uint;" json:"index"`
  71. //[ 7] content_url varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  72. ContentURL string `gorm:"column:content_url;type:varchar;size:256;" json:"content_url"`
  73. //[ 8] assets_image_url varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  74. AssetsImageURL string `gorm:"column:assets_image_url;type:varchar;size:256;" json:"assets_image_url"`
  75. //[ 9] lastest_price double null: true primary: false isArray: false auto: false col: double len: -1 default: []
  76. LastestPrice null.Float `gorm:"column:lastest_price;type:double;" json:"lastest_price"`
  77. //[10] royalties uint null: false primary: false isArray: false auto: false col: uint len: -1 default: [0]
  78. Royalties uint32 `gorm:"column:royalties;type:uint;default:0;" json:"royalties"`
  79. //[11] creator_address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  80. CreatorAddress string `gorm:"column:creator_address;type:varchar;size:256;" json:"creator_address"`
  81. //[12] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  82. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  83. //[13] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  84. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  85. //[14] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  86. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  87. //[15] lastest_currency char(3) null: true primary: false isArray: false auto: false col: char len: 3 default: []
  88. LastestCurrency null.String `gorm:"column:lastest_currency;type:char;size:3;" json:"lastest_currency"`
  89. //[16] owner_address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  90. OwnerAddress string `gorm:"column:owner_address;type:varchar;size:256;" json:"owner_address"`
  91. //[17] like_count uint null: false primary: false isArray: false auto: false col: uint len: -1 default: [0]
  92. LikeCount uint32 `gorm:"column:like_count;type:uint;default:0;" json:"like_count"`
  93. //[18] uid varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  94. UID string `gorm:"column:uid;type:varchar;size:256;" json:"uid"`
  95. }
  96. var tokenTableInfo = &TableInfo{
  97. Name: "token",
  98. Columns: []*ColumnInfo{
  99. &ColumnInfo{
  100. Index: 0,
  101. Name: "id",
  102. Comment: ``,
  103. Notes: `column is set for unsigned`,
  104. Nullable: false,
  105. DatabaseTypeName: "ubigint",
  106. DatabaseTypePretty: "ubigint",
  107. IsPrimaryKey: true,
  108. IsAutoIncrement: true,
  109. IsArray: false,
  110. ColumnType: "ubigint",
  111. ColumnLength: -1,
  112. GoFieldName: "ID",
  113. GoFieldType: "uint64",
  114. JSONFieldName: "id",
  115. ProtobufFieldName: "id",
  116. ProtobufType: "uint64",
  117. ProtobufPos: 1,
  118. },
  119. &ColumnInfo{
  120. Index: 1,
  121. Name: "collection_id",
  122. Comment: ``,
  123. Notes: `column is set for unsigned`,
  124. Nullable: false,
  125. DatabaseTypeName: "ubigint",
  126. DatabaseTypePretty: "ubigint",
  127. IsPrimaryKey: false,
  128. IsAutoIncrement: false,
  129. IsArray: false,
  130. ColumnType: "ubigint",
  131. ColumnLength: -1,
  132. GoFieldName: "CollectionID",
  133. GoFieldType: "uint64",
  134. JSONFieldName: "collection_id",
  135. ProtobufFieldName: "collection_id",
  136. ProtobufType: "uint64",
  137. ProtobufPos: 2,
  138. },
  139. &ColumnInfo{
  140. Index: 2,
  141. Name: "name",
  142. Comment: ``,
  143. Notes: ``,
  144. Nullable: false,
  145. DatabaseTypeName: "varchar",
  146. DatabaseTypePretty: "varchar(128)",
  147. IsPrimaryKey: false,
  148. IsAutoIncrement: false,
  149. IsArray: false,
  150. ColumnType: "varchar",
  151. ColumnLength: 128,
  152. GoFieldName: "Name",
  153. GoFieldType: "string",
  154. JSONFieldName: "name",
  155. ProtobufFieldName: "name",
  156. ProtobufType: "string",
  157. ProtobufPos: 3,
  158. },
  159. &ColumnInfo{
  160. Index: 3,
  161. Name: "description",
  162. Comment: ``,
  163. Notes: ``,
  164. Nullable: false,
  165. DatabaseTypeName: "text",
  166. DatabaseTypePretty: "text(65535)",
  167. IsPrimaryKey: false,
  168. IsAutoIncrement: false,
  169. IsArray: false,
  170. ColumnType: "text",
  171. ColumnLength: 65535,
  172. GoFieldName: "Description",
  173. GoFieldType: "string",
  174. JSONFieldName: "description",
  175. ProtobufFieldName: "description",
  176. ProtobufType: "string",
  177. ProtobufPos: 4,
  178. },
  179. &ColumnInfo{
  180. Index: 4,
  181. Name: "type",
  182. Comment: ``,
  183. Notes: ``,
  184. Nullable: false,
  185. DatabaseTypeName: "char",
  186. DatabaseTypePretty: "char(7)",
  187. IsPrimaryKey: false,
  188. IsAutoIncrement: false,
  189. IsArray: false,
  190. ColumnType: "char",
  191. ColumnLength: 7,
  192. GoFieldName: "Type",
  193. GoFieldType: "string",
  194. JSONFieldName: "type",
  195. ProtobufFieldName: "type",
  196. ProtobufType: "string",
  197. ProtobufPos: 5,
  198. },
  199. &ColumnInfo{
  200. Index: 5,
  201. Name: "total_count",
  202. Comment: ``,
  203. Notes: `column is set for unsigned`,
  204. Nullable: true,
  205. DatabaseTypeName: "uint",
  206. DatabaseTypePretty: "uint",
  207. IsPrimaryKey: false,
  208. IsAutoIncrement: false,
  209. IsArray: false,
  210. ColumnType: "uint",
  211. ColumnLength: -1,
  212. GoFieldName: "TotalCount",
  213. GoFieldType: "null.Int",
  214. JSONFieldName: "total_count",
  215. ProtobufFieldName: "total_count",
  216. ProtobufType: "uint32",
  217. ProtobufPos: 6,
  218. },
  219. &ColumnInfo{
  220. Index: 6,
  221. Name: "index",
  222. Comment: ``,
  223. Notes: `column is set for unsigned`,
  224. Nullable: true,
  225. DatabaseTypeName: "uint",
  226. DatabaseTypePretty: "uint",
  227. IsPrimaryKey: false,
  228. IsAutoIncrement: false,
  229. IsArray: false,
  230. ColumnType: "uint",
  231. ColumnLength: -1,
  232. GoFieldName: "Index",
  233. GoFieldType: "null.Int",
  234. JSONFieldName: "index",
  235. ProtobufFieldName: "index",
  236. ProtobufType: "uint32",
  237. ProtobufPos: 7,
  238. },
  239. &ColumnInfo{
  240. Index: 7,
  241. Name: "content_url",
  242. Comment: ``,
  243. Notes: ``,
  244. Nullable: false,
  245. DatabaseTypeName: "varchar",
  246. DatabaseTypePretty: "varchar(256)",
  247. IsPrimaryKey: false,
  248. IsAutoIncrement: false,
  249. IsArray: false,
  250. ColumnType: "varchar",
  251. ColumnLength: 256,
  252. GoFieldName: "ContentURL",
  253. GoFieldType: "string",
  254. JSONFieldName: "content_url",
  255. ProtobufFieldName: "content_url",
  256. ProtobufType: "string",
  257. ProtobufPos: 8,
  258. },
  259. &ColumnInfo{
  260. Index: 8,
  261. Name: "assets_image_url",
  262. Comment: ``,
  263. Notes: ``,
  264. Nullable: false,
  265. DatabaseTypeName: "varchar",
  266. DatabaseTypePretty: "varchar(256)",
  267. IsPrimaryKey: false,
  268. IsAutoIncrement: false,
  269. IsArray: false,
  270. ColumnType: "varchar",
  271. ColumnLength: 256,
  272. GoFieldName: "AssetsImageURL",
  273. GoFieldType: "string",
  274. JSONFieldName: "assets_image_url",
  275. ProtobufFieldName: "assets_image_url",
  276. ProtobufType: "string",
  277. ProtobufPos: 9,
  278. },
  279. &ColumnInfo{
  280. Index: 9,
  281. Name: "lastest_price",
  282. Comment: ``,
  283. Notes: ``,
  284. Nullable: true,
  285. DatabaseTypeName: "double",
  286. DatabaseTypePretty: "double",
  287. IsPrimaryKey: false,
  288. IsAutoIncrement: false,
  289. IsArray: false,
  290. ColumnType: "double",
  291. ColumnLength: -1,
  292. GoFieldName: "LastestPrice",
  293. GoFieldType: "null.Float",
  294. JSONFieldName: "lastest_price",
  295. ProtobufFieldName: "lastest_price",
  296. ProtobufType: "float",
  297. ProtobufPos: 10,
  298. },
  299. &ColumnInfo{
  300. Index: 10,
  301. Name: "royalties",
  302. Comment: ``,
  303. Notes: `column is set for unsigned`,
  304. Nullable: false,
  305. DatabaseTypeName: "uint",
  306. DatabaseTypePretty: "uint",
  307. IsPrimaryKey: false,
  308. IsAutoIncrement: false,
  309. IsArray: false,
  310. ColumnType: "uint",
  311. ColumnLength: -1,
  312. GoFieldName: "Royalties",
  313. GoFieldType: "uint32",
  314. JSONFieldName: "royalties",
  315. ProtobufFieldName: "royalties",
  316. ProtobufType: "uint32",
  317. ProtobufPos: 11,
  318. },
  319. &ColumnInfo{
  320. Index: 11,
  321. Name: "creator_address",
  322. Comment: ``,
  323. Notes: ``,
  324. Nullable: false,
  325. DatabaseTypeName: "varchar",
  326. DatabaseTypePretty: "varchar(256)",
  327. IsPrimaryKey: false,
  328. IsAutoIncrement: false,
  329. IsArray: false,
  330. ColumnType: "varchar",
  331. ColumnLength: 256,
  332. GoFieldName: "CreatorAddress",
  333. GoFieldType: "string",
  334. JSONFieldName: "creator_address",
  335. ProtobufFieldName: "creator_address",
  336. ProtobufType: "string",
  337. ProtobufPos: 12,
  338. },
  339. &ColumnInfo{
  340. Index: 12,
  341. Name: "created_at",
  342. Comment: ``,
  343. Notes: ``,
  344. Nullable: false,
  345. DatabaseTypeName: "timestamp",
  346. DatabaseTypePretty: "timestamp",
  347. IsPrimaryKey: false,
  348. IsAutoIncrement: false,
  349. IsArray: false,
  350. ColumnType: "timestamp",
  351. ColumnLength: -1,
  352. GoFieldName: "CreatedAt",
  353. GoFieldType: "time.Time",
  354. JSONFieldName: "created_at",
  355. ProtobufFieldName: "created_at",
  356. ProtobufType: "uint64",
  357. ProtobufPos: 13,
  358. },
  359. &ColumnInfo{
  360. Index: 13,
  361. Name: "updated_at",
  362. Comment: ``,
  363. Notes: ``,
  364. Nullable: false,
  365. DatabaseTypeName: "timestamp",
  366. DatabaseTypePretty: "timestamp",
  367. IsPrimaryKey: false,
  368. IsAutoIncrement: false,
  369. IsArray: false,
  370. ColumnType: "timestamp",
  371. ColumnLength: -1,
  372. GoFieldName: "UpdatedAt",
  373. GoFieldType: "time.Time",
  374. JSONFieldName: "updated_at",
  375. ProtobufFieldName: "updated_at",
  376. ProtobufType: "uint64",
  377. ProtobufPos: 14,
  378. },
  379. &ColumnInfo{
  380. Index: 14,
  381. Name: "deleted_at",
  382. Comment: ``,
  383. Notes: ``,
  384. Nullable: true,
  385. DatabaseTypeName: "timestamp",
  386. DatabaseTypePretty: "timestamp",
  387. IsPrimaryKey: false,
  388. IsAutoIncrement: false,
  389. IsArray: false,
  390. ColumnType: "timestamp",
  391. ColumnLength: -1,
  392. GoFieldName: "DeletedAt",
  393. GoFieldType: "null.Time",
  394. JSONFieldName: "deleted_at",
  395. ProtobufFieldName: "deleted_at",
  396. ProtobufType: "uint64",
  397. ProtobufPos: 15,
  398. },
  399. &ColumnInfo{
  400. Index: 15,
  401. Name: "lastest_currency",
  402. Comment: ``,
  403. Notes: ``,
  404. Nullable: true,
  405. DatabaseTypeName: "char",
  406. DatabaseTypePretty: "char(3)",
  407. IsPrimaryKey: false,
  408. IsAutoIncrement: false,
  409. IsArray: false,
  410. ColumnType: "char",
  411. ColumnLength: 3,
  412. GoFieldName: "LastestCurrency",
  413. GoFieldType: "null.String",
  414. JSONFieldName: "lastest_currency",
  415. ProtobufFieldName: "lastest_currency",
  416. ProtobufType: "string",
  417. ProtobufPos: 16,
  418. },
  419. &ColumnInfo{
  420. Index: 16,
  421. Name: "owner_address",
  422. Comment: ``,
  423. Notes: ``,
  424. Nullable: false,
  425. DatabaseTypeName: "varchar",
  426. DatabaseTypePretty: "varchar(256)",
  427. IsPrimaryKey: false,
  428. IsAutoIncrement: false,
  429. IsArray: false,
  430. ColumnType: "varchar",
  431. ColumnLength: 256,
  432. GoFieldName: "OwnerAddress",
  433. GoFieldType: "string",
  434. JSONFieldName: "owner_address",
  435. ProtobufFieldName: "owner_address",
  436. ProtobufType: "string",
  437. ProtobufPos: 17,
  438. },
  439. &ColumnInfo{
  440. Index: 17,
  441. Name: "like_count",
  442. Comment: ``,
  443. Notes: `column is set for unsigned`,
  444. Nullable: false,
  445. DatabaseTypeName: "uint",
  446. DatabaseTypePretty: "uint",
  447. IsPrimaryKey: false,
  448. IsAutoIncrement: false,
  449. IsArray: false,
  450. ColumnType: "uint",
  451. ColumnLength: -1,
  452. GoFieldName: "LikeCount",
  453. GoFieldType: "uint32",
  454. JSONFieldName: "like_count",
  455. ProtobufFieldName: "like_count",
  456. ProtobufType: "uint32",
  457. ProtobufPos: 18,
  458. },
  459. &ColumnInfo{
  460. Index: 18,
  461. Name: "uid",
  462. Comment: ``,
  463. Notes: ``,
  464. Nullable: false,
  465. DatabaseTypeName: "varchar",
  466. DatabaseTypePretty: "varchar(256)",
  467. IsPrimaryKey: false,
  468. IsAutoIncrement: false,
  469. IsArray: false,
  470. ColumnType: "varchar",
  471. ColumnLength: 256,
  472. GoFieldName: "UID",
  473. GoFieldType: "string",
  474. JSONFieldName: "uid",
  475. ProtobufFieldName: "uid",
  476. ProtobufType: "string",
  477. ProtobufPos: 19,
  478. },
  479. },
  480. }
  481. // TableName sets the insert table name for this struct type
  482. func (t *Token) TableName() string {
  483. return "token"
  484. }
  485. // BeforeSave invoked before saving, return an error if field is not populated.
  486. func (t *Token) BeforeSave(*gorm.DB) error {
  487. return nil
  488. }
  489. // Prepare invoked before saving, can be used to populate fields etc.
  490. func (t *Token) Prepare() {
  491. }
  492. // Validate invoked before performing action, return an error if field is not populated.
  493. func (t *Token) Validate(action Action) error {
  494. return nil
  495. }
  496. // TableInfo return table meta data
  497. func (t *Token) TableInfo() *TableInfo {
  498. return tokenTableInfo
  499. }