Add a mixin for time fields

This commit is contained in:
Achim Rohn
2025-09-12 09:31:21 +02:00
parent 6cbd155db6
commit a817f7550b
25 changed files with 1086 additions and 336 deletions
+25
View File
@@ -6,6 +6,7 @@ import (
"ersteller-lib/schema/ent/example/ent/group" "ersteller-lib/schema/ent/example/ent/group"
"fmt" "fmt"
"strings" "strings"
"time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
@@ -16,6 +17,10 @@ type Group struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Name holds the value of the "name" field. // Name holds the value of the "name" field.
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// Edges holds the relations/edges for other nodes in the graph. // Edges holds the relations/edges for other nodes in the graph.
@@ -62,6 +67,8 @@ func (*Group) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case group.FieldName: case group.FieldName:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
case group.FieldCreatedAt, group.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default: default:
values[i] = new(sql.UnknownType) values[i] = new(sql.UnknownType)
} }
@@ -83,6 +90,18 @@ func (_m *Group) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case group.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case group.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
case group.FieldName: case group.FieldName:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i]) return fmt.Errorf("unexpected type %T for field name", values[i])
@@ -135,6 +154,12 @@ func (_m *Group) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("Group(") builder.WriteString("Group(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("name=") builder.WriteString("name=")
builder.WriteString(_m.Name) builder.WriteString(_m.Name)
builder.WriteByte(')') builder.WriteByte(')')
+24
View File
@@ -3,6 +3,8 @@
package group package group
import ( import (
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
) )
@@ -12,6 +14,10 @@ const (
Label = "group" Label = "group"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldName holds the string denoting the name field in the database. // FieldName holds the string denoting the name field in the database.
FieldName = "name" FieldName = "name"
// EdgeUsers holds the string denoting the users edge name in mutations. // EdgeUsers holds the string denoting the users edge name in mutations.
@@ -37,6 +43,8 @@ const (
// Columns holds all SQL columns for group fields. // Columns holds all SQL columns for group fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldName, FieldName,
} }
@@ -57,6 +65,12 @@ func ValidColumn(column string) bool {
} }
var ( var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultName holds the default value on creation for the "name" field. // DefaultName holds the default value on creation for the "name" field.
DefaultName string DefaultName string
) )
@@ -69,6 +83,16 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByName orders the results by the name field. // ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption { func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc() return sql.OrderByField(FieldName, opts...).ToFunc()
+91
View File
@@ -4,6 +4,7 @@ package group
import ( import (
"ersteller-lib/schema/ent/example/ent/predicate" "ersteller-lib/schema/ent/example/ent/predicate"
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
@@ -54,11 +55,101 @@ func IDLTE(id int) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldID, id)) return predicate.Group(sql.FieldLTE(FieldID, id))
} }
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ. // Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Group { func Name(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldName, v)) return predicate.Group(sql.FieldEQ(FieldName, v))
} }
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Group {
return predicate.Group(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Group {
return predicate.Group(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Group {
return predicate.Group(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Group {
return predicate.Group(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Group {
return predicate.Group(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Group {
return predicate.Group(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Group {
return predicate.Group(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Group {
return predicate.Group(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Group {
return predicate.Group(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Group {
return predicate.Group(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldUpdatedAt, v))
}
// NameEQ applies the EQ predicate on the "name" field. // NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Group { func NameEQ(v string) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldName, v)) return predicate.Group(sql.FieldEQ(FieldName, v))
+51
View File
@@ -9,6 +9,7 @@ import (
"ersteller-lib/schema/ent/example/ent/todo" "ersteller-lib/schema/ent/example/ent/todo"
"ersteller-lib/schema/ent/example/ent/user" "ersteller-lib/schema/ent/example/ent/user"
"fmt" "fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
@@ -21,6 +22,34 @@ type GroupCreate struct {
hooks []Hook hooks []Hook
} }
// SetCreatedAt sets the "created_at" field.
func (_c *GroupCreate) SetCreatedAt(v time.Time) *GroupCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *GroupCreate) SetNillableCreatedAt(v *time.Time) *GroupCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *GroupCreate) SetUpdatedAt(v time.Time) *GroupCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *GroupCreate) SetNillableUpdatedAt(v *time.Time) *GroupCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetName sets the "name" field. // SetName sets the "name" field.
func (_c *GroupCreate) SetName(v string) *GroupCreate { func (_c *GroupCreate) SetName(v string) *GroupCreate {
_c.mutation.SetName(v) _c.mutation.SetName(v)
@@ -100,6 +129,14 @@ func (_c *GroupCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *GroupCreate) defaults() { func (_c *GroupCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := group.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := group.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Name(); !ok { if _, ok := _c.mutation.Name(); !ok {
v := group.DefaultName v := group.DefaultName
_c.mutation.SetName(v) _c.mutation.SetName(v)
@@ -108,6 +145,12 @@ func (_c *GroupCreate) defaults() {
// check runs all checks and user-defined validators on the builder. // check runs all checks and user-defined validators on the builder.
func (_c *GroupCreate) check() error { func (_c *GroupCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Group.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Group.updated_at"`)}
}
if _, ok := _c.mutation.Name(); !ok { if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)} return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)}
} }
@@ -137,6 +180,14 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_node = &Group{config: _c.config} _node = &Group{config: _c.config}
_spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(group.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.Name(); ok { if value, ok := _c.mutation.Name(); ok {
_spec.SetField(group.FieldName, field.TypeString, value) _spec.SetField(group.FieldName, field.TypeString, value)
_node.Name = value _node.Name = value
+4 -4
View File
@@ -335,12 +335,12 @@ func (_q *GroupQuery) WithTodos(opts ...func(*TodoQuery)) *GroupQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Name string `json:"name,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.Group.Query(). // client.Group.Query().
// GroupBy(group.FieldName). // GroupBy(group.FieldCreatedAt).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
@@ -358,11 +358,11 @@ func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Name string `json:"name,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// } // }
// //
// client.Group.Query(). // client.Group.Query().
// Select(group.FieldName). // Select(group.FieldCreatedAt).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *GroupQuery) Select(fields ...string) *GroupSelect { func (_q *GroupQuery) Select(fields ...string) *GroupSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)
+37
View File
@@ -10,6 +10,7 @@ import (
"ersteller-lib/schema/ent/example/ent/todo" "ersteller-lib/schema/ent/example/ent/todo"
"ersteller-lib/schema/ent/example/ent/user" "ersteller-lib/schema/ent/example/ent/user"
"fmt" "fmt"
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
@@ -29,6 +30,12 @@ func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
return _u return _u
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field. // SetName sets the "name" field.
func (_u *GroupUpdate) SetName(v string) *GroupUpdate { func (_u *GroupUpdate) SetName(v string) *GroupUpdate {
_u.mutation.SetName(v) _u.mutation.SetName(v)
@@ -122,6 +129,7 @@ func (_u *GroupUpdate) RemoveTodos(v ...*Todo) *GroupUpdate {
// Save executes the query and returns the number of nodes affected by the update operation. // Save executes the query and returns the number of nodes affected by the update operation.
func (_u *GroupUpdate) Save(ctx context.Context) (int, error) { func (_u *GroupUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
} }
@@ -147,6 +155,14 @@ func (_u *GroupUpdate) ExecX(ctx context.Context) {
} }
} }
// defaults sets the default values of the builder before save.
func (_u *GroupUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := group.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 { if ps := _u.mutation.predicates; len(ps) > 0 {
@@ -156,6 +172,9 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok { if value, ok := _u.mutation.Name(); ok {
_spec.SetField(group.FieldName, field.TypeString, value) _spec.SetField(group.FieldName, field.TypeString, value)
} }
@@ -269,6 +288,12 @@ type GroupUpdateOne struct {
mutation *GroupMutation mutation *GroupMutation
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetName sets the "name" field. // SetName sets the "name" field.
func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne { func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne {
_u.mutation.SetName(v) _u.mutation.SetName(v)
@@ -375,6 +400,7 @@ func (_u *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne
// Save executes the query and returns the updated Group entity. // Save executes the query and returns the updated Group entity.
func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
} }
@@ -400,6 +426,14 @@ func (_u *GroupUpdateOne) ExecX(ctx context.Context) {
} }
} }
// defaults sets the default values of the builder before save.
func (_u *GroupUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := group.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) { func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
id, ok := _u.mutation.ID() id, ok := _u.mutation.ID()
@@ -426,6 +460,9 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Name(); ok { if value, ok := _u.mutation.Name(); ok {
_spec.SetField(group.FieldName, field.TypeString, value) _spec.SetField(group.FieldName, field.TypeString, value)
} }
+7 -3
View File
@@ -11,6 +11,8 @@ var (
// GroupsColumns holds the columns for the "groups" table. // GroupsColumns holds the columns for the "groups" table.
GroupsColumns = []*schema.Column{ GroupsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "name", Type: field.TypeString, Default: ""}, {Name: "name", Type: field.TypeString, Default: ""},
} }
// GroupsTable holds the schema information for the "groups" table. // GroupsTable holds the schema information for the "groups" table.
@@ -22,6 +24,8 @@ var (
// TodosColumns holds the columns for the "todos" table. // TodosColumns holds the columns for the "todos" table.
TodosColumns = []*schema.Column{ TodosColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "title", Type: field.TypeString, Default: ""}, {Name: "title", Type: field.TypeString, Default: ""},
{Name: "completed", Type: field.TypeBool, Default: false}, {Name: "completed", Type: field.TypeBool, Default: false},
{Name: "todo_group", Type: field.TypeInt, Nullable: true}, {Name: "todo_group", Type: field.TypeInt, Nullable: true},
@@ -34,7 +38,7 @@ var (
ForeignKeys: []*schema.ForeignKey{ ForeignKeys: []*schema.ForeignKey{
{ {
Symbol: "todos_groups_group", Symbol: "todos_groups_group",
Columns: []*schema.Column{TodosColumns[3]}, Columns: []*schema.Column{TodosColumns[5]},
RefColumns: []*schema.Column{GroupsColumns[0]}, RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull, OnDelete: schema.SetNull,
}, },
@@ -43,10 +47,10 @@ var (
// UsersColumns holds the columns for the "users" table. // UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{ UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true}, {Name: "id", Type: field.TypeInt, Increment: true},
{Name: "email", Type: field.TypeString, Default: "unknown@localhost"},
{Name: "password", Type: field.TypeString, Default: ""},
{Name: "created_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime},
{Name: "email", Type: field.TypeString, Default: "unknown@localhost"},
{Name: "password", Type: field.TypeString, Default: ""},
} }
// UsersTable holds the schema information for the "users" table. // UsersTable holds the schema information for the "users" table.
UsersTable = &schema.Table{ UsersTable = &schema.Table{
+326 -110
View File
@@ -37,6 +37,8 @@ type GroupMutation struct {
op Op op Op
typ string typ string
id *int id *int
created_at *time.Time
updated_at *time.Time
name *string name *string
clearedFields map[string]struct{} clearedFields map[string]struct{}
users map[int]struct{} users map[int]struct{}
@@ -148,6 +150,78 @@ func (m *GroupMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetCreatedAt sets the "created_at" field.
func (m *GroupMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *GroupMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *GroupMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *GroupMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *GroupMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *GroupMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetName sets the "name" field. // SetName sets the "name" field.
func (m *GroupMutation) SetName(s string) { func (m *GroupMutation) SetName(s string) {
m.name = &s m.name = &s
@@ -326,7 +400,13 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *GroupMutation) Fields() []string { func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 1) fields := make([]string, 0, 3)
if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, group.FieldUpdatedAt)
}
if m.name != nil { if m.name != nil {
fields = append(fields, group.FieldName) fields = append(fields, group.FieldName)
} }
@@ -338,6 +418,10 @@ func (m *GroupMutation) Fields() []string {
// schema. // schema.
func (m *GroupMutation) Field(name string) (ent.Value, bool) { func (m *GroupMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case group.FieldCreatedAt:
return m.CreatedAt()
case group.FieldUpdatedAt:
return m.UpdatedAt()
case group.FieldName: case group.FieldName:
return m.Name() return m.Name()
} }
@@ -349,6 +433,10 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case group.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case group.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case group.FieldName: case group.FieldName:
return m.OldName(ctx) return m.OldName(ctx)
} }
@@ -360,6 +448,20 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
// type. // type.
func (m *GroupMutation) SetField(name string, value ent.Value) error { func (m *GroupMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case group.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case group.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case group.FieldName: case group.FieldName:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -416,6 +518,12 @@ func (m *GroupMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *GroupMutation) ResetField(name string) error { func (m *GroupMutation) ResetField(name string) error {
switch name { switch name {
case group.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case group.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case group.FieldName: case group.FieldName:
m.ResetName() m.ResetName()
return nil return nil
@@ -539,6 +647,8 @@ type TodoMutation struct {
op Op op Op
typ string typ string
id *int id *int
created_at *time.Time
updated_at *time.Time
title *string title *string
completed *bool completed *bool
clearedFields map[string]struct{} clearedFields map[string]struct{}
@@ -647,6 +757,78 @@ func (m *TodoMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetCreatedAt sets the "created_at" field.
func (m *TodoMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *TodoMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Todo entity.
// If the Todo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TodoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *TodoMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *TodoMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *TodoMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Todo entity.
// If the Todo object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *TodoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *TodoMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetTitle sets the "title" field. // SetTitle sets the "title" field.
func (m *TodoMutation) SetTitle(s string) { func (m *TodoMutation) SetTitle(s string) {
m.title = &s m.title = &s
@@ -792,7 +974,13 @@ func (m *TodoMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call // order to get all numeric fields that were incremented/decremented, call
// AddedFields(). // AddedFields().
func (m *TodoMutation) Fields() []string { func (m *TodoMutation) Fields() []string {
fields := make([]string, 0, 2) fields := make([]string, 0, 4)
if m.created_at != nil {
fields = append(fields, todo.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, todo.FieldUpdatedAt)
}
if m.title != nil { if m.title != nil {
fields = append(fields, todo.FieldTitle) fields = append(fields, todo.FieldTitle)
} }
@@ -807,6 +995,10 @@ func (m *TodoMutation) Fields() []string {
// schema. // schema.
func (m *TodoMutation) Field(name string) (ent.Value, bool) { func (m *TodoMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case todo.FieldCreatedAt:
return m.CreatedAt()
case todo.FieldUpdatedAt:
return m.UpdatedAt()
case todo.FieldTitle: case todo.FieldTitle:
return m.Title() return m.Title()
case todo.FieldCompleted: case todo.FieldCompleted:
@@ -820,6 +1012,10 @@ func (m *TodoMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case todo.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case todo.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case todo.FieldTitle: case todo.FieldTitle:
return m.OldTitle(ctx) return m.OldTitle(ctx)
case todo.FieldCompleted: case todo.FieldCompleted:
@@ -833,6 +1029,20 @@ func (m *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, er
// type. // type.
func (m *TodoMutation) SetField(name string, value ent.Value) error { func (m *TodoMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case todo.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case todo.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case todo.FieldTitle: case todo.FieldTitle:
v, ok := value.(string) v, ok := value.(string)
if !ok { if !ok {
@@ -896,6 +1106,12 @@ func (m *TodoMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *TodoMutation) ResetField(name string) error { func (m *TodoMutation) ResetField(name string) error {
switch name { switch name {
case todo.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case todo.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case todo.FieldTitle: case todo.FieldTitle:
m.ResetTitle() m.ResetTitle()
return nil return nil
@@ -986,10 +1202,10 @@ type UserMutation struct {
op Op op Op
typ string typ string
id *int id *int
email *string
password *string
created_at *time.Time created_at *time.Time
updated_at *time.Time updated_at *time.Time
email *string
password *string
clearedFields map[string]struct{} clearedFields map[string]struct{}
group map[int]struct{} group map[int]struct{}
removedgroup map[int]struct{} removedgroup map[int]struct{}
@@ -1097,78 +1313,6 @@ func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
} }
} }
// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
m.email = nil
}
// SetPassword sets the "password" field.
func (m *UserMutation) SetPassword(s string) {
m.password = &s
}
// Password returns the value of the "password" field in the mutation.
func (m *UserMutation) Password() (r string, exists bool) {
v := m.password
if v == nil {
return
}
return *v, true
}
// OldPassword returns the old "password" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPassword requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
}
return oldValue.Password, nil
}
// ResetPassword resets all changes to the "password" field.
func (m *UserMutation) ResetPassword() {
m.password = nil
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (m *UserMutation) SetCreatedAt(t time.Time) { func (m *UserMutation) SetCreatedAt(t time.Time) {
m.created_at = &t m.created_at = &t
@@ -1241,6 +1385,78 @@ func (m *UserMutation) ResetUpdatedAt() {
m.updated_at = nil m.updated_at = nil
} }
// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
m.email = nil
}
// SetPassword sets the "password" field.
func (m *UserMutation) SetPassword(s string) {
m.password = &s
}
// Password returns the value of the "password" field in the mutation.
func (m *UserMutation) Password() (r string, exists bool) {
v := m.password
if v == nil {
return
}
return *v, true
}
// OldPassword returns the old "password" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPassword requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
}
return oldValue.Password, nil
}
// ResetPassword resets all changes to the "password" field.
func (m *UserMutation) ResetPassword() {
m.password = nil
}
// AddGroupIDs adds the "group" edge to the Group entity by ids. // AddGroupIDs adds the "group" edge to the Group entity by ids.
func (m *UserMutation) AddGroupIDs(ids ...int) { func (m *UserMutation) AddGroupIDs(ids ...int) {
if m.group == nil { if m.group == nil {
@@ -1330,18 +1546,18 @@ func (m *UserMutation) Type() string {
// AddedFields(). // AddedFields().
func (m *UserMutation) Fields() []string { func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 4) fields := make([]string, 0, 4)
if m.email != nil {
fields = append(fields, user.FieldEmail)
}
if m.password != nil {
fields = append(fields, user.FieldPassword)
}
if m.created_at != nil { if m.created_at != nil {
fields = append(fields, user.FieldCreatedAt) fields = append(fields, user.FieldCreatedAt)
} }
if m.updated_at != nil { if m.updated_at != nil {
fields = append(fields, user.FieldUpdatedAt) fields = append(fields, user.FieldUpdatedAt)
} }
if m.email != nil {
fields = append(fields, user.FieldEmail)
}
if m.password != nil {
fields = append(fields, user.FieldPassword)
}
return fields return fields
} }
@@ -1350,14 +1566,14 @@ func (m *UserMutation) Fields() []string {
// schema. // schema.
func (m *UserMutation) Field(name string) (ent.Value, bool) { func (m *UserMutation) Field(name string) (ent.Value, bool) {
switch name { switch name {
case user.FieldEmail:
return m.Email()
case user.FieldPassword:
return m.Password()
case user.FieldCreatedAt: case user.FieldCreatedAt:
return m.CreatedAt() return m.CreatedAt()
case user.FieldUpdatedAt: case user.FieldUpdatedAt:
return m.UpdatedAt() return m.UpdatedAt()
case user.FieldEmail:
return m.Email()
case user.FieldPassword:
return m.Password()
} }
return nil, false return nil, false
} }
@@ -1367,14 +1583,14 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
// database failed. // database failed.
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name { switch name {
case user.FieldEmail:
return m.OldEmail(ctx)
case user.FieldPassword:
return m.OldPassword(ctx)
case user.FieldCreatedAt: case user.FieldCreatedAt:
return m.OldCreatedAt(ctx) return m.OldCreatedAt(ctx)
case user.FieldUpdatedAt: case user.FieldUpdatedAt:
return m.OldUpdatedAt(ctx) return m.OldUpdatedAt(ctx)
case user.FieldEmail:
return m.OldEmail(ctx)
case user.FieldPassword:
return m.OldPassword(ctx)
} }
return nil, fmt.Errorf("unknown User field %s", name) return nil, fmt.Errorf("unknown User field %s", name)
} }
@@ -1384,20 +1600,6 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
// type. // type.
func (m *UserMutation) SetField(name string, value ent.Value) error { func (m *UserMutation) SetField(name string, value ent.Value) error {
switch name { switch name {
case user.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case user.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case user.FieldCreatedAt: case user.FieldCreatedAt:
v, ok := value.(time.Time) v, ok := value.(time.Time)
if !ok { if !ok {
@@ -1412,6 +1614,20 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
} }
m.SetUpdatedAt(v) m.SetUpdatedAt(v)
return nil return nil
case user.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case user.FieldPassword:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
} }
return fmt.Errorf("unknown User field %s", name) return fmt.Errorf("unknown User field %s", name)
} }
@@ -1461,18 +1677,18 @@ func (m *UserMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema. // It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error { func (m *UserMutation) ResetField(name string) error {
switch name { switch name {
case user.FieldEmail:
m.ResetEmail()
return nil
case user.FieldPassword:
m.ResetPassword()
return nil
case user.FieldCreatedAt: case user.FieldCreatedAt:
m.ResetCreatedAt() m.ResetCreatedAt()
return nil return nil
case user.FieldUpdatedAt: case user.FieldUpdatedAt:
m.ResetUpdatedAt() m.ResetUpdatedAt()
return nil return nil
case user.FieldEmail:
m.ResetEmail()
return nil
case user.FieldPassword:
m.ResetPassword()
return nil
} }
return fmt.Errorf("unknown User field %s", name) return fmt.Errorf("unknown User field %s", name)
} }
+39 -10
View File
@@ -14,14 +14,40 @@ import (
// (default values, validators, hooks and policies) and stitches it // (default values, validators, hooks and policies) and stitches it
// to their package variables. // to their package variables.
func init() { func init() {
groupMixin := schema.Group{}.Mixin()
groupMixinFields0 := groupMixin[0].Fields()
_ = groupMixinFields0
groupFields := schema.Group{}.Fields() groupFields := schema.Group{}.Fields()
_ = groupFields _ = groupFields
// groupDescCreatedAt is the schema descriptor for created_at field.
groupDescCreatedAt := groupMixinFields0[0].Descriptor()
// group.DefaultCreatedAt holds the default value on creation for the created_at field.
group.DefaultCreatedAt = groupDescCreatedAt.Default.(func() time.Time)
// groupDescUpdatedAt is the schema descriptor for updated_at field.
groupDescUpdatedAt := groupMixinFields0[1].Descriptor()
// group.DefaultUpdatedAt holds the default value on creation for the updated_at field.
group.DefaultUpdatedAt = groupDescUpdatedAt.Default.(func() time.Time)
// group.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
group.UpdateDefaultUpdatedAt = groupDescUpdatedAt.UpdateDefault.(func() time.Time)
// groupDescName is the schema descriptor for name field. // groupDescName is the schema descriptor for name field.
groupDescName := groupFields[0].Descriptor() groupDescName := groupFields[0].Descriptor()
// group.DefaultName holds the default value on creation for the name field. // group.DefaultName holds the default value on creation for the name field.
group.DefaultName = groupDescName.Default.(string) group.DefaultName = groupDescName.Default.(string)
todoMixin := schema.Todo{}.Mixin()
todoMixinFields0 := todoMixin[0].Fields()
_ = todoMixinFields0
todoFields := schema.Todo{}.Fields() todoFields := schema.Todo{}.Fields()
_ = todoFields _ = todoFields
// todoDescCreatedAt is the schema descriptor for created_at field.
todoDescCreatedAt := todoMixinFields0[0].Descriptor()
// todo.DefaultCreatedAt holds the default value on creation for the created_at field.
todo.DefaultCreatedAt = todoDescCreatedAt.Default.(func() time.Time)
// todoDescUpdatedAt is the schema descriptor for updated_at field.
todoDescUpdatedAt := todoMixinFields0[1].Descriptor()
// todo.DefaultUpdatedAt holds the default value on creation for the updated_at field.
todo.DefaultUpdatedAt = todoDescUpdatedAt.Default.(func() time.Time)
// todo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
todo.UpdateDefaultUpdatedAt = todoDescUpdatedAt.UpdateDefault.(func() time.Time)
// todoDescTitle is the schema descriptor for title field. // todoDescTitle is the schema descriptor for title field.
todoDescTitle := todoFields[0].Descriptor() todoDescTitle := todoFields[0].Descriptor()
// todo.DefaultTitle holds the default value on creation for the title field. // todo.DefaultTitle holds the default value on creation for the title field.
@@ -30,8 +56,21 @@ func init() {
todoDescCompleted := todoFields[1].Descriptor() todoDescCompleted := todoFields[1].Descriptor()
// todo.DefaultCompleted holds the default value on creation for the completed field. // todo.DefaultCompleted holds the default value on creation for the completed field.
todo.DefaultCompleted = todoDescCompleted.Default.(bool) todo.DefaultCompleted = todoDescCompleted.Default.(bool)
userMixin := schema.User{}.Mixin()
userMixinFields0 := userMixin[0].Fields()
_ = userMixinFields0
userFields := schema.User{}.Fields() userFields := schema.User{}.Fields()
_ = userFields _ = userFields
// userDescCreatedAt is the schema descriptor for created_at field.
userDescCreatedAt := userMixinFields0[0].Descriptor()
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
// userDescUpdatedAt is the schema descriptor for updated_at field.
userDescUpdatedAt := userMixinFields0[1].Descriptor()
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
// userDescEmail is the schema descriptor for email field. // userDescEmail is the schema descriptor for email field.
userDescEmail := userFields[0].Descriptor() userDescEmail := userFields[0].Descriptor()
// user.DefaultEmail holds the default value on creation for the email field. // user.DefaultEmail holds the default value on creation for the email field.
@@ -40,14 +79,4 @@ func init() {
userDescPassword := userFields[1].Descriptor() userDescPassword := userFields[1].Descriptor()
// user.DefaultPassword holds the default value on creation for the password field. // user.DefaultPassword holds the default value on creation for the password field.
user.DefaultPassword = userDescPassword.Default.(string) user.DefaultPassword = userDescPassword.Default.(string)
// userDescCreatedAt is the schema descriptor for created_at field.
userDescCreatedAt := userFields[2].Descriptor()
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
user.DefaultCreatedAt = userDescCreatedAt.Default.(time.Time)
// userDescUpdatedAt is the schema descriptor for updated_at field.
userDescUpdatedAt := userFields[3].Descriptor()
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(time.Time)
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
} }
+8 -1
View File
@@ -1,6 +1,8 @@
package schema package schema
import ( import (
"ersteller-lib/schema/ent"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/schema/edge" "entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
@@ -10,13 +12,18 @@ type Group struct {
ent.Schema ent.Schema
} }
func (Group) Mixin() []ent.Mixin {
return []ent.Mixin{
ersteller_ent.TimeMixin{},
}
}
func (Group) Fields() []ent.Field { func (Group) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.String("name").Default(""), field.String("name").Default(""),
} }
} }
// Add edges to define relationships
func (Group) Edges() []ent.Edge { func (Group) Edges() []ent.Edge {
return []ent.Edge{ return []ent.Edge{
// Back-reference to users that belong to this group // Back-reference to users that belong to this group
+8
View File
@@ -1,6 +1,8 @@
package schema package schema
import ( import (
"ersteller-lib/schema/ent"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/schema/edge" "entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
@@ -10,6 +12,12 @@ type Todo struct {
ent.Schema ent.Schema
} }
func (Todo) Mixin() []ent.Mixin {
return []ent.Mixin{
ersteller_ent.TimeMixin{},
}
}
func (Todo) Fields() []ent.Field { func (Todo) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.String("title").Default(""), field.String("title").Default(""),
+7 -4
View File
@@ -1,7 +1,7 @@
package schema package schema
import ( import (
"time" "ersteller-lib/schema/ent"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/schema/edge" "entgo.io/ent/schema/edge"
@@ -13,15 +13,18 @@ type User struct {
ent.Schema ent.Schema
} }
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
ersteller_ent.TimeMixin{},
}
}
// Fields of the User. // Fields of the User.
func (User) Fields() []ent.Field { func (User) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.String("email"). field.String("email").
Default("unknown@localhost"), Default("unknown@localhost"),
field.String("password").Default(""), field.String("password").Default(""),
field.Time("created_at").Default(time.Now()).Immutable(),
field.Time("updated_at").Default(time.Now()).
UpdateDefault(time.Now),
} }
} }
+25
View File
@@ -7,6 +7,7 @@ import (
"ersteller-lib/schema/ent/example/ent/todo" "ersteller-lib/schema/ent/example/ent/todo"
"fmt" "fmt"
"strings" "strings"
"time"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
@@ -17,6 +18,10 @@ type Todo struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Title holds the value of the "title" field. // Title holds the value of the "title" field.
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
// Completed holds the value of the "completed" field. // Completed holds the value of the "completed" field.
@@ -59,6 +64,8 @@ func (*Todo) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
case todo.FieldTitle: case todo.FieldTitle:
values[i] = new(sql.NullString) values[i] = new(sql.NullString)
case todo.FieldCreatedAt, todo.FieldUpdatedAt:
values[i] = new(sql.NullTime)
case todo.ForeignKeys[0]: // todo_group case todo.ForeignKeys[0]: // todo_group
values[i] = new(sql.NullInt64) values[i] = new(sql.NullInt64)
default: default:
@@ -82,6 +89,18 @@ func (_m *Todo) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case todo.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case todo.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
case todo.FieldTitle: case todo.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok { if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i]) return fmt.Errorf("unexpected type %T for field title", values[i])
@@ -142,6 +161,12 @@ func (_m *Todo) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("Todo(") builder.WriteString("Todo(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("title=") builder.WriteString("title=")
builder.WriteString(_m.Title) builder.WriteString(_m.Title)
builder.WriteString(", ") builder.WriteString(", ")
+24
View File
@@ -3,6 +3,8 @@
package todo package todo
import ( import (
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
) )
@@ -12,6 +14,10 @@ const (
Label = "todo" Label = "todo"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldTitle holds the string denoting the title field in the database. // FieldTitle holds the string denoting the title field in the database.
FieldTitle = "title" FieldTitle = "title"
// FieldCompleted holds the string denoting the completed field in the database. // FieldCompleted holds the string denoting the completed field in the database.
@@ -32,6 +38,8 @@ const (
// Columns holds all SQL columns for todo fields. // Columns holds all SQL columns for todo fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldTitle, FieldTitle,
FieldCompleted, FieldCompleted,
} }
@@ -58,6 +66,12 @@ func ValidColumn(column string) bool {
} }
var ( var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultTitle holds the default value on creation for the "title" field. // DefaultTitle holds the default value on creation for the "title" field.
DefaultTitle string DefaultTitle string
// DefaultCompleted holds the default value on creation for the "completed" field. // DefaultCompleted holds the default value on creation for the "completed" field.
@@ -72,6 +86,16 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByTitle orders the results by the title field. // ByTitle orders the results by the title field.
func ByTitle(opts ...sql.OrderTermOption) OrderOption { func ByTitle(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTitle, opts...).ToFunc() return sql.OrderByField(FieldTitle, opts...).ToFunc()
+91
View File
@@ -4,6 +4,7 @@ package todo
import ( import (
"ersteller-lib/schema/ent/example/ent/predicate" "ersteller-lib/schema/ent/example/ent/predicate"
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
@@ -54,6 +55,16 @@ func IDLTE(id int) predicate.Todo {
return predicate.Todo(sql.FieldLTE(FieldID, id)) return predicate.Todo(sql.FieldLTE(FieldID, id))
} }
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. // Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.Todo { func Title(v string) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldTitle, v)) return predicate.Todo(sql.FieldEQ(FieldTitle, v))
@@ -64,6 +75,86 @@ func Completed(v bool) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldCompleted, v)) return predicate.Todo(sql.FieldEQ(FieldCompleted, v))
} }
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Todo {
return predicate.Todo(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Todo {
return predicate.Todo(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Todo {
return predicate.Todo(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Todo {
return predicate.Todo(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Todo {
return predicate.Todo(sql.FieldLTE(FieldUpdatedAt, v))
}
// TitleEQ applies the EQ predicate on the "title" field. // TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.Todo { func TitleEQ(v string) predicate.Todo {
return predicate.Todo(sql.FieldEQ(FieldTitle, v)) return predicate.Todo(sql.FieldEQ(FieldTitle, v))
+51
View File
@@ -8,6 +8,7 @@ import (
"ersteller-lib/schema/ent/example/ent/group" "ersteller-lib/schema/ent/example/ent/group"
"ersteller-lib/schema/ent/example/ent/todo" "ersteller-lib/schema/ent/example/ent/todo"
"fmt" "fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
@@ -20,6 +21,34 @@ type TodoCreate struct {
hooks []Hook hooks []Hook
} }
// SetCreatedAt sets the "created_at" field.
func (_c *TodoCreate) SetCreatedAt(v time.Time) *TodoCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *TodoCreate) SetNillableCreatedAt(v *time.Time) *TodoCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *TodoCreate) SetUpdatedAt(v time.Time) *TodoCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *TodoCreate) SetNillableUpdatedAt(v *time.Time) *TodoCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetTitle sets the "title" field. // SetTitle sets the "title" field.
func (_c *TodoCreate) SetTitle(v string) *TodoCreate { func (_c *TodoCreate) SetTitle(v string) *TodoCreate {
_c.mutation.SetTitle(v) _c.mutation.SetTitle(v)
@@ -102,6 +131,14 @@ func (_c *TodoCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *TodoCreate) defaults() { func (_c *TodoCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := todo.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := todo.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Title(); !ok { if _, ok := _c.mutation.Title(); !ok {
v := todo.DefaultTitle v := todo.DefaultTitle
_c.mutation.SetTitle(v) _c.mutation.SetTitle(v)
@@ -114,6 +151,12 @@ func (_c *TodoCreate) defaults() {
// check runs all checks and user-defined validators on the builder. // check runs all checks and user-defined validators on the builder.
func (_c *TodoCreate) check() error { func (_c *TodoCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Todo.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Todo.updated_at"`)}
}
if _, ok := _c.mutation.Title(); !ok { if _, ok := _c.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Todo.title"`)} return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Todo.title"`)}
} }
@@ -146,6 +189,14 @@ func (_c *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) {
_node = &Todo{config: _c.config} _node = &Todo{config: _c.config}
_spec = sqlgraph.NewCreateSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(todo.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.Title(); ok { if value, ok := _c.mutation.Title(); ok {
_spec.SetField(todo.FieldTitle, field.TypeString, value) _spec.SetField(todo.FieldTitle, field.TypeString, value)
_node.Title = value _node.Title = value
+4 -4
View File
@@ -299,12 +299,12 @@ func (_q *TodoQuery) WithGroup(opts ...func(*GroupQuery)) *TodoQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Title string `json:"title,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.Todo.Query(). // client.Todo.Query().
// GroupBy(todo.FieldTitle). // GroupBy(todo.FieldCreatedAt).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy { func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy {
@@ -322,11 +322,11 @@ func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Title string `json:"title,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// } // }
// //
// client.Todo.Query(). // client.Todo.Query().
// Select(todo.FieldTitle). // Select(todo.FieldCreatedAt).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *TodoQuery) Select(fields ...string) *TodoSelect { func (_q *TodoQuery) Select(fields ...string) *TodoSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)
+37
View File
@@ -9,6 +9,7 @@ import (
"ersteller-lib/schema/ent/example/ent/predicate" "ersteller-lib/schema/ent/example/ent/predicate"
"ersteller-lib/schema/ent/example/ent/todo" "ersteller-lib/schema/ent/example/ent/todo"
"fmt" "fmt"
"time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
@@ -28,6 +29,12 @@ func (_u *TodoUpdate) Where(ps ...predicate.Todo) *TodoUpdate {
return _u return _u
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *TodoUpdate) SetUpdatedAt(v time.Time) *TodoUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetTitle sets the "title" field. // SetTitle sets the "title" field.
func (_u *TodoUpdate) SetTitle(v string) *TodoUpdate { func (_u *TodoUpdate) SetTitle(v string) *TodoUpdate {
_u.mutation.SetTitle(v) _u.mutation.SetTitle(v)
@@ -88,6 +95,7 @@ func (_u *TodoUpdate) ClearGroup() *TodoUpdate {
// Save executes the query and returns the number of nodes affected by the update operation. // Save executes the query and returns the number of nodes affected by the update operation.
func (_u *TodoUpdate) Save(ctx context.Context) (int, error) { func (_u *TodoUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
} }
@@ -113,6 +121,14 @@ func (_u *TodoUpdate) ExecX(ctx context.Context) {
} }
} }
// defaults sets the default values of the builder before save.
func (_u *TodoUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := todo.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *TodoUpdate) sqlSave(ctx context.Context) (_node int, err error) { func (_u *TodoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) _spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 { if ps := _u.mutation.predicates; len(ps) > 0 {
@@ -122,6 +138,9 @@ func (_u *TodoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Title(); ok { if value, ok := _u.mutation.Title(); ok {
_spec.SetField(todo.FieldTitle, field.TypeString, value) _spec.SetField(todo.FieldTitle, field.TypeString, value)
} }
@@ -177,6 +196,12 @@ type TodoUpdateOne struct {
mutation *TodoMutation mutation *TodoMutation
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *TodoUpdateOne) SetUpdatedAt(v time.Time) *TodoUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetTitle sets the "title" field. // SetTitle sets the "title" field.
func (_u *TodoUpdateOne) SetTitle(v string) *TodoUpdateOne { func (_u *TodoUpdateOne) SetTitle(v string) *TodoUpdateOne {
_u.mutation.SetTitle(v) _u.mutation.SetTitle(v)
@@ -250,6 +275,7 @@ func (_u *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne {
// Save executes the query and returns the updated Todo entity. // Save executes the query and returns the updated Todo entity.
func (_u *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { func (_u *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
} }
@@ -275,6 +301,14 @@ func (_u *TodoUpdateOne) ExecX(ctx context.Context) {
} }
} }
// defaults sets the default values of the builder before save.
func (_u *TodoUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := todo.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) { func (_u *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) {
_spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) _spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt))
id, ok := _u.mutation.ID() id, ok := _u.mutation.ID()
@@ -301,6 +335,9 @@ func (_u *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) {
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Title(); ok { if value, ok := _u.mutation.Title(); ok {
_spec.SetField(todo.FieldTitle, field.TypeString, value) _spec.SetField(todo.FieldTitle, field.TypeString, value)
} }
+22 -22
View File
@@ -17,14 +17,14 @@ type User struct {
config `json:"-"` config `json:"-"`
// ID of the ent. // ID of the ent.
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
// Email holds the value of the "email" field.
Email string `json:"email,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"password,omitempty"`
// CreatedAt holds the value of the "created_at" field. // CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field. // UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
// Email holds the value of the "email" field.
Email string `json:"email,omitempty"`
// Password holds the value of the "password" field.
Password string `json:"password,omitempty"`
// Edges holds the relations/edges for other nodes in the graph. // Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set. // The values are being populated by the UserQuery when eager-loading is set.
Edges UserEdges `json:"edges"` Edges UserEdges `json:"edges"`
@@ -81,18 +81,6 @@ func (_m *User) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field id", value) return fmt.Errorf("unexpected type %T for field id", value)
} }
_m.ID = int(value.Int64) _m.ID = int(value.Int64)
case user.FieldEmail:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field email", values[i])
} else if value.Valid {
_m.Email = value.String
}
case user.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
_m.Password = value.String
}
case user.FieldCreatedAt: case user.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok { if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i]) return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -105,6 +93,18 @@ func (_m *User) assignValues(columns []string, values []any) error {
} else if value.Valid { } else if value.Valid {
_m.UpdatedAt = value.Time _m.UpdatedAt = value.Time
} }
case user.FieldEmail:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field email", values[i])
} else if value.Valid {
_m.Email = value.String
}
case user.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
_m.Password = value.String
}
default: default:
_m.selectValues.Set(columns[i], values[i]) _m.selectValues.Set(columns[i], values[i])
} }
@@ -146,17 +146,17 @@ func (_m *User) String() string {
var builder strings.Builder var builder strings.Builder
builder.WriteString("User(") builder.WriteString("User(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("email=")
builder.WriteString(_m.Email)
builder.WriteString(", ")
builder.WriteString("password=")
builder.WriteString(_m.Password)
builder.WriteString(", ")
builder.WriteString("created_at=") builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ") builder.WriteString(", ")
builder.WriteString("updated_at=") builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("email=")
builder.WriteString(_m.Email)
builder.WriteString(", ")
builder.WriteString("password=")
builder.WriteString(_m.Password)
builder.WriteByte(')') builder.WriteByte(')')
return builder.String() return builder.String()
} }
+22 -22
View File
@@ -14,14 +14,14 @@ const (
Label = "user" Label = "user"
// FieldID holds the string denoting the id field in the database. // FieldID holds the string denoting the id field in the database.
FieldID = "id" FieldID = "id"
// FieldEmail holds the string denoting the email field in the database.
FieldEmail = "email"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldCreatedAt holds the string denoting the created_at field in the database. // FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at" FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database. // FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at" FieldUpdatedAt = "updated_at"
// FieldEmail holds the string denoting the email field in the database.
FieldEmail = "email"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// EdgeGroup holds the string denoting the group edge name in mutations. // EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group" EdgeGroup = "group"
// Table holds the table name of the user in the database. // Table holds the table name of the user in the database.
@@ -36,10 +36,10 @@ const (
// Columns holds all SQL columns for user fields. // Columns holds all SQL columns for user fields.
var Columns = []string{ var Columns = []string{
FieldID, FieldID,
FieldEmail,
FieldPassword,
FieldCreatedAt, FieldCreatedAt,
FieldUpdatedAt, FieldUpdatedAt,
FieldEmail,
FieldPassword,
} }
var ( var (
@@ -59,16 +59,16 @@ func ValidColumn(column string) bool {
} }
var ( var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultEmail holds the default value on creation for the "email" field. // DefaultEmail holds the default value on creation for the "email" field.
DefaultEmail string DefaultEmail string
// DefaultPassword holds the default value on creation for the "password" field. // DefaultPassword holds the default value on creation for the "password" field.
DefaultPassword string DefaultPassword string
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
) )
// OrderOption defines the ordering options for the User queries. // OrderOption defines the ordering options for the User queries.
@@ -79,16 +79,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc() return sql.OrderByField(FieldID, opts...).ToFunc()
} }
// ByEmail orders the results by the email field.
func ByEmail(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldEmail, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field. // ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
@@ -99,6 +89,16 @@ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
} }
// ByEmail orders the results by the email field.
func ByEmail(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldEmail, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByGroupCount orders the results by group count. // ByGroupCount orders the results by group count.
func ByGroupCount(opts ...sql.OrderTermOption) OrderOption { func ByGroupCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) { return func(s *sql.Selector) {
+84 -84
View File
@@ -55,6 +55,16 @@ func IDLTE(id int) predicate.User {
return predicate.User(sql.FieldLTE(FieldID, id)) return predicate.User(sql.FieldLTE(FieldID, id))
} }
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
}
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ. // Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
func Email(v string) predicate.User { func Email(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldEmail, v)) return predicate.User(sql.FieldEQ(FieldEmail, v))
@@ -65,16 +75,86 @@ func Password(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldPassword, v)) return predicate.User(sql.FieldEQ(FieldPassword, v))
} }
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. // CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAt(v time.Time) predicate.User { func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
} }
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. // CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func UpdatedAt(v time.Time) predicate.User { func CreatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
} }
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldUpdatedAt, v))
}
// EmailEQ applies the EQ predicate on the "email" field. // EmailEQ applies the EQ predicate on the "email" field.
func EmailEQ(v string) predicate.User { func EmailEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldEmail, v)) return predicate.User(sql.FieldEQ(FieldEmail, v))
@@ -205,86 +285,6 @@ func PasswordContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldPassword, v)) return predicate.User(sql.FieldContainsFold(FieldPassword, v))
} }
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.User {
return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.User {
return predicate.User(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.User {
return predicate.User(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.User {
return predicate.User(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.User {
return predicate.User(sql.FieldLTE(FieldUpdatedAt, v))
}
// HasGroup applies the HasEdge predicate on the "group" edge. // HasGroup applies the HasEdge predicate on the "group" edge.
func HasGroup() predicate.User { func HasGroup() predicate.User {
return predicate.User(func(s *sql.Selector) { return predicate.User(func(s *sql.Selector) {
+50 -50
View File
@@ -21,34 +21,6 @@ type UserCreate struct {
hooks []Hook hooks []Hook
} }
// SetEmail sets the "email" field.
func (_c *UserCreate) SetEmail(v string) *UserCreate {
_c.mutation.SetEmail(v)
return _c
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (_c *UserCreate) SetNillableEmail(v *string) *UserCreate {
if v != nil {
_c.SetEmail(*v)
}
return _c
}
// SetPassword sets the "password" field.
func (_c *UserCreate) SetPassword(v string) *UserCreate {
_c.mutation.SetPassword(v)
return _c
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_c *UserCreate) SetNillablePassword(v *string) *UserCreate {
if v != nil {
_c.SetPassword(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field. // SetCreatedAt sets the "created_at" field.
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate { func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
_c.mutation.SetCreatedAt(v) _c.mutation.SetCreatedAt(v)
@@ -77,6 +49,34 @@ func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate {
return _c return _c
} }
// SetEmail sets the "email" field.
func (_c *UserCreate) SetEmail(v string) *UserCreate {
_c.mutation.SetEmail(v)
return _c
}
// SetNillableEmail sets the "email" field if the given value is not nil.
func (_c *UserCreate) SetNillableEmail(v *string) *UserCreate {
if v != nil {
_c.SetEmail(*v)
}
return _c
}
// SetPassword sets the "password" field.
func (_c *UserCreate) SetPassword(v string) *UserCreate {
_c.mutation.SetPassword(v)
return _c
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_c *UserCreate) SetNillablePassword(v *string) *UserCreate {
if v != nil {
_c.SetPassword(*v)
}
return _c
}
// AddGroupIDs adds the "group" edge to the Group entity by IDs. // AddGroupIDs adds the "group" edge to the Group entity by IDs.
func (_c *UserCreate) AddGroupIDs(ids ...int) *UserCreate { func (_c *UserCreate) AddGroupIDs(ids ...int) *UserCreate {
_c.mutation.AddGroupIDs(ids...) _c.mutation.AddGroupIDs(ids...)
@@ -127,6 +127,14 @@ func (_c *UserCreate) ExecX(ctx context.Context) {
// defaults sets the default values of the builder before save. // defaults sets the default values of the builder before save.
func (_c *UserCreate) defaults() { func (_c *UserCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := user.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := user.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Email(); !ok { if _, ok := _c.mutation.Email(); !ok {
v := user.DefaultEmail v := user.DefaultEmail
_c.mutation.SetEmail(v) _c.mutation.SetEmail(v)
@@ -135,30 +143,22 @@ func (_c *UserCreate) defaults() {
v := user.DefaultPassword v := user.DefaultPassword
_c.mutation.SetPassword(v) _c.mutation.SetPassword(v)
} }
if _, ok := _c.mutation.CreatedAt(); !ok {
v := user.DefaultCreatedAt
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := user.DefaultUpdatedAt
_c.mutation.SetUpdatedAt(v)
}
} }
// check runs all checks and user-defined validators on the builder. // check runs all checks and user-defined validators on the builder.
func (_c *UserCreate) check() error { func (_c *UserCreate) check() error {
if _, ok := _c.mutation.Email(); !ok {
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "User.email"`)}
}
if _, ok := _c.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok { if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)} return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
} }
if _, ok := _c.mutation.UpdatedAt(); !ok { if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)} return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
} }
if _, ok := _c.mutation.Email(); !ok {
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "User.email"`)}
}
if _, ok := _c.mutation.Password(); !ok {
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)}
}
return nil return nil
} }
@@ -185,14 +185,6 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_node = &User{config: _c.config} _node = &User{config: _c.config}
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) _spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
) )
if value, ok := _c.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
_node.Email = value
}
if value, ok := _c.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
_node.Password = value
}
if value, ok := _c.mutation.CreatedAt(); ok { if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value) _spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value _node.CreatedAt = value
@@ -201,6 +193,14 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value _node.UpdatedAt = value
} }
if value, ok := _c.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value)
_node.Email = value
}
if value, ok := _c.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value)
_node.Password = value
}
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M, Rel: sqlgraph.M2M,
+4 -4
View File
@@ -299,12 +299,12 @@ func (_q *UserQuery) WithGroup(opts ...func(*GroupQuery)) *UserQuery {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Email string `json:"email,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"` // Count int `json:"count,omitempty"`
// } // }
// //
// client.User.Query(). // client.User.Query().
// GroupBy(user.FieldEmail). // GroupBy(user.FieldCreatedAt).
// Aggregate(ent.Count()). // Aggregate(ent.Count()).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
@@ -322,11 +322,11 @@ func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
// Example: // Example:
// //
// var v []struct { // var v []struct {
// Email string `json:"email,omitempty"` // CreatedAt time.Time `json:"created_at,omitempty"`
// } // }
// //
// client.User.Query(). // client.User.Query().
// Select(user.FieldEmail). // Select(user.FieldCreatedAt).
// Scan(ctx, &v) // Scan(ctx, &v)
func (_q *UserQuery) Select(fields ...string) *UserSelect { func (_q *UserQuery) Select(fields ...string) *UserSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...) _q.ctx.Fields = append(_q.ctx.Fields, fields...)
+18 -18
View File
@@ -29,6 +29,12 @@ func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
return _u return _u
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetEmail sets the "email" field. // SetEmail sets the "email" field.
func (_u *UserUpdate) SetEmail(v string) *UserUpdate { func (_u *UserUpdate) SetEmail(v string) *UserUpdate {
_u.mutation.SetEmail(v) _u.mutation.SetEmail(v)
@@ -57,12 +63,6 @@ func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate {
return _u return _u
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// AddGroupIDs adds the "group" edge to the Group entity by IDs. // AddGroupIDs adds the "group" edge to the Group entity by IDs.
func (_u *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate { func (_u *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
_u.mutation.AddGroupIDs(ids...) _u.mutation.AddGroupIDs(ids...)
@@ -149,15 +149,15 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Email(); ok { if value, ok := _u.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value) _spec.SetField(user.FieldEmail, field.TypeString, value)
} }
if value, ok := _u.mutation.Password(); ok { if value, ok := _u.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value) _spec.SetField(user.FieldPassword, field.TypeString, value)
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.GroupCleared() { if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M, Rel: sqlgraph.M2M,
@@ -223,6 +223,12 @@ type UserUpdateOne struct {
mutation *UserMutation mutation *UserMutation
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetEmail sets the "email" field. // SetEmail sets the "email" field.
func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne { func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne {
_u.mutation.SetEmail(v) _u.mutation.SetEmail(v)
@@ -251,12 +257,6 @@ func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne {
return _u return _u
} }
// SetUpdatedAt sets the "updated_at" field.
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// AddGroupIDs adds the "group" edge to the Group entity by IDs. // AddGroupIDs adds the "group" edge to the Group entity by IDs.
func (_u *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne { func (_u *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
_u.mutation.AddGroupIDs(ids...) _u.mutation.AddGroupIDs(ids...)
@@ -373,15 +373,15 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
} }
} }
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.Email(); ok { if value, ok := _u.mutation.Email(); ok {
_spec.SetField(user.FieldEmail, field.TypeString, value) _spec.SetField(user.FieldEmail, field.TypeString, value)
} }
if value, ok := _u.mutation.Password(); ok { if value, ok := _u.mutation.Password(); ok {
_spec.SetField(user.FieldPassword, field.TypeString, value) _spec.SetField(user.FieldPassword, field.TypeString, value)
} }
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.GroupCleared() { if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{ edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M, Rel: sqlgraph.M2M,
+27
View File
@@ -0,0 +1,27 @@
package ersteller_ent
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
)
// TimeMixin implements the ent.Mixin for sharing
// time fields with package schemas.
type TimeMixin struct {
mixin.Schema
}
// Fields of the TimeMixin.
func (TimeMixin) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Default(time.Now).
Immutable(),
field.Time("updated_at").
Default(time.Now).
UpdateDefault(time.Now),
}
}