user_profile.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 `user_profile` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `user_id` bigint(20) unsigned NOT NULL,
  21. `name` varchar(128) COLLATE utf8mb4_bin DEFAULT NULL,
  22. `description` text COLLATE utf8mb4_bin,
  23. `thumbnail_image` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  24. `cover_image` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  25. `twitter` varchar(128) COLLATE utf8mb4_bin DEFAULT NULL,
  26. `phone` varchar(128) COLLATE utf8mb4_bin DEFAULT 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. UNIQUE KEY `name_UNIQUE` (`name`),
  33. KEY `fk_user_profile_user1_idx` (`user_id`),
  34. CONSTRAINT `fk_user_profile_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  35. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  36. JSON Sample
  37. -------------------------------------
  38. { "id": 27, "user_id": 81, "name": "rFyDaRrWKkIBaWbBrSNUVFgcR", "description": "ZrshrLIUeHKyWXIaBOCvqxBiL", "thumbnail_image": "IqOPjBWjewHSrUiPfYjhlELCh", "cover_image": "haMZlpofHcflluQtJVUapfaVF", "twitter": "mcilISbCjSmiJYCBvxMIUgyMm", "phone": "lIxmtyEtdmcUPiqSnVvvaFtEZ", "created_at": "2285-03-04T03:11:06.107023701+09:00", "updated_at": "2164-11-10T10:42:59.086610084+09:00", "deleted_at": "2288-06-20T05:33:35.637597276+09:00"}
  39. Comments
  40. -------------------------------------
  41. [ 0] column is set for unsigned
  42. [ 1] column is set for unsigned
  43. */
  44. // UserProfile struct is a row record of the user_profile table in the metarare database
  45. type UserProfile struct {
  46. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  47. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  48. //[ 1] user_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  49. UserID uint64 `gorm:"column:user_id;type:ubigint;" json:"user_id"`
  50. //[ 2] name varchar(128) null: true primary: false isArray: false auto: false col: varchar len: 128 default: []
  51. Name null.String `gorm:"column:name;type:varchar;size:128;" json:"name"`
  52. //[ 3] description text(65535) null: true primary: false isArray: false auto: false col: text len: 65535 default: []
  53. Description null.String `gorm:"column:description;type:text;size:65535;" json:"description"`
  54. //[ 4] thumbnail_image varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  55. ThumbnailImage null.String `gorm:"column:thumbnail_image;type:varchar;size:256;" json:"thumbnail_image"`
  56. //[ 5] cover_image varchar(256) null: true primary: false isArray: false auto: false col: varchar len: 256 default: []
  57. CoverImage null.String `gorm:"column:cover_image;type:varchar;size:256;" json:"cover_image"`
  58. //[ 6] twitter varchar(128) null: true primary: false isArray: false auto: false col: varchar len: 128 default: []
  59. Twitter null.String `gorm:"column:twitter;type:varchar;size:128;" json:"twitter"`
  60. //[ 7] phone varchar(128) null: true primary: false isArray: false auto: false col: varchar len: 128 default: []
  61. Phone null.String `gorm:"column:phone;type:varchar;size:128;" json:"phone"`
  62. //[ 8] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  63. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  64. //[ 9] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  65. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  66. //[10] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  67. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  68. }
  69. var user_profileTableInfo = &TableInfo{
  70. Name: "user_profile",
  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: "user_id",
  95. Comment: ``,
  96. Notes: `column is set for unsigned`,
  97. Nullable: false,
  98. DatabaseTypeName: "ubigint",
  99. DatabaseTypePretty: "ubigint",
  100. IsPrimaryKey: false,
  101. IsAutoIncrement: false,
  102. IsArray: false,
  103. ColumnType: "ubigint",
  104. ColumnLength: -1,
  105. GoFieldName: "UserID",
  106. GoFieldType: "uint64",
  107. JSONFieldName: "user_id",
  108. ProtobufFieldName: "user_id",
  109. ProtobufType: "uint64",
  110. ProtobufPos: 2,
  111. },
  112. &ColumnInfo{
  113. Index: 2,
  114. Name: "name",
  115. Comment: ``,
  116. Notes: ``,
  117. Nullable: true,
  118. DatabaseTypeName: "varchar",
  119. DatabaseTypePretty: "varchar(128)",
  120. IsPrimaryKey: false,
  121. IsAutoIncrement: false,
  122. IsArray: false,
  123. ColumnType: "varchar",
  124. ColumnLength: 128,
  125. GoFieldName: "Name",
  126. GoFieldType: "null.String",
  127. JSONFieldName: "name",
  128. ProtobufFieldName: "name",
  129. ProtobufType: "string",
  130. ProtobufPos: 3,
  131. },
  132. &ColumnInfo{
  133. Index: 3,
  134. Name: "description",
  135. Comment: ``,
  136. Notes: ``,
  137. Nullable: true,
  138. DatabaseTypeName: "text",
  139. DatabaseTypePretty: "text(65535)",
  140. IsPrimaryKey: false,
  141. IsAutoIncrement: false,
  142. IsArray: false,
  143. ColumnType: "text",
  144. ColumnLength: 65535,
  145. GoFieldName: "Description",
  146. GoFieldType: "null.String",
  147. JSONFieldName: "description",
  148. ProtobufFieldName: "description",
  149. ProtobufType: "string",
  150. ProtobufPos: 4,
  151. },
  152. &ColumnInfo{
  153. Index: 4,
  154. Name: "thumbnail_image",
  155. Comment: ``,
  156. Notes: ``,
  157. Nullable: true,
  158. DatabaseTypeName: "varchar",
  159. DatabaseTypePretty: "varchar(256)",
  160. IsPrimaryKey: false,
  161. IsAutoIncrement: false,
  162. IsArray: false,
  163. ColumnType: "varchar",
  164. ColumnLength: 256,
  165. GoFieldName: "ThumbnailImage",
  166. GoFieldType: "null.String",
  167. JSONFieldName: "thumbnail_image",
  168. ProtobufFieldName: "thumbnail_image",
  169. ProtobufType: "string",
  170. ProtobufPos: 5,
  171. },
  172. &ColumnInfo{
  173. Index: 5,
  174. Name: "cover_image",
  175. Comment: ``,
  176. Notes: ``,
  177. Nullable: true,
  178. DatabaseTypeName: "varchar",
  179. DatabaseTypePretty: "varchar(256)",
  180. IsPrimaryKey: false,
  181. IsAutoIncrement: false,
  182. IsArray: false,
  183. ColumnType: "varchar",
  184. ColumnLength: 256,
  185. GoFieldName: "CoverImage",
  186. GoFieldType: "null.String",
  187. JSONFieldName: "cover_image",
  188. ProtobufFieldName: "cover_image",
  189. ProtobufType: "string",
  190. ProtobufPos: 6,
  191. },
  192. &ColumnInfo{
  193. Index: 6,
  194. Name: "twitter",
  195. Comment: ``,
  196. Notes: ``,
  197. Nullable: true,
  198. DatabaseTypeName: "varchar",
  199. DatabaseTypePretty: "varchar(128)",
  200. IsPrimaryKey: false,
  201. IsAutoIncrement: false,
  202. IsArray: false,
  203. ColumnType: "varchar",
  204. ColumnLength: 128,
  205. GoFieldName: "Twitter",
  206. GoFieldType: "null.String",
  207. JSONFieldName: "twitter",
  208. ProtobufFieldName: "twitter",
  209. ProtobufType: "string",
  210. ProtobufPos: 7,
  211. },
  212. &ColumnInfo{
  213. Index: 7,
  214. Name: "phone",
  215. Comment: ``,
  216. Notes: ``,
  217. Nullable: true,
  218. DatabaseTypeName: "varchar",
  219. DatabaseTypePretty: "varchar(128)",
  220. IsPrimaryKey: false,
  221. IsAutoIncrement: false,
  222. IsArray: false,
  223. ColumnType: "varchar",
  224. ColumnLength: 128,
  225. GoFieldName: "Phone",
  226. GoFieldType: "null.String",
  227. JSONFieldName: "phone",
  228. ProtobufFieldName: "phone",
  229. ProtobufType: "string",
  230. ProtobufPos: 8,
  231. },
  232. &ColumnInfo{
  233. Index: 8,
  234. Name: "created_at",
  235. Comment: ``,
  236. Notes: ``,
  237. Nullable: false,
  238. DatabaseTypeName: "timestamp",
  239. DatabaseTypePretty: "timestamp",
  240. IsPrimaryKey: false,
  241. IsAutoIncrement: false,
  242. IsArray: false,
  243. ColumnType: "timestamp",
  244. ColumnLength: -1,
  245. GoFieldName: "CreatedAt",
  246. GoFieldType: "time.Time",
  247. JSONFieldName: "created_at",
  248. ProtobufFieldName: "created_at",
  249. ProtobufType: "uint64",
  250. ProtobufPos: 9,
  251. },
  252. &ColumnInfo{
  253. Index: 9,
  254. Name: "updated_at",
  255. Comment: ``,
  256. Notes: ``,
  257. Nullable: false,
  258. DatabaseTypeName: "timestamp",
  259. DatabaseTypePretty: "timestamp",
  260. IsPrimaryKey: false,
  261. IsAutoIncrement: false,
  262. IsArray: false,
  263. ColumnType: "timestamp",
  264. ColumnLength: -1,
  265. GoFieldName: "UpdatedAt",
  266. GoFieldType: "time.Time",
  267. JSONFieldName: "updated_at",
  268. ProtobufFieldName: "updated_at",
  269. ProtobufType: "uint64",
  270. ProtobufPos: 10,
  271. },
  272. &ColumnInfo{
  273. Index: 10,
  274. Name: "deleted_at",
  275. Comment: ``,
  276. Notes: ``,
  277. Nullable: true,
  278. DatabaseTypeName: "timestamp",
  279. DatabaseTypePretty: "timestamp",
  280. IsPrimaryKey: false,
  281. IsAutoIncrement: false,
  282. IsArray: false,
  283. ColumnType: "timestamp",
  284. ColumnLength: -1,
  285. GoFieldName: "DeletedAt",
  286. GoFieldType: "null.Time",
  287. JSONFieldName: "deleted_at",
  288. ProtobufFieldName: "deleted_at",
  289. ProtobufType: "uint64",
  290. ProtobufPos: 11,
  291. },
  292. },
  293. }
  294. // TableName sets the insert table name for this struct type
  295. func (u *UserProfile) TableName() string {
  296. return "user_profile"
  297. }
  298. // BeforeSave invoked before saving, return an error if field is not populated.
  299. func (u *UserProfile) BeforeSave(*gorm.DB) error {
  300. return nil
  301. }
  302. // Prepare invoked before saving, can be used to populate fields etc.
  303. func (u *UserProfile) Prepare() {
  304. }
  305. // Validate invoked before performing action, return an error if field is not populated.
  306. func (u *UserProfile) Validate(action Action) error {
  307. return nil
  308. }
  309. // TableInfo return table meta data
  310. func (u *UserProfile) TableInfo() *TableInfo {
  311. return user_profileTableInfo
  312. }