parent
9d28fde00c
commit
c2d28f95c5
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserGroup struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UserGroup) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int("user_id"),
|
||||||
|
field.Int("group_id"),
|
||||||
|
field.Bool("is_primary").
|
||||||
|
Default(false),
|
||||||
|
field.Time("expires_at").
|
||||||
|
Optional().
|
||||||
|
Nillable().
|
||||||
|
SchemaType(map[string]string{
|
||||||
|
dialect.MySQL: "datetime",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (UserGroup) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.To("user", User.Type).
|
||||||
|
Required().
|
||||||
|
Unique().
|
||||||
|
Field("user_id"),
|
||||||
|
edge.To("group", Group.Type).
|
||||||
|
Required().
|
||||||
|
Unique().
|
||||||
|
Field("group_id"),
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,206 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/usergroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserGroup is the model entity for the UserGroup schema.
|
||||||
|
type UserGroup struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
// UserID holds the value of the "user_id" field.
|
||||||
|
UserID int `json:"user_id,omitempty"`
|
||||||
|
// GroupID holds the value of the "group_id" field.
|
||||||
|
GroupID int `json:"group_id,omitempty"`
|
||||||
|
// IsPrimary holds the value of the "is_primary" field.
|
||||||
|
IsPrimary bool `json:"is_primary,omitempty"`
|
||||||
|
// ExpiresAt holds the value of the "expires_at" field.
|
||||||
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the UserGroupQuery when eager-loading is set.
|
||||||
|
Edges UserGroupEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type UserGroupEdges struct {
|
||||||
|
// User holds the value of the user edge.
|
||||||
|
User *User `json:"user,omitempty"`
|
||||||
|
// Group holds the value of the group edge.
|
||||||
|
Group *Group `json:"group,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserOrErr returns the User value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e UserGroupEdges) UserOrErr() (*User, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.User == nil {
|
||||||
|
// Edge was loaded but was not found.
|
||||||
|
return nil, &NotFoundError{label: user.Label}
|
||||||
|
}
|
||||||
|
return e.User, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "user"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupOrErr returns the Group value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e UserGroupEdges) GroupOrErr() (*Group, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
if e.Group == nil {
|
||||||
|
// Edge was loaded but was not found.
|
||||||
|
return nil, &NotFoundError{label: group.Label}
|
||||||
|
}
|
||||||
|
return e.Group, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "group"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*UserGroup) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case usergroup.FieldIsPrimary:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case usergroup.FieldID, usergroup.FieldUserID, usergroup.FieldGroupID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case usergroup.FieldExpiresAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the UserGroup fields.
|
||||||
|
func (ug *UserGroup) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case usergroup.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
ug.ID = int(value.Int64)
|
||||||
|
case usergroup.FieldUserID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ug.UserID = int(value.Int64)
|
||||||
|
}
|
||||||
|
case usergroup.FieldGroupID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field group_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ug.GroupID = int(value.Int64)
|
||||||
|
}
|
||||||
|
case usergroup.FieldIsPrimary:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field is_primary", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ug.IsPrimary = value.Bool
|
||||||
|
}
|
||||||
|
case usergroup.FieldExpiresAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field expires_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
ug.ExpiresAt = new(time.Time)
|
||||||
|
*ug.ExpiresAt = value.Time
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ug.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the UserGroup.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (ug *UserGroup) Value(name string) (ent.Value, error) {
|
||||||
|
return ug.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser queries the "user" edge of the UserGroup entity.
|
||||||
|
func (ug *UserGroup) QueryUser() *UserQuery {
|
||||||
|
return NewUserGroupClient(ug.config).QueryUser(ug)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryGroup queries the "group" edge of the UserGroup entity.
|
||||||
|
func (ug *UserGroup) QueryGroup() *GroupQuery {
|
||||||
|
return NewUserGroupClient(ug.config).QueryGroup(ug)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this UserGroup.
|
||||||
|
// Note that you need to call UserGroup.Unwrap() before calling this method if this UserGroup
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (ug *UserGroup) Update() *UserGroupUpdateOne {
|
||||||
|
return NewUserGroupClient(ug.config).UpdateOne(ug)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the UserGroup entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (ug *UserGroup) Unwrap() *UserGroup {
|
||||||
|
_tx, ok := ug.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: UserGroup is not a transactional entity")
|
||||||
|
}
|
||||||
|
ug.config.driver = _tx.drv
|
||||||
|
return ug
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (ug *UserGroup) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("UserGroup(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", ug.ID))
|
||||||
|
builder.WriteString("user_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ug.UserID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("group_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ug.GroupID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("is_primary=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", ug.IsPrimary))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := ug.ExpiresAt; v != nil {
|
||||||
|
builder.WriteString("expires_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser manually set the edge as loaded state.
|
||||||
|
func (e *UserGroup) SetUser(v *User) {
|
||||||
|
e.Edges.User = v
|
||||||
|
e.Edges.loadedTypes[0] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroup manually set the edge as loaded state.
|
||||||
|
func (e *UserGroup) SetGroup(v *Group) {
|
||||||
|
e.Edges.Group = v
|
||||||
|
e.Edges.loadedTypes[1] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroups is a parsable slice of UserGroup.
|
||||||
|
type UserGroups []*UserGroup
|
@ -0,0 +1,123 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package usergroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the usergroup type in the database.
|
||||||
|
Label = "user_group"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldUserID holds the string denoting the user_id field in the database.
|
||||||
|
FieldUserID = "user_id"
|
||||||
|
// FieldGroupID holds the string denoting the group_id field in the database.
|
||||||
|
FieldGroupID = "group_id"
|
||||||
|
// FieldIsPrimary holds the string denoting the is_primary field in the database.
|
||||||
|
FieldIsPrimary = "is_primary"
|
||||||
|
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
||||||
|
FieldExpiresAt = "expires_at"
|
||||||
|
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||||
|
EdgeUser = "user"
|
||||||
|
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||||
|
EdgeGroup = "group"
|
||||||
|
// Table holds the table name of the usergroup in the database.
|
||||||
|
Table = "user_groups"
|
||||||
|
// UserTable is the table that holds the user relation/edge.
|
||||||
|
UserTable = "user_groups"
|
||||||
|
// UserInverseTable is the table name for the User entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||||
|
UserInverseTable = "users"
|
||||||
|
// UserColumn is the table column denoting the user relation/edge.
|
||||||
|
UserColumn = "user_id"
|
||||||
|
// GroupTable is the table that holds the group relation/edge.
|
||||||
|
GroupTable = "user_groups"
|
||||||
|
// GroupInverseTable is the table name for the Group entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "group" package.
|
||||||
|
GroupInverseTable = "groups"
|
||||||
|
// GroupColumn is the table column denoting the group relation/edge.
|
||||||
|
GroupColumn = "group_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for usergroup fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldUserID,
|
||||||
|
FieldGroupID,
|
||||||
|
FieldIsPrimary,
|
||||||
|
FieldExpiresAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultIsPrimary holds the default value on creation for the "is_primary" field.
|
||||||
|
DefaultIsPrimary bool
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the UserGroup queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserID orders the results by the user_id field.
|
||||||
|
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByGroupID orders the results by the group_id field.
|
||||||
|
func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldGroupID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByIsPrimary orders the results by the is_primary field.
|
||||||
|
func ByIsPrimary(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldIsPrimary, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByExpiresAt orders the results by the expires_at field.
|
||||||
|
func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUserField orders the results by user field.
|
||||||
|
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByGroupField orders the results by group field.
|
||||||
|
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newUserStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(UserInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newGroupStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(GroupInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,237 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package usergroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||||
|
func UserID(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
|
||||||
|
func GroupID(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldGroupID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPrimary applies equality check predicate on the "is_primary" field. It's identical to IsPrimaryEQ.
|
||||||
|
func IsPrimary(v bool) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldIsPrimary, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
|
||||||
|
func ExpiresAt(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||||
|
func UserIDEQ(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||||
|
func UserIDNEQ(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNEQ(FieldUserID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDIn applies the In predicate on the "user_id" field.
|
||||||
|
func UserIDIn(vs ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||||
|
func UserIDNotIn(vs ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNotIn(FieldUserID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupIDEQ applies the EQ predicate on the "group_id" field.
|
||||||
|
func GroupIDEQ(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldGroupID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
|
||||||
|
func GroupIDNEQ(v int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNEQ(FieldGroupID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupIDIn applies the In predicate on the "group_id" field.
|
||||||
|
func GroupIDIn(vs ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldIn(FieldGroupID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
|
||||||
|
func GroupIDNotIn(vs ...int) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNotIn(FieldGroupID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPrimaryEQ applies the EQ predicate on the "is_primary" field.
|
||||||
|
func IsPrimaryEQ(v bool) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldIsPrimary, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsPrimaryNEQ applies the NEQ predicate on the "is_primary" field.
|
||||||
|
func IsPrimaryNEQ(v bool) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNEQ(FieldIsPrimary, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtEQ(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldEQ(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtNEQ(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNEQ(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtIn applies the In predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtIn(vs ...time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldIn(FieldExpiresAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtNotIn(vs ...time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNotIn(FieldExpiresAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtGT(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldGT(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtGTE(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldGTE(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtLT(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldLT(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtLTE(v time.Time) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldLTE(FieldExpiresAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtIsNil() predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldIsNull(FieldExpiresAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field.
|
||||||
|
func ExpiresAtNotNil() predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.FieldNotNull(FieldExpiresAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||||
|
func HasUser() predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||||
|
func HasUserWith(preds ...predicate.User) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(func(s *sql.Selector) {
|
||||||
|
step := newUserStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasGroup applies the HasEdge predicate on the "group" edge.
|
||||||
|
func HasGroup() predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
|
||||||
|
func HasGroupWith(preds ...predicate.Group) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(func(s *sql.Selector) {
|
||||||
|
step := newGroupStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.UserGroup) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.UserGroup) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.UserGroup) predicate.UserGroup {
|
||||||
|
return predicate.UserGroup(sql.NotPredicates(p))
|
||||||
|
}
|
@ -0,0 +1,713 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/usergroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserGroupCreate is the builder for creating a UserGroup entity.
|
||||||
|
type UserGroupCreate struct {
|
||||||
|
config
|
||||||
|
mutation *UserGroupMutation
|
||||||
|
hooks []Hook
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (ugc *UserGroupCreate) SetUserID(i int) *UserGroupCreate {
|
||||||
|
ugc.mutation.SetUserID(i)
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (ugc *UserGroupCreate) SetGroupID(i int) *UserGroupCreate {
|
||||||
|
ugc.mutation.SetGroupID(i)
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (ugc *UserGroupCreate) SetIsPrimary(b bool) *UserGroupCreate {
|
||||||
|
ugc.mutation.SetIsPrimary(b)
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
|
||||||
|
func (ugc *UserGroupCreate) SetNillableIsPrimary(b *bool) *UserGroupCreate {
|
||||||
|
if b != nil {
|
||||||
|
ugc.SetIsPrimary(*b)
|
||||||
|
}
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (ugc *UserGroupCreate) SetExpiresAt(t time.Time) *UserGroupCreate {
|
||||||
|
ugc.mutation.SetExpiresAt(t)
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
||||||
|
func (ugc *UserGroupCreate) SetNillableExpiresAt(t *time.Time) *UserGroupCreate {
|
||||||
|
if t != nil {
|
||||||
|
ugc.SetExpiresAt(*t)
|
||||||
|
}
|
||||||
|
return ugc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the User entity.
|
||||||
|
func (ugc *UserGroupCreate) SetUser(u *User) *UserGroupCreate {
|
||||||
|
return ugc.SetUserID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroup sets the "group" edge to the Group entity.
|
||||||
|
func (ugc *UserGroupCreate) SetGroup(g *Group) *UserGroupCreate {
|
||||||
|
return ugc.SetGroupID(g.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserGroupMutation object of the builder.
|
||||||
|
func (ugc *UserGroupCreate) Mutation() *UserGroupMutation {
|
||||||
|
return ugc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the UserGroup in the database.
|
||||||
|
func (ugc *UserGroupCreate) Save(ctx context.Context) (*UserGroup, error) {
|
||||||
|
ugc.defaults()
|
||||||
|
return withHooks(ctx, ugc.sqlSave, ugc.mutation, ugc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (ugc *UserGroupCreate) SaveX(ctx context.Context) *UserGroup {
|
||||||
|
v, err := ugc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ugc *UserGroupCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := ugc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ugc *UserGroupCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := ugc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (ugc *UserGroupCreate) defaults() {
|
||||||
|
if _, ok := ugc.mutation.IsPrimary(); !ok {
|
||||||
|
v := usergroup.DefaultIsPrimary
|
||||||
|
ugc.mutation.SetIsPrimary(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ugc *UserGroupCreate) check() error {
|
||||||
|
if _, ok := ugc.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserGroup.user_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ugc.mutation.GroupID(); !ok {
|
||||||
|
return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "UserGroup.group_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ugc.mutation.IsPrimary(); !ok {
|
||||||
|
return &ValidationError{Name: "is_primary", err: errors.New(`ent: missing required field "UserGroup.is_primary"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ugc.mutation.UserID(); !ok {
|
||||||
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserGroup.user"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ugc.mutation.GroupID(); !ok {
|
||||||
|
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "UserGroup.group"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugc *UserGroupCreate) sqlSave(ctx context.Context) (*UserGroup, error) {
|
||||||
|
if err := ugc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := ugc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, ugc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int(id)
|
||||||
|
ugc.mutation.id = &_node.ID
|
||||||
|
ugc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugc *UserGroupCreate) createSpec() (*UserGroup, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &UserGroup{config: ugc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(usergroup.Table, sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
|
||||||
|
if id, ok := ugc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
id64 := int64(id)
|
||||||
|
_spec.ID.Value = id64
|
||||||
|
}
|
||||||
|
|
||||||
|
_spec.OnConflict = ugc.conflict
|
||||||
|
if value, ok := ugc.mutation.IsPrimary(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldIsPrimary, field.TypeBool, value)
|
||||||
|
_node.IsPrimary = value
|
||||||
|
}
|
||||||
|
if value, ok := ugc.mutation.ExpiresAt(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldExpiresAt, field.TypeTime, value)
|
||||||
|
_node.ExpiresAt = &value
|
||||||
|
}
|
||||||
|
if nodes := ugc.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.UserTable,
|
||||||
|
Columns: []string{usergroup.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.UserID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := ugc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.GroupTable,
|
||||||
|
Columns: []string{usergroup.GroupColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.GroupID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// SetUserID(v).
|
||||||
|
// OnConflict(
|
||||||
|
// // Update the row with the new values
|
||||||
|
// // the was proposed for insertion.
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// // Override some of the fields with custom
|
||||||
|
// // update values.
|
||||||
|
// Update(func(u *ent.UserGroupUpsert) {
|
||||||
|
// SetUserID(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (ugc *UserGroupCreate) OnConflict(opts ...sql.ConflictOption) *UserGroupUpsertOne {
|
||||||
|
ugc.conflict = opts
|
||||||
|
return &UserGroupUpsertOne{
|
||||||
|
create: ugc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (ugc *UserGroupCreate) OnConflictColumns(columns ...string) *UserGroupUpsertOne {
|
||||||
|
ugc.conflict = append(ugc.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &UserGroupUpsertOne{
|
||||||
|
create: ugc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// UserGroupUpsertOne is the builder for "upsert"-ing
|
||||||
|
// one UserGroup node.
|
||||||
|
UserGroupUpsertOne struct {
|
||||||
|
create *UserGroupCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupUpsert is the "OnConflict" setter.
|
||||||
|
UserGroupUpsert struct {
|
||||||
|
*sql.UpdateSet
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *UserGroupUpsert) SetUserID(v int) *UserGroupUpsert {
|
||||||
|
u.Set(usergroup.FieldUserID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsert) UpdateUserID() *UserGroupUpsert {
|
||||||
|
u.SetExcluded(usergroup.FieldUserID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (u *UserGroupUpsert) SetGroupID(v int) *UserGroupUpsert {
|
||||||
|
u.Set(usergroup.FieldGroupID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsert) UpdateGroupID() *UserGroupUpsert {
|
||||||
|
u.SetExcluded(usergroup.FieldGroupID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (u *UserGroupUpsert) SetIsPrimary(v bool) *UserGroupUpsert {
|
||||||
|
u.Set(usergroup.FieldIsPrimary, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIsPrimary sets the "is_primary" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsert) UpdateIsPrimary() *UserGroupUpsert {
|
||||||
|
u.SetExcluded(usergroup.FieldIsPrimary)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsert) SetExpiresAt(v time.Time) *UserGroupUpsert {
|
||||||
|
u.Set(usergroup.FieldExpiresAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsert) UpdateExpiresAt() *UserGroupUpsert {
|
||||||
|
u.SetExcluded(usergroup.FieldExpiresAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsert) ClearExpiresAt() *UserGroupUpsert {
|
||||||
|
u.SetNull(usergroup.FieldExpiresAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *UserGroupUpsertOne) UpdateNewValues() *UserGroupUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *UserGroupUpsertOne) Ignore() *UserGroupUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||||
|
// Supported only by SQLite and PostgreSQL.
|
||||||
|
func (u *UserGroupUpsertOne) DoNothing() *UserGroupUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the UserGroupCreate.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *UserGroupUpsertOne) Update(set func(*UserGroupUpsert)) *UserGroupUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&UserGroupUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *UserGroupUpsertOne) SetUserID(v int) *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetUserID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertOne) UpdateUserID() *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateUserID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (u *UserGroupUpsertOne) SetGroupID(v int) *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetGroupID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertOne) UpdateGroupID() *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateGroupID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (u *UserGroupUpsertOne) SetIsPrimary(v bool) *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetIsPrimary(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIsPrimary sets the "is_primary" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertOne) UpdateIsPrimary() *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateIsPrimary()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsertOne) SetExpiresAt(v time.Time) *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetExpiresAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertOne) UpdateExpiresAt() *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateExpiresAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsertOne) ClearExpiresAt() *UserGroupUpsertOne {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.ClearExpiresAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *UserGroupUpsertOne) Exec(ctx context.Context) error {
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for UserGroupCreate.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *UserGroupUpsertOne) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||||
|
func (u *UserGroupUpsertOne) ID(ctx context.Context) (id int, err error) {
|
||||||
|
node, err := u.create.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return id, err
|
||||||
|
}
|
||||||
|
return node.ID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDX is like ID, but panics if an error occurs.
|
||||||
|
func (u *UserGroupUpsertOne) IDX(ctx context.Context) int {
|
||||||
|
id, err := u.ID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *UserGroupCreate) SetRawID(t int) *UserGroupCreate {
|
||||||
|
m.mutation.SetRawID(t)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupCreateBulk is the builder for creating many UserGroup entities in bulk.
|
||||||
|
type UserGroupCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*UserGroupCreate
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the UserGroup entities in the database.
|
||||||
|
func (ugcb *UserGroupCreateBulk) Save(ctx context.Context) ([]*UserGroup, error) {
|
||||||
|
if ugcb.err != nil {
|
||||||
|
return nil, ugcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(ugcb.builders))
|
||||||
|
nodes := make([]*UserGroup, len(ugcb.builders))
|
||||||
|
mutators := make([]Mutator, len(ugcb.builders))
|
||||||
|
for i := range ugcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := ugcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*UserGroupMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, ugcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
spec.OnConflict = ugcb.conflict
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, ugcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
if specs[i].ID.Value != nil {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int(id)
|
||||||
|
}
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, ugcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (ugcb *UserGroupCreateBulk) SaveX(ctx context.Context) []*UserGroup {
|
||||||
|
v, err := ugcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ugcb *UserGroupCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := ugcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ugcb *UserGroupCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := ugcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.UserGroup.CreateBulk(builders...).
|
||||||
|
// OnConflict(
|
||||||
|
// // Update the row with the new values
|
||||||
|
// // the was proposed for insertion.
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// // Override some of the fields with custom
|
||||||
|
// // update values.
|
||||||
|
// Update(func(u *ent.UserGroupUpsert) {
|
||||||
|
// SetUserID(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (ugcb *UserGroupCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserGroupUpsertBulk {
|
||||||
|
ugcb.conflict = opts
|
||||||
|
return &UserGroupUpsertBulk{
|
||||||
|
create: ugcb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (ugcb *UserGroupCreateBulk) OnConflictColumns(columns ...string) *UserGroupUpsertBulk {
|
||||||
|
ugcb.conflict = append(ugcb.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &UserGroupUpsertBulk{
|
||||||
|
create: ugcb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupUpsertBulk is the builder for "upsert"-ing
|
||||||
|
// a bulk of UserGroup nodes.
|
||||||
|
type UserGroupUpsertBulk struct {
|
||||||
|
create *UserGroupCreateBulk
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that
|
||||||
|
// were set on create. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *UserGroupUpsertBulk) UpdateNewValues() *UserGroupUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.UserGroup.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *UserGroupUpsertBulk) Ignore() *UserGroupUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||||
|
// Supported only by SQLite and PostgreSQL.
|
||||||
|
func (u *UserGroupUpsertBulk) DoNothing() *UserGroupUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the UserGroupCreateBulk.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *UserGroupUpsertBulk) Update(set func(*UserGroupUpsert)) *UserGroupUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&UserGroupUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (u *UserGroupUpsertBulk) SetUserID(v int) *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetUserID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertBulk) UpdateUserID() *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateUserID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (u *UserGroupUpsertBulk) SetGroupID(v int) *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetGroupID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertBulk) UpdateGroupID() *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateGroupID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (u *UserGroupUpsertBulk) SetIsPrimary(v bool) *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetIsPrimary(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateIsPrimary sets the "is_primary" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertBulk) UpdateIsPrimary() *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateIsPrimary()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsertBulk) SetExpiresAt(v time.Time) *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.SetExpiresAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
|
||||||
|
func (u *UserGroupUpsertBulk) UpdateExpiresAt() *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.UpdateExpiresAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
||||||
|
func (u *UserGroupUpsertBulk) ClearExpiresAt() *UserGroupUpsertBulk {
|
||||||
|
return u.Update(func(s *UserGroupUpsert) {
|
||||||
|
s.ClearExpiresAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *UserGroupUpsertBulk) Exec(ctx context.Context) error {
|
||||||
|
if u.create.err != nil {
|
||||||
|
return u.create.err
|
||||||
|
}
|
||||||
|
for i, b := range u.create.builders {
|
||||||
|
if len(b.conflict) != 0 {
|
||||||
|
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the UserGroupCreateBulk instead", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for UserGroupCreateBulk.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *UserGroupUpsertBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/usergroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserGroupDelete is the builder for deleting a UserGroup entity.
|
||||||
|
type UserGroupDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserGroupMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserGroupDelete builder.
|
||||||
|
func (ugd *UserGroupDelete) Where(ps ...predicate.UserGroup) *UserGroupDelete {
|
||||||
|
ugd.mutation.Where(ps...)
|
||||||
|
return ugd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (ugd *UserGroupDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, ugd.sqlExec, ugd.mutation, ugd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ugd *UserGroupDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := ugd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugd *UserGroupDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(usergroup.Table, sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeInt))
|
||||||
|
if ps := ugd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, ugd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
ugd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupDeleteOne is the builder for deleting a single UserGroup entity.
|
||||||
|
type UserGroupDeleteOne struct {
|
||||||
|
ugd *UserGroupDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserGroupDelete builder.
|
||||||
|
func (ugdo *UserGroupDeleteOne) Where(ps ...predicate.UserGroup) *UserGroupDeleteOne {
|
||||||
|
ugdo.ugd.mutation.Where(ps...)
|
||||||
|
return ugdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (ugdo *UserGroupDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := ugdo.ugd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{usergroup.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ugdo *UserGroupDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := ugdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,680 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/usergroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserGroupQuery is the builder for querying UserGroup entities.
|
||||||
|
type UserGroupQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []usergroup.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.UserGroup
|
||||||
|
withUser *UserQuery
|
||||||
|
withGroup *GroupQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the UserGroupQuery builder.
|
||||||
|
func (ugq *UserGroupQuery) Where(ps ...predicate.UserGroup) *UserGroupQuery {
|
||||||
|
ugq.predicates = append(ugq.predicates, ps...)
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (ugq *UserGroupQuery) Limit(limit int) *UserGroupQuery {
|
||||||
|
ugq.ctx.Limit = &limit
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (ugq *UserGroupQuery) Offset(offset int) *UserGroupQuery {
|
||||||
|
ugq.ctx.Offset = &offset
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (ugq *UserGroupQuery) Unique(unique bool) *UserGroupQuery {
|
||||||
|
ugq.ctx.Unique = &unique
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (ugq *UserGroupQuery) Order(o ...usergroup.OrderOption) *UserGroupQuery {
|
||||||
|
ugq.order = append(ugq.order, o...)
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryUser chains the current query on the "user" edge.
|
||||||
|
func (ugq *UserGroupQuery) QueryUser() *UserQuery {
|
||||||
|
query := (&UserClient{config: ugq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := ugq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := ugq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(usergroup.Table, usergroup.FieldID, selector),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, usergroup.UserTable, usergroup.UserColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(ugq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryGroup chains the current query on the "group" edge.
|
||||||
|
func (ugq *UserGroupQuery) QueryGroup() *GroupQuery {
|
||||||
|
query := (&GroupClient{config: ugq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := ugq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := ugq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(usergroup.Table, usergroup.FieldID, selector),
|
||||||
|
sqlgraph.To(group.Table, group.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, false, usergroup.GroupTable, usergroup.GroupColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(ugq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first UserGroup entity from the query.
|
||||||
|
// Returns a *NotFoundError when no UserGroup was found.
|
||||||
|
func (ugq *UserGroupQuery) First(ctx context.Context) (*UserGroup, error) {
|
||||||
|
nodes, err := ugq.Limit(1).All(setContextOp(ctx, ugq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{usergroup.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) FirstX(ctx context.Context) *UserGroup {
|
||||||
|
node, err := ugq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first UserGroup ID from the query.
|
||||||
|
// Returns a *NotFoundError when no UserGroup ID was found.
|
||||||
|
func (ugq *UserGroupQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = ugq.Limit(1).IDs(setContextOp(ctx, ugq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{usergroup.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := ugq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single UserGroup entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one UserGroup entity is found.
|
||||||
|
// Returns a *NotFoundError when no UserGroup entities are found.
|
||||||
|
func (ugq *UserGroupQuery) Only(ctx context.Context) (*UserGroup, error) {
|
||||||
|
nodes, err := ugq.Limit(2).All(setContextOp(ctx, ugq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{usergroup.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{usergroup.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) OnlyX(ctx context.Context) *UserGroup {
|
||||||
|
node, err := ugq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only UserGroup ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one UserGroup ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (ugq *UserGroupQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = ugq.Limit(2).IDs(setContextOp(ctx, ugq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{usergroup.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{usergroup.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := ugq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of UserGroups.
|
||||||
|
func (ugq *UserGroupQuery) All(ctx context.Context) ([]*UserGroup, error) {
|
||||||
|
ctx = setContextOp(ctx, ugq.ctx, "All")
|
||||||
|
if err := ugq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*UserGroup, *UserGroupQuery]()
|
||||||
|
return withInterceptors[[]*UserGroup](ctx, ugq, qr, ugq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) AllX(ctx context.Context) []*UserGroup {
|
||||||
|
nodes, err := ugq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of UserGroup IDs.
|
||||||
|
func (ugq *UserGroupQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if ugq.ctx.Unique == nil && ugq.path != nil {
|
||||||
|
ugq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, ugq.ctx, "IDs")
|
||||||
|
if err = ugq.Select(usergroup.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := ugq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (ugq *UserGroupQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, ugq.ctx, "Count")
|
||||||
|
if err := ugq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, ugq, querierCount[*UserGroupQuery](), ugq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := ugq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (ugq *UserGroupQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, ugq.ctx, "Exist")
|
||||||
|
switch _, err := ugq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (ugq *UserGroupQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := ugq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the UserGroupQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (ugq *UserGroupQuery) Clone() *UserGroupQuery {
|
||||||
|
if ugq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &UserGroupQuery{
|
||||||
|
config: ugq.config,
|
||||||
|
ctx: ugq.ctx.Clone(),
|
||||||
|
order: append([]usergroup.OrderOption{}, ugq.order...),
|
||||||
|
inters: append([]Interceptor{}, ugq.inters...),
|
||||||
|
predicates: append([]predicate.UserGroup{}, ugq.predicates...),
|
||||||
|
withUser: ugq.withUser.Clone(),
|
||||||
|
withGroup: ugq.withGroup.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: ugq.sql.Clone(),
|
||||||
|
path: ugq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (ugq *UserGroupQuery) WithUser(opts ...func(*UserQuery)) *UserGroupQuery {
|
||||||
|
query := (&UserClient{config: ugq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
ugq.withUser = query
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (ugq *UserGroupQuery) WithGroup(opts ...func(*GroupQuery)) *UserGroupQuery {
|
||||||
|
query := (&GroupClient{config: ugq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
ugq.withGroup = query
|
||||||
|
return ugq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int `json:"user_id,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UserGroup.Query().
|
||||||
|
// GroupBy(usergroup.FieldUserID).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (ugq *UserGroupQuery) GroupBy(field string, fields ...string) *UserGroupGroupBy {
|
||||||
|
ugq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &UserGroupGroupBy{build: ugq}
|
||||||
|
grbuild.flds = &ugq.ctx.Fields
|
||||||
|
grbuild.label = usergroup.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// UserID int `json:"user_id,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.UserGroup.Query().
|
||||||
|
// Select(usergroup.FieldUserID).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (ugq *UserGroupQuery) Select(fields ...string) *UserGroupSelect {
|
||||||
|
ugq.ctx.Fields = append(ugq.ctx.Fields, fields...)
|
||||||
|
sbuild := &UserGroupSelect{UserGroupQuery: ugq}
|
||||||
|
sbuild.label = usergroup.Label
|
||||||
|
sbuild.flds, sbuild.scan = &ugq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a UserGroupSelect configured with the given aggregations.
|
||||||
|
func (ugq *UserGroupQuery) Aggregate(fns ...AggregateFunc) *UserGroupSelect {
|
||||||
|
return ugq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range ugq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, ugq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range ugq.ctx.Fields {
|
||||||
|
if !usergroup.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ugq.path != nil {
|
||||||
|
prev, err := ugq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ugq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*UserGroup, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*UserGroup{}
|
||||||
|
_spec = ugq.querySpec()
|
||||||
|
loadedTypes = [2]bool{
|
||||||
|
ugq.withUser != nil,
|
||||||
|
ugq.withGroup != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*UserGroup).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &UserGroup{config: ugq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, ugq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := ugq.withUser; query != nil {
|
||||||
|
if err := ugq.loadUser(ctx, query, nodes, nil,
|
||||||
|
func(n *UserGroup, e *User) { n.Edges.User = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := ugq.withGroup; query != nil {
|
||||||
|
if err := ugq.loadGroup(ctx, query, nodes, nil,
|
||||||
|
func(n *UserGroup, e *Group) { n.Edges.Group = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*UserGroup, init func(*UserGroup), assign func(*UserGroup, *User)) error {
|
||||||
|
ids := make([]int, 0, len(nodes))
|
||||||
|
nodeids := make(map[int][]*UserGroup)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].UserID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(user.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (ugq *UserGroupQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*UserGroup, init func(*UserGroup), assign func(*UserGroup, *Group)) error {
|
||||||
|
ids := make([]int, 0, len(nodes))
|
||||||
|
nodeids := make(map[int][]*UserGroup)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].GroupID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(group.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := ugq.querySpec()
|
||||||
|
_spec.Node.Columns = ugq.ctx.Fields
|
||||||
|
if len(ugq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = ugq.ctx.Unique != nil && *ugq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, ugq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(usergroup.Table, usergroup.Columns, sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeInt))
|
||||||
|
_spec.From = ugq.sql
|
||||||
|
if unique := ugq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if ugq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := ugq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, usergroup.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != usergroup.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ugq.withUser != nil {
|
||||||
|
_spec.Node.AddColumnOnce(usergroup.FieldUserID)
|
||||||
|
}
|
||||||
|
if ugq.withGroup != nil {
|
||||||
|
_spec.Node.AddColumnOnce(usergroup.FieldGroupID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := ugq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := ugq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := ugq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := ugq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugq *UserGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(ugq.driver.Dialect())
|
||||||
|
t1 := builder.Table(usergroup.Table)
|
||||||
|
columns := ugq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = usergroup.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if ugq.sql != nil {
|
||||||
|
selector = ugq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if ugq.ctx.Unique != nil && *ugq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range ugq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range ugq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := ugq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := ugq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupGroupBy is the group-by builder for UserGroup entities.
|
||||||
|
type UserGroupGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *UserGroupQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (uggb *UserGroupGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupGroupBy {
|
||||||
|
uggb.fns = append(uggb.fns, fns...)
|
||||||
|
return uggb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (uggb *UserGroupGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, uggb.build.ctx, "GroupBy")
|
||||||
|
if err := uggb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UserGroupQuery, *UserGroupGroupBy](ctx, uggb.build, uggb, uggb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uggb *UserGroupGroupBy) sqlScan(ctx context.Context, root *UserGroupQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(uggb.fns))
|
||||||
|
for _, fn := range uggb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*uggb.flds)+len(uggb.fns))
|
||||||
|
for _, f := range *uggb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*uggb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := uggb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupSelect is the builder for selecting fields of UserGroup entities.
|
||||||
|
type UserGroupSelect struct {
|
||||||
|
*UserGroupQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (ugs *UserGroupSelect) Aggregate(fns ...AggregateFunc) *UserGroupSelect {
|
||||||
|
ugs.fns = append(ugs.fns, fns...)
|
||||||
|
return ugs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (ugs *UserGroupSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, ugs.ctx, "Select")
|
||||||
|
if err := ugs.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*UserGroupQuery, *UserGroupSelect](ctx, ugs.UserGroupQuery, ugs, ugs.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugs *UserGroupSelect) sqlScan(ctx context.Context, root *UserGroupQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(ugs.fns))
|
||||||
|
for _, fn := range ugs.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*ugs.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := ugs.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
@ -0,0 +1,508 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/group"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/usergroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserGroupUpdate is the builder for updating UserGroup entities.
|
||||||
|
type UserGroupUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserGroupMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserGroupUpdate builder.
|
||||||
|
func (ugu *UserGroupUpdate) Where(ps ...predicate.UserGroup) *UserGroupUpdate {
|
||||||
|
ugu.mutation.Where(ps...)
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (ugu *UserGroupUpdate) SetUserID(i int) *UserGroupUpdate {
|
||||||
|
ugu.mutation.SetUserID(i)
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (ugu *UserGroupUpdate) SetNillableUserID(i *int) *UserGroupUpdate {
|
||||||
|
if i != nil {
|
||||||
|
ugu.SetUserID(*i)
|
||||||
|
}
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (ugu *UserGroupUpdate) SetGroupID(i int) *UserGroupUpdate {
|
||||||
|
ugu.mutation.SetGroupID(i)
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
|
||||||
|
func (ugu *UserGroupUpdate) SetNillableGroupID(i *int) *UserGroupUpdate {
|
||||||
|
if i != nil {
|
||||||
|
ugu.SetGroupID(*i)
|
||||||
|
}
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (ugu *UserGroupUpdate) SetIsPrimary(b bool) *UserGroupUpdate {
|
||||||
|
ugu.mutation.SetIsPrimary(b)
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
|
||||||
|
func (ugu *UserGroupUpdate) SetNillableIsPrimary(b *bool) *UserGroupUpdate {
|
||||||
|
if b != nil {
|
||||||
|
ugu.SetIsPrimary(*b)
|
||||||
|
}
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (ugu *UserGroupUpdate) SetExpiresAt(t time.Time) *UserGroupUpdate {
|
||||||
|
ugu.mutation.SetExpiresAt(t)
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
||||||
|
func (ugu *UserGroupUpdate) SetNillableExpiresAt(t *time.Time) *UserGroupUpdate {
|
||||||
|
if t != nil {
|
||||||
|
ugu.SetExpiresAt(*t)
|
||||||
|
}
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
||||||
|
func (ugu *UserGroupUpdate) ClearExpiresAt() *UserGroupUpdate {
|
||||||
|
ugu.mutation.ClearExpiresAt()
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the User entity.
|
||||||
|
func (ugu *UserGroupUpdate) SetUser(u *User) *UserGroupUpdate {
|
||||||
|
return ugu.SetUserID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroup sets the "group" edge to the Group entity.
|
||||||
|
func (ugu *UserGroupUpdate) SetGroup(g *Group) *UserGroupUpdate {
|
||||||
|
return ugu.SetGroupID(g.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserGroupMutation object of the builder.
|
||||||
|
func (ugu *UserGroupUpdate) Mutation() *UserGroupMutation {
|
||||||
|
return ugu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the User entity.
|
||||||
|
func (ugu *UserGroupUpdate) ClearUser() *UserGroupUpdate {
|
||||||
|
ugu.mutation.ClearUser()
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGroup clears the "group" edge to the Group entity.
|
||||||
|
func (ugu *UserGroupUpdate) ClearGroup() *UserGroupUpdate {
|
||||||
|
ugu.mutation.ClearGroup()
|
||||||
|
return ugu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (ugu *UserGroupUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, ugu.sqlSave, ugu.mutation, ugu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (ugu *UserGroupUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := ugu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ugu *UserGroupUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := ugu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ugu *UserGroupUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := ugu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ugu *UserGroupUpdate) check() error {
|
||||||
|
if _, ok := ugu.mutation.UserID(); ugu.mutation.UserCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "UserGroup.user"`)
|
||||||
|
}
|
||||||
|
if _, ok := ugu.mutation.GroupID(); ugu.mutation.GroupCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "UserGroup.group"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ugu *UserGroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := ugu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(usergroup.Table, usergroup.Columns, sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeInt))
|
||||||
|
if ps := ugu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := ugu.mutation.IsPrimary(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldIsPrimary, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := ugu.mutation.ExpiresAt(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldExpiresAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if ugu.mutation.ExpiresAtCleared() {
|
||||||
|
_spec.ClearField(usergroup.FieldExpiresAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if ugu.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.UserTable,
|
||||||
|
Columns: []string{usergroup.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := ugu.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.UserTable,
|
||||||
|
Columns: []string{usergroup.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if ugu.mutation.GroupCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.GroupTable,
|
||||||
|
Columns: []string{usergroup.GroupColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := ugu.mutation.GroupIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.GroupTable,
|
||||||
|
Columns: []string{usergroup.GroupColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, ugu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{usergroup.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
ugu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserGroupUpdateOne is the builder for updating a single UserGroup entity.
|
||||||
|
type UserGroupUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *UserGroupMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserID sets the "user_id" field.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetUserID(i int) *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.SetUserID(i)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetNillableUserID(i *int) *UserGroupUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
uguo.SetUserID(*i)
|
||||||
|
}
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroupID sets the "group_id" field.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetGroupID(i int) *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.SetGroupID(i)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetNillableGroupID(i *int) *UserGroupUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
uguo.SetGroupID(*i)
|
||||||
|
}
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetIsPrimary sets the "is_primary" field.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetIsPrimary(b bool) *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.SetIsPrimary(b)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetNillableIsPrimary(b *bool) *UserGroupUpdateOne {
|
||||||
|
if b != nil {
|
||||||
|
uguo.SetIsPrimary(*b)
|
||||||
|
}
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpiresAt sets the "expires_at" field.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetExpiresAt(t time.Time) *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.SetExpiresAt(t)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetNillableExpiresAt(t *time.Time) *UserGroupUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
uguo.SetExpiresAt(*t)
|
||||||
|
}
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
||||||
|
func (uguo *UserGroupUpdateOne) ClearExpiresAt() *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.ClearExpiresAt()
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUser sets the "user" edge to the User entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetUser(u *User) *UserGroupUpdateOne {
|
||||||
|
return uguo.SetUserID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGroup sets the "group" edge to the Group entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) SetGroup(g *Group) *UserGroupUpdateOne {
|
||||||
|
return uguo.SetGroupID(g.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the UserGroupMutation object of the builder.
|
||||||
|
func (uguo *UserGroupUpdateOne) Mutation() *UserGroupMutation {
|
||||||
|
return uguo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUser clears the "user" edge to the User entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) ClearUser() *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.ClearUser()
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGroup clears the "group" edge to the Group entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) ClearGroup() *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.ClearGroup()
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the UserGroupUpdate builder.
|
||||||
|
func (uguo *UserGroupUpdateOne) Where(ps ...predicate.UserGroup) *UserGroupUpdateOne {
|
||||||
|
uguo.mutation.Where(ps...)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (uguo *UserGroupUpdateOne) Select(field string, fields ...string) *UserGroupUpdateOne {
|
||||||
|
uguo.fields = append([]string{field}, fields...)
|
||||||
|
return uguo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated UserGroup entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) Save(ctx context.Context) (*UserGroup, error) {
|
||||||
|
return withHooks(ctx, uguo.sqlSave, uguo.mutation, uguo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (uguo *UserGroupUpdateOne) SaveX(ctx context.Context) *UserGroup {
|
||||||
|
node, err := uguo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (uguo *UserGroupUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := uguo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (uguo *UserGroupUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := uguo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (uguo *UserGroupUpdateOne) check() error {
|
||||||
|
if _, ok := uguo.mutation.UserID(); uguo.mutation.UserCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "UserGroup.user"`)
|
||||||
|
}
|
||||||
|
if _, ok := uguo.mutation.GroupID(); uguo.mutation.GroupCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "UserGroup.group"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uguo *UserGroupUpdateOne) sqlSave(ctx context.Context) (_node *UserGroup, err error) {
|
||||||
|
if err := uguo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(usergroup.Table, usergroup.Columns, sqlgraph.NewFieldSpec(usergroup.FieldID, field.TypeInt))
|
||||||
|
id, ok := uguo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserGroup.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := uguo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, usergroup.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !usergroup.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != usergroup.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := uguo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := uguo.mutation.IsPrimary(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldIsPrimary, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := uguo.mutation.ExpiresAt(); ok {
|
||||||
|
_spec.SetField(usergroup.FieldExpiresAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if uguo.mutation.ExpiresAtCleared() {
|
||||||
|
_spec.ClearField(usergroup.FieldExpiresAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if uguo.mutation.UserCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.UserTable,
|
||||||
|
Columns: []string{usergroup.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := uguo.mutation.UserIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.UserTable,
|
||||||
|
Columns: []string{usergroup.UserColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if uguo.mutation.GroupCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.GroupTable,
|
||||||
|
Columns: []string{usergroup.GroupColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := uguo.mutation.GroupIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: false,
|
||||||
|
Table: usergroup.GroupTable,
|
||||||
|
Columns: []string{usergroup.GroupColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &UserGroup{config: uguo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, uguo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{usergroup.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uguo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
Loading…
Reference in new issue