child.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "sikey/w303a/http/internal/data/ent/child"
  6. "strings"
  7. "time"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. "github.com/google/uuid"
  11. )
  12. // Child is the model entity for the Child schema.
  13. type Child struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. // 孩子ID
  17. ID uuid.UUID `json:"id,omitempty"`
  18. // 创建时间
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // 更新时间
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // 删除时间
  23. DeletedAt *time.Time `json:"deleted_at,omitempty"`
  24. // 名字
  25. ChildName string `json:"child_name,omitempty"`
  26. // 手机号码
  27. PhoneNumber string `json:"phone_number,omitempty"`
  28. // 国际码
  29. AreaCode string `json:"area_code,omitempty"`
  30. // 头像地址
  31. Avatar *string `json:"avatar,omitempty"`
  32. // 性别 2: 男 3: 女
  33. Gender int8 `json:"gender,omitempty"`
  34. // 身高 单位: cm
  35. Height int32 `json:"height,omitempty"`
  36. // 体重 单位:g
  37. Weight int32 `json:"weight,omitempty"`
  38. // 生日
  39. Birthday *string `json:"birthday,omitempty"`
  40. // 是否拒接陌生人
  41. IsEnableBlockUnknownCall bool `json:"is_enable_block_unknown_call,omitempty"`
  42. // 是否开启围栏
  43. IsEnableFence bool `json:"is_enable_fence,omitempty"`
  44. // Edges holds the relations/edges for other nodes in the graph.
  45. // The values are being populated by the ChildQuery when eager-loading is set.
  46. Edges ChildEdges `json:"edges"`
  47. selectValues sql.SelectValues
  48. }
  49. // ChildEdges holds the relations/edges for other nodes in the graph.
  50. type ChildEdges struct {
  51. // ChildRefs holds the value of the childRefs edge.
  52. ChildRefs []*ChildRef `json:"childRefs,omitempty"`
  53. // ChildDevice holds the value of the childDevice edge.
  54. ChildDevice []*DeviceBind `json:"childDevice,omitempty"`
  55. // ChildContacts holds the value of the childContacts edge.
  56. ChildContacts []*Contacts `json:"childContacts,omitempty"`
  57. // loadedTypes holds the information for reporting if a
  58. // type was loaded (or requested) in eager-loading or not.
  59. loadedTypes [3]bool
  60. }
  61. // ChildRefsOrErr returns the ChildRefs value or an error if the edge
  62. // was not loaded in eager-loading.
  63. func (e ChildEdges) ChildRefsOrErr() ([]*ChildRef, error) {
  64. if e.loadedTypes[0] {
  65. return e.ChildRefs, nil
  66. }
  67. return nil, &NotLoadedError{edge: "childRefs"}
  68. }
  69. // ChildDeviceOrErr returns the ChildDevice value or an error if the edge
  70. // was not loaded in eager-loading.
  71. func (e ChildEdges) ChildDeviceOrErr() ([]*DeviceBind, error) {
  72. if e.loadedTypes[1] {
  73. return e.ChildDevice, nil
  74. }
  75. return nil, &NotLoadedError{edge: "childDevice"}
  76. }
  77. // ChildContactsOrErr returns the ChildContacts value or an error if the edge
  78. // was not loaded in eager-loading.
  79. func (e ChildEdges) ChildContactsOrErr() ([]*Contacts, error) {
  80. if e.loadedTypes[2] {
  81. return e.ChildContacts, nil
  82. }
  83. return nil, &NotLoadedError{edge: "childContacts"}
  84. }
  85. // scanValues returns the types for scanning values from sql.Rows.
  86. func (*Child) scanValues(columns []string) ([]any, error) {
  87. values := make([]any, len(columns))
  88. for i := range columns {
  89. switch columns[i] {
  90. case child.FieldIsEnableBlockUnknownCall, child.FieldIsEnableFence:
  91. values[i] = new(sql.NullBool)
  92. case child.FieldGender, child.FieldHeight, child.FieldWeight:
  93. values[i] = new(sql.NullInt64)
  94. case child.FieldChildName, child.FieldPhoneNumber, child.FieldAreaCode, child.FieldAvatar, child.FieldBirthday:
  95. values[i] = new(sql.NullString)
  96. case child.FieldCreatedAt, child.FieldUpdatedAt, child.FieldDeletedAt:
  97. values[i] = new(sql.NullTime)
  98. case child.FieldID:
  99. values[i] = new(uuid.UUID)
  100. default:
  101. values[i] = new(sql.UnknownType)
  102. }
  103. }
  104. return values, nil
  105. }
  106. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  107. // to the Child fields.
  108. func (c *Child) assignValues(columns []string, values []any) error {
  109. if m, n := len(values), len(columns); m < n {
  110. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  111. }
  112. for i := range columns {
  113. switch columns[i] {
  114. case child.FieldID:
  115. if value, ok := values[i].(*uuid.UUID); !ok {
  116. return fmt.Errorf("unexpected type %T for field id", values[i])
  117. } else if value != nil {
  118. c.ID = *value
  119. }
  120. case child.FieldCreatedAt:
  121. if value, ok := values[i].(*sql.NullTime); !ok {
  122. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  123. } else if value.Valid {
  124. c.CreatedAt = value.Time
  125. }
  126. case child.FieldUpdatedAt:
  127. if value, ok := values[i].(*sql.NullTime); !ok {
  128. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  129. } else if value.Valid {
  130. c.UpdatedAt = value.Time
  131. }
  132. case child.FieldDeletedAt:
  133. if value, ok := values[i].(*sql.NullTime); !ok {
  134. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  135. } else if value.Valid {
  136. c.DeletedAt = new(time.Time)
  137. *c.DeletedAt = value.Time
  138. }
  139. case child.FieldChildName:
  140. if value, ok := values[i].(*sql.NullString); !ok {
  141. return fmt.Errorf("unexpected type %T for field child_name", values[i])
  142. } else if value.Valid {
  143. c.ChildName = value.String
  144. }
  145. case child.FieldPhoneNumber:
  146. if value, ok := values[i].(*sql.NullString); !ok {
  147. return fmt.Errorf("unexpected type %T for field phone_number", values[i])
  148. } else if value.Valid {
  149. c.PhoneNumber = value.String
  150. }
  151. case child.FieldAreaCode:
  152. if value, ok := values[i].(*sql.NullString); !ok {
  153. return fmt.Errorf("unexpected type %T for field area_code", values[i])
  154. } else if value.Valid {
  155. c.AreaCode = value.String
  156. }
  157. case child.FieldAvatar:
  158. if value, ok := values[i].(*sql.NullString); !ok {
  159. return fmt.Errorf("unexpected type %T for field avatar", values[i])
  160. } else if value.Valid {
  161. c.Avatar = new(string)
  162. *c.Avatar = value.String
  163. }
  164. case child.FieldGender:
  165. if value, ok := values[i].(*sql.NullInt64); !ok {
  166. return fmt.Errorf("unexpected type %T for field gender", values[i])
  167. } else if value.Valid {
  168. c.Gender = int8(value.Int64)
  169. }
  170. case child.FieldHeight:
  171. if value, ok := values[i].(*sql.NullInt64); !ok {
  172. return fmt.Errorf("unexpected type %T for field height", values[i])
  173. } else if value.Valid {
  174. c.Height = int32(value.Int64)
  175. }
  176. case child.FieldWeight:
  177. if value, ok := values[i].(*sql.NullInt64); !ok {
  178. return fmt.Errorf("unexpected type %T for field weight", values[i])
  179. } else if value.Valid {
  180. c.Weight = int32(value.Int64)
  181. }
  182. case child.FieldBirthday:
  183. if value, ok := values[i].(*sql.NullString); !ok {
  184. return fmt.Errorf("unexpected type %T for field birthday", values[i])
  185. } else if value.Valid {
  186. c.Birthday = new(string)
  187. *c.Birthday = value.String
  188. }
  189. case child.FieldIsEnableBlockUnknownCall:
  190. if value, ok := values[i].(*sql.NullBool); !ok {
  191. return fmt.Errorf("unexpected type %T for field is_enable_block_unknown_call", values[i])
  192. } else if value.Valid {
  193. c.IsEnableBlockUnknownCall = value.Bool
  194. }
  195. case child.FieldIsEnableFence:
  196. if value, ok := values[i].(*sql.NullBool); !ok {
  197. return fmt.Errorf("unexpected type %T for field is_enable_fence", values[i])
  198. } else if value.Valid {
  199. c.IsEnableFence = value.Bool
  200. }
  201. default:
  202. c.selectValues.Set(columns[i], values[i])
  203. }
  204. }
  205. return nil
  206. }
  207. // Value returns the ent.Value that was dynamically selected and assigned to the Child.
  208. // This includes values selected through modifiers, order, etc.
  209. func (c *Child) Value(name string) (ent.Value, error) {
  210. return c.selectValues.Get(name)
  211. }
  212. // QueryChildRefs queries the "childRefs" edge of the Child entity.
  213. func (c *Child) QueryChildRefs() *ChildRefQuery {
  214. return NewChildClient(c.config).QueryChildRefs(c)
  215. }
  216. // QueryChildDevice queries the "childDevice" edge of the Child entity.
  217. func (c *Child) QueryChildDevice() *DeviceBindQuery {
  218. return NewChildClient(c.config).QueryChildDevice(c)
  219. }
  220. // QueryChildContacts queries the "childContacts" edge of the Child entity.
  221. func (c *Child) QueryChildContacts() *ContactsQuery {
  222. return NewChildClient(c.config).QueryChildContacts(c)
  223. }
  224. // Update returns a builder for updating this Child.
  225. // Note that you need to call Child.Unwrap() before calling this method if this Child
  226. // was returned from a transaction, and the transaction was committed or rolled back.
  227. func (c *Child) Update() *ChildUpdateOne {
  228. return NewChildClient(c.config).UpdateOne(c)
  229. }
  230. // Unwrap unwraps the Child entity that was returned from a transaction after it was closed,
  231. // so that all future queries will be executed through the driver which created the transaction.
  232. func (c *Child) Unwrap() *Child {
  233. _tx, ok := c.config.driver.(*txDriver)
  234. if !ok {
  235. panic("ent: Child is not a transactional entity")
  236. }
  237. c.config.driver = _tx.drv
  238. return c
  239. }
  240. // String implements the fmt.Stringer.
  241. func (c *Child) String() string {
  242. var builder strings.Builder
  243. builder.WriteString("Child(")
  244. builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
  245. builder.WriteString("created_at=")
  246. builder.WriteString(c.CreatedAt.Format(time.ANSIC))
  247. builder.WriteString(", ")
  248. builder.WriteString("updated_at=")
  249. builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
  250. builder.WriteString(", ")
  251. if v := c.DeletedAt; v != nil {
  252. builder.WriteString("deleted_at=")
  253. builder.WriteString(v.Format(time.ANSIC))
  254. }
  255. builder.WriteString(", ")
  256. builder.WriteString("child_name=")
  257. builder.WriteString(c.ChildName)
  258. builder.WriteString(", ")
  259. builder.WriteString("phone_number=")
  260. builder.WriteString(c.PhoneNumber)
  261. builder.WriteString(", ")
  262. builder.WriteString("area_code=")
  263. builder.WriteString(c.AreaCode)
  264. builder.WriteString(", ")
  265. if v := c.Avatar; v != nil {
  266. builder.WriteString("avatar=")
  267. builder.WriteString(*v)
  268. }
  269. builder.WriteString(", ")
  270. builder.WriteString("gender=")
  271. builder.WriteString(fmt.Sprintf("%v", c.Gender))
  272. builder.WriteString(", ")
  273. builder.WriteString("height=")
  274. builder.WriteString(fmt.Sprintf("%v", c.Height))
  275. builder.WriteString(", ")
  276. builder.WriteString("weight=")
  277. builder.WriteString(fmt.Sprintf("%v", c.Weight))
  278. builder.WriteString(", ")
  279. if v := c.Birthday; v != nil {
  280. builder.WriteString("birthday=")
  281. builder.WriteString(*v)
  282. }
  283. builder.WriteString(", ")
  284. builder.WriteString("is_enable_block_unknown_call=")
  285. builder.WriteString(fmt.Sprintf("%v", c.IsEnableBlockUnknownCall))
  286. builder.WriteString(", ")
  287. builder.WriteString("is_enable_fence=")
  288. builder.WriteString(fmt.Sprintf("%v", c.IsEnableFence))
  289. builder.WriteByte(')')
  290. return builder.String()
  291. }
  292. // Childs is a parsable slice of Child.
  293. type Childs []*Child