log.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 `log` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `log_relation_id` bigint(20) unsigned NOT NULL,
  21. `type` enum('create','sell','purchase','transfer','burn','bid','like','withdrawal') COLLATE utf8mb4_bin NOT NULL,
  22. `sale_uid` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  23. `to_address` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  24. `from_address` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  25. `price` double DEFAULT NULL,
  26. `is_cancel` tinyint(4) DEFAULT '0',
  27. `tx` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  28. PRIMARY KEY (`id`),
  29. UNIQUE KEY `id_UNIQUE` (`id`),
  30. KEY `fk_template_table_log_relation1_idx` (`log_relation_id`),
  31. CONSTRAINT `fk_template_table_log_relation1` FOREIGN KEY (`log_relation_id`) REFERENCES `log_relation` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  32. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  33. JSON Sample
  34. -------------------------------------
  35. { "id": 72, "log_relation_id": 85, "type": "NGHjuUSYhitQnJbfXRnYANIlV", "sale_uid": "metxsoQWKaotFRqVDcrqKUiCk", "to_address": "NrfxseBemNEwiBiARaxIwoFPS", "from_address": "bJyumtYuACeSDgTxnkZjHuFDS", "price": 0.33262747080622135, "is_cancel": 15, "tx": "bjTncXoWtdbUkDlwwBvQcXflt"}
  36. Comments
  37. -------------------------------------
  38. [ 0] column is set for unsigned
  39. [ 1] column is set for unsigned
  40. */
  41. // Log struct is a row record of the log table in the metarare database
  42. type Log struct {
  43. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  44. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  45. //[ 1] log_relation_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  46. LogRelationID uint64 `gorm:"column:log_relation_id;type:ubigint;" json:"log_relation_id"`
  47. //[ 2] type char(10) null: false primary: false isArray: false auto: false col: char len: 10 default: []
  48. Type string `gorm:"column:type;type:char;size:10;" json:"type"`
  49. //[ 3] sale_uid varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  50. SaleUID null.String `gorm:"column:sale_uid;type:varchar;size:256;" json:"sale_uid"`
  51. //[ 4] to_address varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  52. ToAddress null.String `gorm:"column:to_address;type:varchar;size:256;" json:"to_address"`
  53. //[ 5] from_address varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  54. FromAddress null.String `gorm:"column:from_address;type:varchar;size:256;" json:"from_address"`
  55. //[ 6] price double null: true primary: false isArray: false auto: false col: double len: -1 default: []
  56. Price null.Float `gorm:"column:price;type:double;" json:"price"`
  57. //[ 7] is_cancel tinyint null: true primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  58. IsCancel null.Int `gorm:"column:is_cancel;type:tinyint;default:0;" json:"is_cancel"`
  59. //[ 8] tx varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  60. Tx null.String `gorm:"column:tx;type:varchar;size:256;" json:"tx"`
  61. }
  62. var logTableInfo = &TableInfo{
  63. Name: "log",
  64. Columns: []*ColumnInfo{
  65. &ColumnInfo{
  66. Index: 0,
  67. Name: "id",
  68. Comment: ``,
  69. Notes: `column is set for unsigned`,
  70. Nullable: false,
  71. DatabaseTypeName: "ubigint",
  72. DatabaseTypePretty: "ubigint",
  73. IsPrimaryKey: true,
  74. IsAutoIncrement: true,
  75. IsArray: false,
  76. ColumnType: "ubigint",
  77. ColumnLength: -1,
  78. GoFieldName: "ID",
  79. GoFieldType: "uint64",
  80. JSONFieldName: "id",
  81. ProtobufFieldName: "id",
  82. ProtobufType: "uint64",
  83. ProtobufPos: 1,
  84. },
  85. &ColumnInfo{
  86. Index: 1,
  87. Name: "log_relation_id",
  88. Comment: ``,
  89. Notes: `column is set for unsigned`,
  90. Nullable: false,
  91. DatabaseTypeName: "ubigint",
  92. DatabaseTypePretty: "ubigint",
  93. IsPrimaryKey: false,
  94. IsAutoIncrement: false,
  95. IsArray: false,
  96. ColumnType: "ubigint",
  97. ColumnLength: -1,
  98. GoFieldName: "LogRelationID",
  99. GoFieldType: "uint64",
  100. JSONFieldName: "log_relation_id",
  101. ProtobufFieldName: "log_relation_id",
  102. ProtobufType: "uint64",
  103. ProtobufPos: 2,
  104. },
  105. &ColumnInfo{
  106. Index: 2,
  107. Name: "type",
  108. Comment: ``,
  109. Notes: ``,
  110. Nullable: false,
  111. DatabaseTypeName: "char",
  112. DatabaseTypePretty: "char(10)",
  113. IsPrimaryKey: false,
  114. IsAutoIncrement: false,
  115. IsArray: false,
  116. ColumnType: "char",
  117. ColumnLength: 10,
  118. GoFieldName: "Type",
  119. GoFieldType: "string",
  120. JSONFieldName: "type",
  121. ProtobufFieldName: "type",
  122. ProtobufType: "string",
  123. ProtobufPos: 3,
  124. },
  125. &ColumnInfo{
  126. Index: 3,
  127. Name: "sale_uid",
  128. Comment: ``,
  129. Notes: ``,
  130. Nullable: true,
  131. DatabaseTypeName: "varchar",
  132. DatabaseTypePretty: "varchar(256)",
  133. IsPrimaryKey: false,
  134. IsAutoIncrement: false,
  135. IsArray: false,
  136. ColumnType: "varchar",
  137. ColumnLength: 256,
  138. GoFieldName: "SaleUID",
  139. GoFieldType: "null.String",
  140. JSONFieldName: "sale_uid",
  141. ProtobufFieldName: "sale_uid",
  142. ProtobufType: "string",
  143. ProtobufPos: 4,
  144. },
  145. &ColumnInfo{
  146. Index: 4,
  147. Name: "to_address",
  148. Comment: ``,
  149. Notes: ``,
  150. Nullable: true,
  151. DatabaseTypeName: "varchar",
  152. DatabaseTypePretty: "varchar(256)",
  153. IsPrimaryKey: false,
  154. IsAutoIncrement: false,
  155. IsArray: false,
  156. ColumnType: "varchar",
  157. ColumnLength: 256,
  158. GoFieldName: "ToAddress",
  159. GoFieldType: "null.String",
  160. JSONFieldName: "to_address",
  161. ProtobufFieldName: "to_address",
  162. ProtobufType: "string",
  163. ProtobufPos: 5,
  164. },
  165. &ColumnInfo{
  166. Index: 5,
  167. Name: "from_address",
  168. Comment: ``,
  169. Notes: ``,
  170. Nullable: true,
  171. DatabaseTypeName: "varchar",
  172. DatabaseTypePretty: "varchar(256)",
  173. IsPrimaryKey: false,
  174. IsAutoIncrement: false,
  175. IsArray: false,
  176. ColumnType: "varchar",
  177. ColumnLength: 256,
  178. GoFieldName: "FromAddress",
  179. GoFieldType: "null.String",
  180. JSONFieldName: "from_address",
  181. ProtobufFieldName: "from_address",
  182. ProtobufType: "string",
  183. ProtobufPos: 6,
  184. },
  185. &ColumnInfo{
  186. Index: 6,
  187. Name: "price",
  188. Comment: ``,
  189. Notes: ``,
  190. Nullable: true,
  191. DatabaseTypeName: "double",
  192. DatabaseTypePretty: "double",
  193. IsPrimaryKey: false,
  194. IsAutoIncrement: false,
  195. IsArray: false,
  196. ColumnType: "double",
  197. ColumnLength: -1,
  198. GoFieldName: "Price",
  199. GoFieldType: "null.Float",
  200. JSONFieldName: "price",
  201. ProtobufFieldName: "price",
  202. ProtobufType: "float",
  203. ProtobufPos: 7,
  204. },
  205. &ColumnInfo{
  206. Index: 7,
  207. Name: "is_cancel",
  208. Comment: ``,
  209. Notes: ``,
  210. Nullable: true,
  211. DatabaseTypeName: "tinyint",
  212. DatabaseTypePretty: "tinyint",
  213. IsPrimaryKey: false,
  214. IsAutoIncrement: false,
  215. IsArray: false,
  216. ColumnType: "tinyint",
  217. ColumnLength: -1,
  218. GoFieldName: "IsCancel",
  219. GoFieldType: "null.Int",
  220. JSONFieldName: "is_cancel",
  221. ProtobufFieldName: "is_cancel",
  222. ProtobufType: "int32",
  223. ProtobufPos: 8,
  224. },
  225. &ColumnInfo{
  226. Index: 8,
  227. Name: "tx",
  228. Comment: ``,
  229. Notes: ``,
  230. Nullable: true,
  231. DatabaseTypeName: "varchar",
  232. DatabaseTypePretty: "varchar(256)",
  233. IsPrimaryKey: false,
  234. IsAutoIncrement: false,
  235. IsArray: false,
  236. ColumnType: "varchar",
  237. ColumnLength: 256,
  238. GoFieldName: "Tx",
  239. GoFieldType: "null.String",
  240. JSONFieldName: "tx",
  241. ProtobufFieldName: "tx",
  242. ProtobufType: "string",
  243. ProtobufPos: 9,
  244. },
  245. },
  246. }
  247. // TableName sets the insert table name for this struct type
  248. func (l *Log) TableName() string {
  249. return "log"
  250. }
  251. // BeforeSave invoked before saving, return an error if field is not populated.
  252. func (l *Log) BeforeSave(*gorm.DB) error {
  253. return nil
  254. }
  255. // Prepare invoked before saving, can be used to populate fields etc.
  256. func (l *Log) Prepare() {
  257. }
  258. // Validate invoked before performing action, return an error if field is not populated.
  259. func (l *Log) Validate(action Action) error {
  260. return nil
  261. }
  262. // TableInfo return table meta data
  263. func (l *Log) TableInfo() *TableInfo {
  264. return logTableInfo
  265. }