dialect/sql/schema: accept convert from string2enum and enum2stirng (#587)

This commit is contained in:
Ariel Mashraki
2020-07-05 22:22:50 +03:00
committed by GitHub
parent 1a8d98f507
commit cedeef653a
17 changed files with 598 additions and 5 deletions

View File

@@ -29,6 +29,8 @@ const (
FieldBlob = "blob"
// FieldState holds the string denoting the state field in the database.
FieldState = "state"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// EdgeParent holds the string denoting the parent edge name in mutations.
EdgeParent = "parent"
@@ -72,6 +74,7 @@ var Columns = []string{
FieldRenamed,
FieldBlob,
FieldState,
FieldStatus,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the User type.

View File

@@ -137,6 +137,13 @@ func Blob(v []byte) predicate.User {
})
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldStatus), v))
})
}
// AgeEQ applies the EQ predicate on the "age" field.
func AgeEQ(v int32) predicate.User {
return predicate.User(func(s *sql.Selector) {
@@ -837,6 +844,131 @@ func StateNotNil() predicate.User {
})
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldStatus), v))
})
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldStatus), v))
})
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.User {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
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(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldStatus), v...))
})
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.User {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
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(v) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldStatus), v...))
})
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldStatus), v))
})
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldStatus), v))
})
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldStatus), v))
})
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldStatus), v))
})
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.Contains(s.C(FieldStatus), v))
})
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.HasPrefix(s.C(FieldStatus), v))
})
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.HasSuffix(s.C(FieldStatus), v))
})
}
// StatusIsNil applies the IsNil predicate on the "status" field.
func StatusIsNil() predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldStatus)))
})
}
// StatusNotNil applies the NotNil predicate on the "status" field.
func StatusNotNil() predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldStatus)))
})
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EqualFold(s.C(FieldStatus), v))
})
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.ContainsFold(s.C(FieldStatus), v))
})
}
// HasParent applies the HasEdge predicate on the "parent" edge.
func HasParent() predicate.User {
return predicate.User(func(s *sql.Selector) {