/examples/entcpkg/ent/user.go

https://github.com/facebookincubator/ent · Go · 83 lines · 53 code · 13 blank · 17 comment · 4 complexity · 7224091dd0830c8d51e4ce8a7db48bfc MD5 · raw file

  1. // Copyright 2019-present Facebook Inc. All rights reserved.
  2. // This source code is licensed under the Apache 2.0 license found
  3. // in the LICENSE file in the root directory of this source tree.
  4. // Code generated by entc, DO NOT EDIT.
  5. package ent
  6. import (
  7. "fmt"
  8. "strings"
  9. "github.com/facebook/ent/dialect/sql"
  10. "github.com/facebook/ent/examples/entcpkg/ent/user"
  11. )
  12. // User is the model entity for the User schema.
  13. type User struct {
  14. config
  15. // ID of the ent.
  16. ID int `json:"id,omitempty"`
  17. // StaticField defined by templates (titled STATICFIELD).
  18. StaticField string `json:"static_field,omitempty"`
  19. }
  20. // scanValues returns the types for scanning values from sql.Rows.
  21. func (*User) scanValues() []interface{} {
  22. return []interface{}{
  23. &sql.NullInt64{}, // id
  24. }
  25. }
  26. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  27. // to the User fields.
  28. func (u *User) assignValues(values ...interface{}) error {
  29. if m, n := len(values), len(user.Columns); m < n {
  30. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  31. }
  32. value, ok := values[0].(*sql.NullInt64)
  33. if !ok {
  34. return fmt.Errorf("unexpected type %T for field id", value)
  35. }
  36. u.ID = int(value.Int64)
  37. values = values[1:]
  38. return nil
  39. }
  40. // Update returns a builder for updating this User.
  41. // Note that, you need to call User.Unwrap() before calling this method, if this User
  42. // was returned from a transaction, and the transaction was committed or rolled back.
  43. func (u *User) Update() *UserUpdateOne {
  44. return (&UserClient{config: u.config}).UpdateOne(u)
  45. }
  46. // Unwrap unwraps the entity that was returned from a transaction after it was closed,
  47. // so that all next queries will be executed through the driver which created the transaction.
  48. func (u *User) Unwrap() *User {
  49. tx, ok := u.config.driver.(*txDriver)
  50. if !ok {
  51. panic("ent: User is not a transactional entity")
  52. }
  53. u.config.driver = tx.drv
  54. return u
  55. }
  56. // String implements the fmt.Stringer.
  57. func (u *User) String() string {
  58. var builder strings.Builder
  59. builder.WriteString("User(")
  60. builder.WriteString(fmt.Sprintf("id=%v", u.ID))
  61. builder.WriteByte(')')
  62. return builder.String()
  63. }
  64. // Users is a parsable slice of User.
  65. type Users []*User
  66. func (u Users) config(cfg config) {
  67. for _i := range u {
  68. u[_i].config = cfg
  69. }
  70. }