setting.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 `setting` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `commission` double NOT NULL,
  21. `special_collection` varchar(128) COLLATE utf8mb4_bin NOT NULL,
  22. `gas_deposit` double NOT NULL,
  23. `treasury_address` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  24. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  25. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  26. `deleted_at` timestamp NULL DEFAULT NULL,
  27. PRIMARY KEY (`id`)
  28. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  29. JSON Sample
  30. -------------------------------------
  31. { "id": 58, "commission": 0.26761219721913815, "special_collection": "fNuKUskZGeuTOrIvAMymkMgMT", "gas_deposit": 0.5107786712562139, "treasury_address": "KkxOkbxRwGcQFLZdTUIjIdxgx", "created_at": "2027-08-29T21:32:51.137710708+09:00", "updated_at": "2292-10-21T02:48:53.679850197+09:00", "deleted_at": "2210-06-07T02:52:12.736595621+09:00"}
  32. Comments
  33. -------------------------------------
  34. [ 0] column is set for unsigned
  35. */
  36. // Setting struct is a row record of the setting table in the metarare database
  37. type Setting struct {
  38. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  39. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  40. //[ 1] commission double null: false primary: false isArray: false auto: false col: double len: -1 default: []
  41. Commission float64 `gorm:"column:commission;type:double;" json:"commission"`
  42. //[ 2] special_collection varchar(128) null: false primary: false isArray: false auto: false col: varchar len: 128 default: []
  43. SpecialCollection string `gorm:"column:special_collection;type:varchar;size:128;" json:"special_collection"`
  44. //[ 3] gas_deposit double null: false primary: false isArray: false auto: false col: double len: -1 default: []
  45. GasDeposit float64 `gorm:"column:gas_deposit;type:double;" json:"gas_deposit"`
  46. //[ 4] treasury_address varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  47. TreasuryAddress string `gorm:"column:treasury_address;type:varchar;size:256;" json:"treasury_address"`
  48. //[ 5] 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. //[ 6] 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. //[ 7] 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 settingTableInfo = &TableInfo{
  56. Name: "setting",
  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: "commission",
  81. Comment: ``,
  82. Notes: ``,
  83. Nullable: false,
  84. DatabaseTypeName: "double",
  85. DatabaseTypePretty: "double",
  86. IsPrimaryKey: false,
  87. IsAutoIncrement: false,
  88. IsArray: false,
  89. ColumnType: "double",
  90. ColumnLength: -1,
  91. GoFieldName: "Commission",
  92. GoFieldType: "float64",
  93. JSONFieldName: "commission",
  94. ProtobufFieldName: "commission",
  95. ProtobufType: "float",
  96. ProtobufPos: 2,
  97. },
  98. &ColumnInfo{
  99. Index: 2,
  100. Name: "special_collection",
  101. Comment: ``,
  102. Notes: ``,
  103. Nullable: false,
  104. DatabaseTypeName: "varchar",
  105. DatabaseTypePretty: "varchar(128)",
  106. IsPrimaryKey: false,
  107. IsAutoIncrement: false,
  108. IsArray: false,
  109. ColumnType: "varchar",
  110. ColumnLength: 128,
  111. GoFieldName: "SpecialCollection",
  112. GoFieldType: "string",
  113. JSONFieldName: "special_collection",
  114. ProtobufFieldName: "special_collection",
  115. ProtobufType: "string",
  116. ProtobufPos: 3,
  117. },
  118. &ColumnInfo{
  119. Index: 3,
  120. Name: "gas_deposit",
  121. Comment: ``,
  122. Notes: ``,
  123. Nullable: false,
  124. DatabaseTypeName: "double",
  125. DatabaseTypePretty: "double",
  126. IsPrimaryKey: false,
  127. IsAutoIncrement: false,
  128. IsArray: false,
  129. ColumnType: "double",
  130. ColumnLength: -1,
  131. GoFieldName: "GasDeposit",
  132. GoFieldType: "float64",
  133. JSONFieldName: "gas_deposit",
  134. ProtobufFieldName: "gas_deposit",
  135. ProtobufType: "float",
  136. ProtobufPos: 4,
  137. },
  138. &ColumnInfo{
  139. Index: 4,
  140. Name: "treasury_address",
  141. Comment: ``,
  142. Notes: ``,
  143. Nullable: false,
  144. DatabaseTypeName: "varchar",
  145. DatabaseTypePretty: "varchar(256)",
  146. IsPrimaryKey: false,
  147. IsAutoIncrement: false,
  148. IsArray: false,
  149. ColumnType: "varchar",
  150. ColumnLength: 256,
  151. GoFieldName: "TreasuryAddress",
  152. GoFieldType: "string",
  153. JSONFieldName: "treasury_address",
  154. ProtobufFieldName: "treasury_address",
  155. ProtobufType: "string",
  156. ProtobufPos: 5,
  157. },
  158. &ColumnInfo{
  159. Index: 5,
  160. Name: "created_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: "CreatedAt",
  172. GoFieldType: "time.Time",
  173. JSONFieldName: "created_at",
  174. ProtobufFieldName: "created_at",
  175. ProtobufType: "uint64",
  176. ProtobufPos: 6,
  177. },
  178. &ColumnInfo{
  179. Index: 6,
  180. Name: "updated_at",
  181. Comment: ``,
  182. Notes: ``,
  183. Nullable: false,
  184. DatabaseTypeName: "timestamp",
  185. DatabaseTypePretty: "timestamp",
  186. IsPrimaryKey: false,
  187. IsAutoIncrement: false,
  188. IsArray: false,
  189. ColumnType: "timestamp",
  190. ColumnLength: -1,
  191. GoFieldName: "UpdatedAt",
  192. GoFieldType: "time.Time",
  193. JSONFieldName: "updated_at",
  194. ProtobufFieldName: "updated_at",
  195. ProtobufType: "uint64",
  196. ProtobufPos: 7,
  197. },
  198. &ColumnInfo{
  199. Index: 7,
  200. Name: "deleted_at",
  201. Comment: ``,
  202. Notes: ``,
  203. Nullable: true,
  204. DatabaseTypeName: "timestamp",
  205. DatabaseTypePretty: "timestamp",
  206. IsPrimaryKey: false,
  207. IsAutoIncrement: false,
  208. IsArray: false,
  209. ColumnType: "timestamp",
  210. ColumnLength: -1,
  211. GoFieldName: "DeletedAt",
  212. GoFieldType: "null.Time",
  213. JSONFieldName: "deleted_at",
  214. ProtobufFieldName: "deleted_at",
  215. ProtobufType: "uint64",
  216. ProtobufPos: 8,
  217. },
  218. },
  219. }
  220. // TableName sets the insert table name for this struct type
  221. func (s *Setting) TableName() string {
  222. return "setting"
  223. }
  224. // BeforeSave invoked before saving, return an error if field is not populated.
  225. func (s *Setting) BeforeSave(*gorm.DB) error {
  226. return nil
  227. }
  228. // Prepare invoked before saving, can be used to populate fields etc.
  229. func (s *Setting) Prepare() {
  230. }
  231. // Validate invoked before performing action, return an error if field is not populated.
  232. func (s *Setting) Validate(action Action) error {
  233. return nil
  234. }
  235. // TableInfo return table meta data
  236. func (s *Setting) TableInfo() *TableInfo {
  237. return settingTableInfo
  238. }