deposit.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 `deposit` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `user_id` bigint(20) unsigned NOT NULL,
  21. `sale_id` bigint(20) unsigned NOT NULL,
  22. `type` enum('eth','mr','mf') COLLATE utf8mb4_bin NOT NULL,
  23. `eth_price` double unsigned DEFAULT NULL,
  24. `mf1_price` double unsigned DEFAULT NULL,
  25. `mr_price` double unsigned DEFAULT NULL,
  26. `status` enum('deposit','withdrawal') COLLATE utf8mb4_bin NOT NULL,
  27. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  28. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  29. `deleted_at` timestamp NULL DEFAULT NULL,
  30. PRIMARY KEY (`id`),
  31. UNIQUE KEY `id_UNIQUE` (`id`),
  32. KEY `fk_deposit_user1_idx` (`user_id`),
  33. KEY `fk_deposit_sale1_idx` (`sale_id`),
  34. CONSTRAINT `fk_deposit_sale1` FOREIGN KEY (`sale_id`) REFERENCES `sale` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  35. CONSTRAINT `fk_deposit_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  36. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  37. JSON Sample
  38. -------------------------------------
  39. { "id": 15, "user_id": 15, "sale_id": 42, "type": "ZUVadboZActhXbCqcqkEmNZLP", "eth_price": 0.8648269980596258, "mf_1_price": 0.6687510484943536, "mr_price": 0.762288315291406, "status": "FCChVpwSLaSNAEJqRSgKsWxGB", "created_at": "2264-08-19T04:05:27.304906346+09:00", "updated_at": "2033-10-22T18:37:03.863970849+09:00", "deleted_at": "2031-01-19T09:51:31.038499828+09:00"}
  40. Comments
  41. -------------------------------------
  42. [ 0] column is set for unsigned
  43. [ 1] column is set for unsigned
  44. [ 2] column is set for unsigned
  45. [ 4] column is set for unsigned
  46. [ 5] column is set for unsigned
  47. [ 6] column is set for unsigned
  48. */
  49. // Deposit struct is a row record of the deposit table in the metarare database
  50. type Deposit struct {
  51. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  52. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  53. //[ 1] user_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  54. UserID uint64 `gorm:"column:user_id;type:ubigint;" json:"user_id"`
  55. //[ 2] sale_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  56. SaleID uint64 `gorm:"column:sale_id;type:ubigint;" json:"sale_id"`
  57. //[ 3] type char(3) null: false primary: false isArray: false auto: false col: char len: 3 default: []
  58. Type string `gorm:"column:type;type:char;size:3;" json:"type"`
  59. //[ 4] eth_price udouble null: true primary: false isArray: false auto: false col: udouble len: -1 default: []
  60. EthPrice null.Float `gorm:"column:eth_price;type:udouble;" json:"eth_price"`
  61. //[ 5] mf1_price udouble null: true primary: false isArray: false auto: false col: udouble len: -1 default: []
  62. Mf1Price null.Float `gorm:"column:mf1_price;type:udouble;" json:"mf_1_price"`
  63. //[ 6] mr_price udouble null: true primary: false isArray: false auto: false col: udouble len: -1 default: []
  64. MrPrice null.Float `gorm:"column:mr_price;type:udouble;" json:"mr_price"`
  65. //[ 7] status char(10) null: false primary: false isArray: false auto: false col: char len: 10 default: []
  66. Status string `gorm:"column:status;type:char;size:10;" json:"status"`
  67. //[ 8] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  68. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  69. //[ 9] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  70. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  71. //[10] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  72. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  73. }
  74. var depositTableInfo = &TableInfo{
  75. Name: "deposit",
  76. Columns: []*ColumnInfo{
  77. &ColumnInfo{
  78. Index: 0,
  79. Name: "id",
  80. Comment: ``,
  81. Notes: `column is set for unsigned`,
  82. Nullable: false,
  83. DatabaseTypeName: "ubigint",
  84. DatabaseTypePretty: "ubigint",
  85. IsPrimaryKey: true,
  86. IsAutoIncrement: true,
  87. IsArray: false,
  88. ColumnType: "ubigint",
  89. ColumnLength: -1,
  90. GoFieldName: "ID",
  91. GoFieldType: "uint64",
  92. JSONFieldName: "id",
  93. ProtobufFieldName: "id",
  94. ProtobufType: "uint64",
  95. ProtobufPos: 1,
  96. },
  97. &ColumnInfo{
  98. Index: 1,
  99. Name: "user_id",
  100. Comment: ``,
  101. Notes: `column is set for unsigned`,
  102. Nullable: false,
  103. DatabaseTypeName: "ubigint",
  104. DatabaseTypePretty: "ubigint",
  105. IsPrimaryKey: false,
  106. IsAutoIncrement: false,
  107. IsArray: false,
  108. ColumnType: "ubigint",
  109. ColumnLength: -1,
  110. GoFieldName: "UserID",
  111. GoFieldType: "uint64",
  112. JSONFieldName: "user_id",
  113. ProtobufFieldName: "user_id",
  114. ProtobufType: "uint64",
  115. ProtobufPos: 2,
  116. },
  117. &ColumnInfo{
  118. Index: 2,
  119. Name: "sale_id",
  120. Comment: ``,
  121. Notes: `column is set for unsigned`,
  122. Nullable: false,
  123. DatabaseTypeName: "ubigint",
  124. DatabaseTypePretty: "ubigint",
  125. IsPrimaryKey: false,
  126. IsAutoIncrement: false,
  127. IsArray: false,
  128. ColumnType: "ubigint",
  129. ColumnLength: -1,
  130. GoFieldName: "SaleID",
  131. GoFieldType: "uint64",
  132. JSONFieldName: "sale_id",
  133. ProtobufFieldName: "sale_id",
  134. ProtobufType: "uint64",
  135. ProtobufPos: 3,
  136. },
  137. &ColumnInfo{
  138. Index: 3,
  139. Name: "type",
  140. Comment: ``,
  141. Notes: ``,
  142. Nullable: false,
  143. DatabaseTypeName: "char",
  144. DatabaseTypePretty: "char(3)",
  145. IsPrimaryKey: false,
  146. IsAutoIncrement: false,
  147. IsArray: false,
  148. ColumnType: "char",
  149. ColumnLength: 3,
  150. GoFieldName: "Type",
  151. GoFieldType: "string",
  152. JSONFieldName: "type",
  153. ProtobufFieldName: "type",
  154. ProtobufType: "string",
  155. ProtobufPos: 4,
  156. },
  157. &ColumnInfo{
  158. Index: 4,
  159. Name: "eth_price",
  160. Comment: ``,
  161. Notes: `column is set for unsigned`,
  162. Nullable: true,
  163. DatabaseTypeName: "udouble",
  164. DatabaseTypePretty: "udouble",
  165. IsPrimaryKey: false,
  166. IsAutoIncrement: false,
  167. IsArray: false,
  168. ColumnType: "udouble",
  169. ColumnLength: -1,
  170. GoFieldName: "EthPrice",
  171. GoFieldType: "null.Float",
  172. JSONFieldName: "eth_price",
  173. ProtobufFieldName: "eth_price",
  174. ProtobufType: "float",
  175. ProtobufPos: 5,
  176. },
  177. &ColumnInfo{
  178. Index: 5,
  179. Name: "mf1_price",
  180. Comment: ``,
  181. Notes: `column is set for unsigned`,
  182. Nullable: true,
  183. DatabaseTypeName: "udouble",
  184. DatabaseTypePretty: "udouble",
  185. IsPrimaryKey: false,
  186. IsAutoIncrement: false,
  187. IsArray: false,
  188. ColumnType: "udouble",
  189. ColumnLength: -1,
  190. GoFieldName: "Mf1Price",
  191. GoFieldType: "null.Float",
  192. JSONFieldName: "mf_1_price",
  193. ProtobufFieldName: "mf_1_price",
  194. ProtobufType: "float",
  195. ProtobufPos: 6,
  196. },
  197. &ColumnInfo{
  198. Index: 6,
  199. Name: "mr_price",
  200. Comment: ``,
  201. Notes: `column is set for unsigned`,
  202. Nullable: true,
  203. DatabaseTypeName: "udouble",
  204. DatabaseTypePretty: "udouble",
  205. IsPrimaryKey: false,
  206. IsAutoIncrement: false,
  207. IsArray: false,
  208. ColumnType: "udouble",
  209. ColumnLength: -1,
  210. GoFieldName: "MrPrice",
  211. GoFieldType: "null.Float",
  212. JSONFieldName: "mr_price",
  213. ProtobufFieldName: "mr_price",
  214. ProtobufType: "float",
  215. ProtobufPos: 7,
  216. },
  217. &ColumnInfo{
  218. Index: 7,
  219. Name: "status",
  220. Comment: ``,
  221. Notes: ``,
  222. Nullable: false,
  223. DatabaseTypeName: "char",
  224. DatabaseTypePretty: "char(10)",
  225. IsPrimaryKey: false,
  226. IsAutoIncrement: false,
  227. IsArray: false,
  228. ColumnType: "char",
  229. ColumnLength: 10,
  230. GoFieldName: "Status",
  231. GoFieldType: "string",
  232. JSONFieldName: "status",
  233. ProtobufFieldName: "status",
  234. ProtobufType: "string",
  235. ProtobufPos: 8,
  236. },
  237. &ColumnInfo{
  238. Index: 8,
  239. Name: "created_at",
  240. Comment: ``,
  241. Notes: ``,
  242. Nullable: false,
  243. DatabaseTypeName: "timestamp",
  244. DatabaseTypePretty: "timestamp",
  245. IsPrimaryKey: false,
  246. IsAutoIncrement: false,
  247. IsArray: false,
  248. ColumnType: "timestamp",
  249. ColumnLength: -1,
  250. GoFieldName: "CreatedAt",
  251. GoFieldType: "time.Time",
  252. JSONFieldName: "created_at",
  253. ProtobufFieldName: "created_at",
  254. ProtobufType: "uint64",
  255. ProtobufPos: 9,
  256. },
  257. &ColumnInfo{
  258. Index: 9,
  259. Name: "updated_at",
  260. Comment: ``,
  261. Notes: ``,
  262. Nullable: false,
  263. DatabaseTypeName: "timestamp",
  264. DatabaseTypePretty: "timestamp",
  265. IsPrimaryKey: false,
  266. IsAutoIncrement: false,
  267. IsArray: false,
  268. ColumnType: "timestamp",
  269. ColumnLength: -1,
  270. GoFieldName: "UpdatedAt",
  271. GoFieldType: "time.Time",
  272. JSONFieldName: "updated_at",
  273. ProtobufFieldName: "updated_at",
  274. ProtobufType: "uint64",
  275. ProtobufPos: 10,
  276. },
  277. &ColumnInfo{
  278. Index: 10,
  279. Name: "deleted_at",
  280. Comment: ``,
  281. Notes: ``,
  282. Nullable: true,
  283. DatabaseTypeName: "timestamp",
  284. DatabaseTypePretty: "timestamp",
  285. IsPrimaryKey: false,
  286. IsAutoIncrement: false,
  287. IsArray: false,
  288. ColumnType: "timestamp",
  289. ColumnLength: -1,
  290. GoFieldName: "DeletedAt",
  291. GoFieldType: "null.Time",
  292. JSONFieldName: "deleted_at",
  293. ProtobufFieldName: "deleted_at",
  294. ProtobufType: "uint64",
  295. ProtobufPos: 11,
  296. },
  297. },
  298. }
  299. // TableName sets the insert table name for this struct type
  300. func (d *Deposit) TableName() string {
  301. return "deposit"
  302. }
  303. // BeforeSave invoked before saving, return an error if field is not populated.
  304. func (d *Deposit) BeforeSave(*gorm.DB) error {
  305. return nil
  306. }
  307. // Prepare invoked before saving, can be used to populate fields etc.
  308. func (d *Deposit) Prepare() {
  309. }
  310. // Validate invoked before performing action, return an error if field is not populated.
  311. func (d *Deposit) Validate(action Action) error {
  312. return nil
  313. }
  314. // TableInfo return table meta data
  315. func (d *Deposit) TableInfo() *TableInfo {
  316. return depositTableInfo
  317. }