mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: remove multi storage support
This commit is contained in:
@@ -50,7 +50,6 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error)
|
||||
return nil, err
|
||||
}
|
||||
return NewClient(append(options, Driver(drv))...), nil
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||
}
|
||||
|
||||
@@ -20,31 +20,24 @@ type Order func(*sql.Selector)
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) Order {
|
||||
return Order(
|
||||
func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Asc(f))
|
||||
}
|
||||
},
|
||||
)
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Asc(f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) Order {
|
||||
return Order(
|
||||
func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Desc(f))
|
||||
}
|
||||
},
|
||||
)
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Desc(f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Aggregate applies an aggregation step on the group-by traversal/selector.
|
||||
type Aggregate struct {
|
||||
// SQL the column wrapped with the aggregation function.
|
||||
SQL func(*sql.Selector) string
|
||||
}
|
||||
type Aggregate func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
@@ -53,55 +46,43 @@ type Aggregate struct {
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn Aggregate, end string) Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.As(fn.SQL(s), end)
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.Max(s.C(field))
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.Avg(s.C(field))
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.Min(s.C(field))
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) Aggregate {
|
||||
return Aggregate{
|
||||
SQL: func(s *sql.Selector) string {
|
||||
return sql.Sum(s.C(field))
|
||||
},
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,201 +22,181 @@ func ID(id int) predicate.User {
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldID), v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
v := make([]interface{}, len(ids))
|
||||
for i := range v {
|
||||
v[i] = ids[i]
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// URLIsNil applies the IsNil predicate on the "url" field.
|
||||
func URLIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldURL)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldURL)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// URLNotNil applies the NotNil predicate on the "url" field.
|
||||
func URLNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldURL)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldURL)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// RawIsNil applies the IsNil predicate on the "raw" field.
|
||||
func RawIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldRaw)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldRaw)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// RawNotNil applies the NotNil predicate on the "raw" field.
|
||||
func RawNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldRaw)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldRaw)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// DirsIsNil applies the IsNil predicate on the "dirs" field.
|
||||
func DirsIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldDirs)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldDirs)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// DirsNotNil applies the NotNil predicate on the "dirs" field.
|
||||
func DirsNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldDirs)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldDirs)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IntsIsNil applies the IsNil predicate on the "ints" field.
|
||||
func IntsIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldInts)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldInts)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IntsNotNil applies the NotNil predicate on the "ints" field.
|
||||
func IntsNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldInts)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldInts)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// FloatsIsNil applies the IsNil predicate on the "floats" field.
|
||||
func FloatsIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldFloats)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldFloats)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// FloatsNotNil applies the NotNil predicate on the "floats" field.
|
||||
func FloatsNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldFloats)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldFloats)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// StringsIsNil applies the IsNil predicate on the "strings" field.
|
||||
func StringsIsNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldStrings)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldStrings)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// StringsNotNil applies the NotNil predicate on the "strings" field.
|
||||
func StringsNotNil() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldStrings)))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldStrings)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ type UserQuery struct {
|
||||
order []Order
|
||||
unique []string
|
||||
predicates []predicate.User
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||
order: append([]Order{}, uq.order...),
|
||||
unique: append([]string{}, uq.unique...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
// clone intermediate queries.
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
}
|
||||
}
|
||||
@@ -343,7 +343,7 @@ type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
|
||||
columns := make([]string, 0, len(ugb.fields)+len(ugb.fns))
|
||||
columns = append(columns, ugb.fields...)
|
||||
for _, fn := range ugb.fns {
|
||||
columns = append(columns, fn.SQL(selector))
|
||||
columns = append(columns, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(ugb.fields...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user