user_like.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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_like` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `is_like` tinyint(4) NOT NULL DEFAULT '0',
  21. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  22. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  23. `deleted_at` timestamp NULL DEFAULT NULL,
  24. `user_id` bigint(20) unsigned NOT NULL,
  25. `token_id` bigint(20) unsigned NOT NULL,
  26. PRIMARY KEY (`id`),
  27. UNIQUE KEY `id_UNIQUE` (`id`),
  28. KEY `fk_user_like_user1_idx` (`user_id`),
  29. KEY `fk_user_like_token1_idx` (`token_id`),
  30. CONSTRAINT `fk_user_like_token1` FOREIGN KEY (`token_id`) REFERENCES `token` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  31. CONSTRAINT `fk_user_like_user1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  32. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  33. JSON Sample
  34. -------------------------------------
  35. { "id": 21, "is_like": 0, "created_at": "2293-03-02T09:26:56.685703114+09:00", "updated_at": "2294-11-15T21:28:28.813340144+09:00", "deleted_at": "2202-11-01T08:41:19.156484638+09:00", "user_id": 44, "token_id": 79}
  36. Comments
  37. -------------------------------------
  38. [ 0] column is set for unsigned
  39. [ 5] column is set for unsigned
  40. [ 6] column is set for unsigned
  41. */
  42. // UserLike struct is a row record of the user_like table in the metarare database
  43. type UserLike struct {
  44. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  45. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  46. //[ 1] is_like tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  47. IsLike int32 `gorm:"column:is_like;type:tinyint;default:0;" json:"is_like"`
  48. //[ 2] 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. //[ 3] 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. //[ 4] 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. //[ 5] user_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  55. UserID uint64 `gorm:"column:user_id;type:ubigint;" json:"user_id"`
  56. //[ 6] token_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  57. TokenID uint64 `gorm:"column:token_id;type:ubigint;" json:"token_id"`
  58. User User
  59. Token Token
  60. }
  61. var user_likeTableInfo = &TableInfo{
  62. Name: "user_like",
  63. Columns: []*ColumnInfo{
  64. &ColumnInfo{
  65. Index: 0,
  66. Name: "id",
  67. Comment: ``,
  68. Notes: `column is set for unsigned`,
  69. Nullable: false,
  70. DatabaseTypeName: "ubigint",
  71. DatabaseTypePretty: "ubigint",
  72. IsPrimaryKey: true,
  73. IsAutoIncrement: true,
  74. IsArray: false,
  75. ColumnType: "ubigint",
  76. ColumnLength: -1,
  77. GoFieldName: "ID",
  78. GoFieldType: "uint64",
  79. JSONFieldName: "id",
  80. ProtobufFieldName: "id",
  81. ProtobufType: "uint64",
  82. ProtobufPos: 1,
  83. },
  84. &ColumnInfo{
  85. Index: 1,
  86. Name: "is_like",
  87. Comment: ``,
  88. Notes: ``,
  89. Nullable: false,
  90. DatabaseTypeName: "tinyint",
  91. DatabaseTypePretty: "tinyint",
  92. IsPrimaryKey: false,
  93. IsAutoIncrement: false,
  94. IsArray: false,
  95. ColumnType: "tinyint",
  96. ColumnLength: -1,
  97. GoFieldName: "IsLike",
  98. GoFieldType: "int32",
  99. JSONFieldName: "is_like",
  100. ProtobufFieldName: "is_like",
  101. ProtobufType: "int32",
  102. ProtobufPos: 2,
  103. },
  104. &ColumnInfo{
  105. Index: 2,
  106. Name: "created_at",
  107. Comment: ``,
  108. Notes: ``,
  109. Nullable: false,
  110. DatabaseTypeName: "timestamp",
  111. DatabaseTypePretty: "timestamp",
  112. IsPrimaryKey: false,
  113. IsAutoIncrement: false,
  114. IsArray: false,
  115. ColumnType: "timestamp",
  116. ColumnLength: -1,
  117. GoFieldName: "CreatedAt",
  118. GoFieldType: "time.Time",
  119. JSONFieldName: "created_at",
  120. ProtobufFieldName: "created_at",
  121. ProtobufType: "uint64",
  122. ProtobufPos: 3,
  123. },
  124. &ColumnInfo{
  125. Index: 3,
  126. Name: "updated_at",
  127. Comment: ``,
  128. Notes: ``,
  129. Nullable: false,
  130. DatabaseTypeName: "timestamp",
  131. DatabaseTypePretty: "timestamp",
  132. IsPrimaryKey: false,
  133. IsAutoIncrement: false,
  134. IsArray: false,
  135. ColumnType: "timestamp",
  136. ColumnLength: -1,
  137. GoFieldName: "UpdatedAt",
  138. GoFieldType: "time.Time",
  139. JSONFieldName: "updated_at",
  140. ProtobufFieldName: "updated_at",
  141. ProtobufType: "uint64",
  142. ProtobufPos: 4,
  143. },
  144. &ColumnInfo{
  145. Index: 4,
  146. Name: "deleted_at",
  147. Comment: ``,
  148. Notes: ``,
  149. Nullable: true,
  150. DatabaseTypeName: "timestamp",
  151. DatabaseTypePretty: "timestamp",
  152. IsPrimaryKey: false,
  153. IsAutoIncrement: false,
  154. IsArray: false,
  155. ColumnType: "timestamp",
  156. ColumnLength: -1,
  157. GoFieldName: "DeletedAt",
  158. GoFieldType: "null.Time",
  159. JSONFieldName: "deleted_at",
  160. ProtobufFieldName: "deleted_at",
  161. ProtobufType: "uint64",
  162. ProtobufPos: 5,
  163. },
  164. &ColumnInfo{
  165. Index: 5,
  166. Name: "user_id",
  167. Comment: ``,
  168. Notes: `column is set for unsigned`,
  169. Nullable: false,
  170. DatabaseTypeName: "ubigint",
  171. DatabaseTypePretty: "ubigint",
  172. IsPrimaryKey: false,
  173. IsAutoIncrement: false,
  174. IsArray: false,
  175. ColumnType: "ubigint",
  176. ColumnLength: -1,
  177. GoFieldName: "UserID",
  178. GoFieldType: "uint64",
  179. JSONFieldName: "user_id",
  180. ProtobufFieldName: "user_id",
  181. ProtobufType: "uint64",
  182. ProtobufPos: 6,
  183. },
  184. &ColumnInfo{
  185. Index: 6,
  186. Name: "token_id",
  187. Comment: ``,
  188. Notes: `column is set for unsigned`,
  189. Nullable: false,
  190. DatabaseTypeName: "ubigint",
  191. DatabaseTypePretty: "ubigint",
  192. IsPrimaryKey: false,
  193. IsAutoIncrement: false,
  194. IsArray: false,
  195. ColumnType: "ubigint",
  196. ColumnLength: -1,
  197. GoFieldName: "TokenID",
  198. GoFieldType: "uint64",
  199. JSONFieldName: "token_id",
  200. ProtobufFieldName: "token_id",
  201. ProtobufType: "uint64",
  202. ProtobufPos: 7,
  203. },
  204. },
  205. }
  206. // TableName sets the insert table name for this struct type
  207. func (u *UserLike) TableName() string {
  208. return "user_like"
  209. }
  210. // BeforeSave invoked before saving, return an error if field is not populated.
  211. func (u *UserLike) BeforeSave(*gorm.DB) error {
  212. return nil
  213. }
  214. // Prepare invoked before saving, can be used to populate fields etc.
  215. func (u *UserLike) Prepare() {
  216. }
  217. // Validate invoked before performing action, return an error if field is not populated.
  218. func (u *UserLike) Validate(action Action) error {
  219. return nil
  220. }
  221. // TableInfo return table meta data
  222. func (u *UserLike) TableInfo() *TableInfo {
  223. return user_likeTableInfo
  224. }