mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/predicate: add isnull/notnull predicates for codegen
Reviewed By: idoshveki Differential Revision: D16687226 fbshipit-source-id: 14a39e066447dbf77413e5c7f7318a2d61bddd32
This commit is contained in:
committed by
Facebook Github Bot
parent
23059c8bae
commit
25f5a2ef01
File diff suppressed because one or more lines are too long
@@ -45,16 +45,20 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// ops returns all operations for given type.
|
||||
func ops(f *Field) []Op {
|
||||
// ops returns all operations for given field.
|
||||
func ops(f *Field) (op []Op) {
|
||||
switch t := f.Type; {
|
||||
case t == field.TypeBool:
|
||||
return boolOps
|
||||
op = boolOps
|
||||
case t == field.TypeString && strings.ToLower(f.Name) != "id":
|
||||
return stringOps
|
||||
op = stringOps
|
||||
default:
|
||||
return numericOps
|
||||
op = numericOps
|
||||
}
|
||||
if f.Nullable || f.Optional {
|
||||
op = append(op, nillableOps...)
|
||||
}
|
||||
return op
|
||||
}
|
||||
|
||||
// xrange generates a slice of len n.
|
||||
|
||||
@@ -11,6 +11,8 @@ const (
|
||||
GTE // >=
|
||||
LT // <
|
||||
LTE // <=
|
||||
IsNull // IS NULL / has
|
||||
NotNull // IS NOT NULL / hasNot
|
||||
In // within
|
||||
NotIn // without
|
||||
Contains // containing
|
||||
@@ -39,6 +41,11 @@ func (o Op) Variadic() bool {
|
||||
return o == In || o == NotIn
|
||||
}
|
||||
|
||||
// Niladic reports if the predicate is a niladic predicate.
|
||||
func (o Op) Niladic() bool {
|
||||
return o == IsNull || o == NotNull
|
||||
}
|
||||
|
||||
var (
|
||||
// operations text.
|
||||
opText = [...]string{
|
||||
@@ -48,6 +55,8 @@ var (
|
||||
GTE: "GTE",
|
||||
LT: "LT",
|
||||
LTE: "LTE",
|
||||
IsNull: "IsNull",
|
||||
NotNull: "NotNull",
|
||||
Contains: "Contains",
|
||||
HasPrefix: "HasPrefix",
|
||||
HasSuffix: "HasSuffix",
|
||||
@@ -56,6 +65,8 @@ var (
|
||||
}
|
||||
// operations code in gremlin.
|
||||
gremlinCode = [...]string{
|
||||
IsNull: "HasNot",
|
||||
NotNull: "Has",
|
||||
In: "Within",
|
||||
NotIn: "Without",
|
||||
Contains: "Containing",
|
||||
@@ -63,7 +74,8 @@ var (
|
||||
HasSuffix: "EndingWith",
|
||||
}
|
||||
// operations per type.
|
||||
boolOps = []Op{EQ, NEQ}
|
||||
numericOps = append(boolOps[:], GT, GTE, LT, LTE, In, NotIn)
|
||||
stringOps = append(numericOps[:], Contains, HasPrefix, HasSuffix)
|
||||
boolOps = []Op{EQ, NEQ}
|
||||
numericOps = append(boolOps[:], GT, GTE, LT, LTE, In, NotIn)
|
||||
stringOps = append(numericOps[:], Contains, HasPrefix, HasSuffix)
|
||||
nillableOps = []Op{IsNull, NotNull}
|
||||
)
|
||||
|
||||
@@ -29,7 +29,11 @@
|
||||
{{- $f := $.Scope.Field -}}
|
||||
{{- $op := $.Scope.Op -}}
|
||||
func(t *dsl.Traversal) {
|
||||
{{- if not $op.Niladic }}
|
||||
t.Has(Label, {{ $f.Constant }}, p.{{ $op.Gremlin }}(v{{ if $op.Variadic }}...{{ end }}))
|
||||
{{- else }}
|
||||
t.HasLabel(Label).{{ $op.Gremlin }}({{ $f.Constant }})
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
return
|
||||
}
|
||||
{{- end }}
|
||||
s.Where(sql.{{ $op.Name }}(s.C({{ $f.Constant }}), v{{ if $op.Variadic }}...{{ end }}))
|
||||
s.Where(sql.{{ $op.Name }}(s.C({{ $f.Constant }}){{ if not $op.Niladic }}, v{{ if $op.Variadic }}...{{ end }}{{ end }}))
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }}
|
||||
update = true
|
||||
builder.Set({{ $.Package }}.{{ $f.Constant }}, *{{ $receiver }}.{{ $f.StructField }})
|
||||
{{- if $one }}
|
||||
{{ if $f.Nullable }}*{{ end }}{{ $.Receiver }}.{{ pascal $f.Name }} = *{{ $receiver }}.{{ $f.StructField }}
|
||||
{{- if $f.Nullable }}
|
||||
{{ $.Receiver }}.{{ pascal $f.Name }} = {{ $receiver }}.{{ $f.StructField }}
|
||||
{{- else }}
|
||||
{{ $.Receiver }}.{{ pascal $f.Name }} = *{{ $receiver }}.{{ $f.StructField }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
@@ -52,7 +52,7 @@ func ID(id {{ $.ID.Type }}) predicate.{{ $.Name }} {
|
||||
{{ $arg := "v" }}{{ if $op.Variadic }}{{ $arg = "vs" }}{{ end }}
|
||||
{{ $func := print (pascal $f.Name) ($op.Name) }}
|
||||
// {{ $func }} applies the {{ $op.Name }} predicate on the {{ quote $f.Name }} field.
|
||||
func {{ $func }}({{ $arg }} {{ if $op.Variadic }}...{{ end }}{{ $f.Type }}) predicate.{{ $.Name }} {
|
||||
func {{ $func }}({{ if not $op.Niladic }}{{ $arg }} {{ if $op.Variadic }}...{{ end }}{{ $f.Type }}{{ end }}) predicate.{{ $.Name }} {
|
||||
{{- if $op.Variadic }}
|
||||
v := make([]interface{}, len({{ $arg }}))
|
||||
for i := range v {
|
||||
|
||||
@@ -119,6 +119,8 @@ func ExampleFile() {
|
||||
Create().
|
||||
SetSize(1).
|
||||
SetName("string").
|
||||
SetUser("string").
|
||||
SetGroup("string").
|
||||
SaveX(ctx)
|
||||
log.Println("file created:", f)
|
||||
|
||||
@@ -142,6 +144,8 @@ func ExampleGroup() {
|
||||
Create().
|
||||
SetSize(1).
|
||||
SetName("string").
|
||||
SetUser("string").
|
||||
SetGroup("string").
|
||||
SaveX(ctx)
|
||||
log.Println("file created:", f0)
|
||||
u1 := client.User.
|
||||
@@ -306,6 +310,8 @@ func ExampleUser() {
|
||||
Create().
|
||||
SetSize(1).
|
||||
SetName("string").
|
||||
SetUser("string").
|
||||
SetGroup("string").
|
||||
SaveX(ctx)
|
||||
log.Println("file created:", f2)
|
||||
gr3 := client.Group.
|
||||
|
||||
@@ -1032,6 +1032,30 @@ func OptionalIntNotIn(vs ...int) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalIntIsNull applies the IsNull predicate on the "optional_int" field.
|
||||
func OptionalIntIsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldOptionalInt)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldOptionalInt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalIntNotNull applies the NotNull predicate on the "optional_int" field.
|
||||
func OptionalIntNotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldOptionalInt)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldOptionalInt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt8EQ applies the EQ predicate on the "optional_int8" field.
|
||||
func OptionalInt8EQ(v int8) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1148,6 +1172,30 @@ func OptionalInt8NotIn(vs ...int8) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt8IsNull applies the IsNull predicate on the "optional_int8" field.
|
||||
func OptionalInt8IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldOptionalInt8)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldOptionalInt8)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt8NotNull applies the NotNull predicate on the "optional_int8" field.
|
||||
func OptionalInt8NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldOptionalInt8)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldOptionalInt8)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt16EQ applies the EQ predicate on the "optional_int16" field.
|
||||
func OptionalInt16EQ(v int16) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1264,6 +1312,30 @@ func OptionalInt16NotIn(vs ...int16) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt16IsNull applies the IsNull predicate on the "optional_int16" field.
|
||||
func OptionalInt16IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldOptionalInt16)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldOptionalInt16)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt16NotNull applies the NotNull predicate on the "optional_int16" field.
|
||||
func OptionalInt16NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldOptionalInt16)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldOptionalInt16)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt32EQ applies the EQ predicate on the "optional_int32" field.
|
||||
func OptionalInt32EQ(v int32) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1380,6 +1452,30 @@ func OptionalInt32NotIn(vs ...int32) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt32IsNull applies the IsNull predicate on the "optional_int32" field.
|
||||
func OptionalInt32IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldOptionalInt32)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldOptionalInt32)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt32NotNull applies the NotNull predicate on the "optional_int32" field.
|
||||
func OptionalInt32NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldOptionalInt32)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldOptionalInt32)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt64EQ applies the EQ predicate on the "optional_int64" field.
|
||||
func OptionalInt64EQ(v int64) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1496,6 +1592,30 @@ func OptionalInt64NotIn(vs ...int64) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt64IsNull applies the IsNull predicate on the "optional_int64" field.
|
||||
func OptionalInt64IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldOptionalInt64)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldOptionalInt64)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// OptionalInt64NotNull applies the NotNull predicate on the "optional_int64" field.
|
||||
func OptionalInt64NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldOptionalInt64)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldOptionalInt64)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableIntEQ applies the EQ predicate on the "nullable_int" field.
|
||||
func NullableIntEQ(v int) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1612,6 +1732,30 @@ func NullableIntNotIn(vs ...int) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// NullableIntIsNull applies the IsNull predicate on the "nullable_int" field.
|
||||
func NullableIntIsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNullableInt)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNullableInt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableIntNotNull applies the NotNull predicate on the "nullable_int" field.
|
||||
func NullableIntNotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNullableInt)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNullableInt)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt8EQ applies the EQ predicate on the "nullable_int8" field.
|
||||
func NullableInt8EQ(v int8) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1728,6 +1872,30 @@ func NullableInt8NotIn(vs ...int8) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt8IsNull applies the IsNull predicate on the "nullable_int8" field.
|
||||
func NullableInt8IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNullableInt8)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNullableInt8)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt8NotNull applies the NotNull predicate on the "nullable_int8" field.
|
||||
func NullableInt8NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNullableInt8)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNullableInt8)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt16EQ applies the EQ predicate on the "nullable_int16" field.
|
||||
func NullableInt16EQ(v int16) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1844,6 +2012,30 @@ func NullableInt16NotIn(vs ...int16) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt16IsNull applies the IsNull predicate on the "nullable_int16" field.
|
||||
func NullableInt16IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNullableInt16)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNullableInt16)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt16NotNull applies the NotNull predicate on the "nullable_int16" field.
|
||||
func NullableInt16NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNullableInt16)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNullableInt16)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt32EQ applies the EQ predicate on the "nullable_int32" field.
|
||||
func NullableInt32EQ(v int32) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -1960,6 +2152,30 @@ func NullableInt32NotIn(vs ...int32) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt32IsNull applies the IsNull predicate on the "nullable_int32" field.
|
||||
func NullableInt32IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNullableInt32)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNullableInt32)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt32NotNull applies the NotNull predicate on the "nullable_int32" field.
|
||||
func NullableInt32NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNullableInt32)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNullableInt32)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt64EQ applies the EQ predicate on the "nullable_int64" field.
|
||||
func NullableInt64EQ(v int64) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
@@ -2076,6 +2292,30 @@ func NullableInt64NotIn(vs ...int64) predicate.FieldType {
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt64IsNull applies the IsNull predicate on the "nullable_int64" field.
|
||||
func NullableInt64IsNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNullableInt64)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNullableInt64)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NullableInt64NotNull applies the NotNull predicate on the "nullable_int64" field.
|
||||
func NullableInt64NotNull() predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNullableInt64)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNullableInt64)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.FieldType) predicate.FieldType {
|
||||
return predicate.FieldTypePerDialect(
|
||||
|
||||
@@ -735,27 +735,27 @@ func (ftuo *FieldTypeUpdateOne) sqlSave(ctx context.Context) (ft *FieldType, err
|
||||
if ftuo.nullable_int != nil {
|
||||
update = true
|
||||
builder.Set(fieldtype.FieldNullableInt, *ftuo.nullable_int)
|
||||
*ft.NullableInt = *ftuo.nullable_int
|
||||
ft.NullableInt = ftuo.nullable_int
|
||||
}
|
||||
if ftuo.nullable_int8 != nil {
|
||||
update = true
|
||||
builder.Set(fieldtype.FieldNullableInt8, *ftuo.nullable_int8)
|
||||
*ft.NullableInt8 = *ftuo.nullable_int8
|
||||
ft.NullableInt8 = ftuo.nullable_int8
|
||||
}
|
||||
if ftuo.nullable_int16 != nil {
|
||||
update = true
|
||||
builder.Set(fieldtype.FieldNullableInt16, *ftuo.nullable_int16)
|
||||
*ft.NullableInt16 = *ftuo.nullable_int16
|
||||
ft.NullableInt16 = ftuo.nullable_int16
|
||||
}
|
||||
if ftuo.nullable_int32 != nil {
|
||||
update = true
|
||||
builder.Set(fieldtype.FieldNullableInt32, *ftuo.nullable_int32)
|
||||
*ft.NullableInt32 = *ftuo.nullable_int32
|
||||
ft.NullableInt32 = ftuo.nullable_int32
|
||||
}
|
||||
if ftuo.nullable_int64 != nil {
|
||||
update = true
|
||||
builder.Set(fieldtype.FieldNullableInt64, *ftuo.nullable_int64)
|
||||
*ft.NullableInt64 = *ftuo.nullable_int64
|
||||
ft.NullableInt64 = ftuo.nullable_int64
|
||||
}
|
||||
if update {
|
||||
query, args := builder.Query()
|
||||
|
||||
@@ -20,26 +20,39 @@ type File struct {
|
||||
Size int `json:"size,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// User holds the value of the "user" field.
|
||||
User *string `json:"user,omitempty"`
|
||||
// Group holds the value of the "group" field.
|
||||
Group string `json:"group,omitempty"`
|
||||
}
|
||||
|
||||
// FromRows scans the sql response data into File.
|
||||
func (f *File) FromRows(rows *sql.Rows) error {
|
||||
var vf struct {
|
||||
ID int
|
||||
Size int
|
||||
Name string
|
||||
ID int
|
||||
Size int
|
||||
Name string
|
||||
User sql.NullString
|
||||
Group sql.NullString
|
||||
}
|
||||
// the order here should be the same as in the `file.Columns`.
|
||||
if err := rows.Scan(
|
||||
&vf.ID,
|
||||
&vf.Size,
|
||||
&vf.Name,
|
||||
&vf.User,
|
||||
&vf.Group,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
f.ID = strconv.Itoa(vf.ID)
|
||||
f.Size = vf.Size
|
||||
f.Name = vf.Name
|
||||
if vf.User.Valid {
|
||||
f.User = new(string)
|
||||
*f.User = vf.User.String
|
||||
}
|
||||
f.Group = vf.Group.String
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,9 +63,11 @@ func (f *File) FromResponse(res *gremlin.Response) error {
|
||||
return err
|
||||
}
|
||||
var vf struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
User *string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
}
|
||||
if err := vmap.Decode(&vf); err != nil {
|
||||
return err
|
||||
@@ -60,6 +75,8 @@ func (f *File) FromResponse(res *gremlin.Response) error {
|
||||
f.ID = vf.ID
|
||||
f.Size = vf.Size
|
||||
f.Name = vf.Name
|
||||
f.User = vf.User
|
||||
f.Group = vf.Group
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -88,6 +105,10 @@ func (f *File) String() string {
|
||||
buf.WriteString(fmt.Sprintf("id=%v", f.ID))
|
||||
buf.WriteString(fmt.Sprintf(", size=%v", f.Size))
|
||||
buf.WriteString(fmt.Sprintf(", name=%v", f.Name))
|
||||
if v := f.User; v != nil {
|
||||
buf.WriteString(fmt.Sprintf(", user=%v", *v))
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf(", group=%v", f.Group))
|
||||
buf.WriteString(")")
|
||||
return buf.String()
|
||||
}
|
||||
@@ -120,18 +141,22 @@ func (f *Files) FromResponse(res *gremlin.Response) error {
|
||||
return err
|
||||
}
|
||||
var vf []struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Size int `json:"size,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
User *string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
}
|
||||
if err := vmap.Decode(&vf); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range vf {
|
||||
*f = append(*f, &File{
|
||||
ID: v.ID,
|
||||
Size: v.Size,
|
||||
Name: v.Name,
|
||||
ID: v.ID,
|
||||
Size: v.Size,
|
||||
Name: v.Name,
|
||||
User: v.User,
|
||||
Group: v.Group,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,10 @@ const (
|
||||
FieldSize = "size"
|
||||
// FieldName holds the string denoting the name vertex property in the database.
|
||||
FieldName = "name"
|
||||
// FieldUser holds the string denoting the user vertex property in the database.
|
||||
FieldUser = "user"
|
||||
// FieldGroup holds the string denoting the group vertex property in the database.
|
||||
FieldGroup = "group"
|
||||
|
||||
// Table holds the table name of the file in the database.
|
||||
Table = "files"
|
||||
@@ -25,6 +29,8 @@ var Columns = []string{
|
||||
FieldID,
|
||||
FieldSize,
|
||||
FieldName,
|
||||
FieldUser,
|
||||
FieldGroup,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -180,6 +180,30 @@ func Name(v string) predicate.File {
|
||||
)
|
||||
}
|
||||
|
||||
// User applies equality check predicate on the "user" field. It's identical to UserEQ.
|
||||
func User(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.EQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Group applies equality check predicate on the "group" field. It's identical to GroupEQ.
|
||||
func Group(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.EQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// SizeEQ applies the EQ predicate on the "size" field.
|
||||
func SizeEQ(v int) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
@@ -448,6 +472,358 @@ func NameHasSuffix(v string) predicate.File {
|
||||
)
|
||||
}
|
||||
|
||||
// UserEQ applies the EQ predicate on the "user" field.
|
||||
func UserEQ(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.EQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserNEQ applies the NEQ predicate on the "user" field.
|
||||
func UserNEQ(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.NEQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserGT applies the GT predicate on the "user" field.
|
||||
func UserGT(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.GT(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserGTE applies the GTE predicate on the "user" field.
|
||||
func UserGTE(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.GTE(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserLT applies the LT predicate on the "user" field.
|
||||
func UserLT(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.LT(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserLTE applies the LTE predicate on the "user" field.
|
||||
func UserLTE(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.LTE(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserIn applies the In predicate on the "user" field.
|
||||
func UserIn(vs ...string) predicate.File {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.FilePerDialect(
|
||||
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(vs) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldUser), v...))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.Within(v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserNotIn applies the NotIn predicate on the "user" field.
|
||||
func UserNotIn(vs ...string) predicate.File {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.FilePerDialect(
|
||||
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(vs) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldUser), v...))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.Without(v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserContains applies the Contains predicate on the "user" field.
|
||||
func UserContains(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.Containing(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserHasPrefix applies the HasPrefix predicate on the "user" field.
|
||||
func UserHasPrefix(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.StartingWith(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserHasSuffix applies the HasSuffix predicate on the "user" field.
|
||||
func UserHasSuffix(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldUser), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldUser, p.EndingWith(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserIsNull applies the IsNull predicate on the "user" field.
|
||||
func UserIsNull() predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldUser)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldUser)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// UserNotNull applies the NotNull predicate on the "user" field.
|
||||
func UserNotNull() predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldUser)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldUser)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupEQ applies the EQ predicate on the "group" field.
|
||||
func GroupEQ(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.EQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupNEQ applies the NEQ predicate on the "group" field.
|
||||
func GroupNEQ(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.NEQ(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupGT applies the GT predicate on the "group" field.
|
||||
func GroupGT(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.GT(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupGTE applies the GTE predicate on the "group" field.
|
||||
func GroupGTE(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.GTE(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupLT applies the LT predicate on the "group" field.
|
||||
func GroupLT(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.LT(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupLTE applies the LTE predicate on the "group" field.
|
||||
func GroupLTE(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.LTE(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupIn applies the In predicate on the "group" field.
|
||||
func GroupIn(vs ...string) predicate.File {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.FilePerDialect(
|
||||
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(vs) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.In(s.C(FieldGroup), v...))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.Within(v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupNotIn applies the NotIn predicate on the "group" field.
|
||||
func GroupNotIn(vs ...string) predicate.File {
|
||||
v := make([]interface{}, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.FilePerDialect(
|
||||
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(vs) == 0 {
|
||||
s.Where(sql.False())
|
||||
return
|
||||
}
|
||||
s.Where(sql.NotIn(s.C(FieldGroup), v...))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.Without(v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupContains applies the Contains predicate on the "group" field.
|
||||
func GroupContains(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.Containing(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupHasPrefix applies the HasPrefix predicate on the "group" field.
|
||||
func GroupHasPrefix(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.StartingWith(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupHasSuffix applies the HasSuffix predicate on the "group" field.
|
||||
func GroupHasSuffix(v string) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldGroup), v))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.Has(Label, FieldGroup, p.EndingWith(v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupIsNull applies the IsNull predicate on the "group" field.
|
||||
func GroupIsNull() predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldGroup)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldGroup)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// GroupNotNull applies the NotNull predicate on the "group" field.
|
||||
func GroupNotNull() predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldGroup)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldGroup)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.File) predicate.File {
|
||||
return predicate.FilePerDialect(
|
||||
|
||||
@@ -20,8 +20,10 @@ import (
|
||||
// FileCreate is the builder for creating a File entity.
|
||||
type FileCreate struct {
|
||||
config
|
||||
size *int
|
||||
name *string
|
||||
size *int
|
||||
name *string
|
||||
user *string
|
||||
group *string
|
||||
}
|
||||
|
||||
// SetSize sets the size field.
|
||||
@@ -44,6 +46,34 @@ func (fc *FileCreate) SetName(s string) *FileCreate {
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetUser sets the user field.
|
||||
func (fc *FileCreate) SetUser(s string) *FileCreate {
|
||||
fc.user = &s
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableUser sets the user field if the given value is not nil.
|
||||
func (fc *FileCreate) SetNillableUser(s *string) *FileCreate {
|
||||
if s != nil {
|
||||
fc.SetUser(*s)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetGroup sets the group field.
|
||||
func (fc *FileCreate) SetGroup(s string) *FileCreate {
|
||||
fc.group = &s
|
||||
return fc
|
||||
}
|
||||
|
||||
// SetNillableGroup sets the group field if the given value is not nil.
|
||||
func (fc *FileCreate) SetNillableGroup(s *string) *FileCreate {
|
||||
if s != nil {
|
||||
fc.SetGroup(*s)
|
||||
}
|
||||
return fc
|
||||
}
|
||||
|
||||
// Save creates the File in the database.
|
||||
func (fc *FileCreate) Save(ctx context.Context) (*File, error) {
|
||||
if fc.size == nil {
|
||||
@@ -93,6 +123,14 @@ func (fc *FileCreate) sqlSave(ctx context.Context) (*File, error) {
|
||||
builder.Set(file.FieldName, *fc.name)
|
||||
f.Name = *fc.name
|
||||
}
|
||||
if fc.user != nil {
|
||||
builder.Set(file.FieldUser, *fc.user)
|
||||
f.User = fc.user
|
||||
}
|
||||
if fc.group != nil {
|
||||
builder.Set(file.FieldGroup, *fc.group)
|
||||
f.Group = *fc.group
|
||||
}
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
return nil, rollback(tx, err)
|
||||
@@ -132,5 +170,11 @@ func (fc *FileCreate) gremlin() *dsl.Traversal {
|
||||
if fc.name != nil {
|
||||
v.Property(dsl.Single, file.FieldName, *fc.name)
|
||||
}
|
||||
if fc.user != nil {
|
||||
v.Property(dsl.Single, file.FieldUser, *fc.user)
|
||||
}
|
||||
if fc.group != nil {
|
||||
v.Property(dsl.Single, file.FieldGroup, *fc.group)
|
||||
}
|
||||
return v.ValueMap(true)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ type FileUpdate struct {
|
||||
config
|
||||
size *int
|
||||
name *string
|
||||
user *string
|
||||
group *string
|
||||
predicates []predicate.File
|
||||
}
|
||||
|
||||
@@ -51,6 +53,34 @@ func (fu *FileUpdate) SetName(s string) *FileUpdate {
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetUser sets the user field.
|
||||
func (fu *FileUpdate) SetUser(s string) *FileUpdate {
|
||||
fu.user = &s
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableUser sets the user field if the given value is not nil.
|
||||
func (fu *FileUpdate) SetNillableUser(s *string) *FileUpdate {
|
||||
if s != nil {
|
||||
fu.SetUser(*s)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetGroup sets the group field.
|
||||
func (fu *FileUpdate) SetGroup(s string) *FileUpdate {
|
||||
fu.group = &s
|
||||
return fu
|
||||
}
|
||||
|
||||
// SetNillableGroup sets the group field if the given value is not nil.
|
||||
func (fu *FileUpdate) SetNillableGroup(s *string) *FileUpdate {
|
||||
if s != nil {
|
||||
fu.SetGroup(*s)
|
||||
}
|
||||
return fu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
|
||||
if fu.size != nil {
|
||||
@@ -130,6 +160,14 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
update = true
|
||||
builder.Set(file.FieldName, *fu.name)
|
||||
}
|
||||
if fu.user != nil {
|
||||
update = true
|
||||
builder.Set(file.FieldUser, *fu.user)
|
||||
}
|
||||
if fu.group != nil {
|
||||
update = true
|
||||
builder.Set(file.FieldGroup, *fu.group)
|
||||
}
|
||||
if update {
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
@@ -168,6 +206,12 @@ func (fu *FileUpdate) gremlin() *dsl.Traversal {
|
||||
if fu.name != nil {
|
||||
v.Property(dsl.Single, file.FieldName, *fu.name)
|
||||
}
|
||||
if fu.user != nil {
|
||||
v.Property(dsl.Single, file.FieldUser, *fu.user)
|
||||
}
|
||||
if fu.group != nil {
|
||||
v.Property(dsl.Single, file.FieldGroup, *fu.group)
|
||||
}
|
||||
v.Count()
|
||||
trs = append(trs, v)
|
||||
return dsl.Join(trs...)
|
||||
@@ -176,9 +220,11 @@ func (fu *FileUpdate) gremlin() *dsl.Traversal {
|
||||
// FileUpdateOne is the builder for updating a single File entity.
|
||||
type FileUpdateOne struct {
|
||||
config
|
||||
id string
|
||||
size *int
|
||||
name *string
|
||||
id string
|
||||
size *int
|
||||
name *string
|
||||
user *string
|
||||
group *string
|
||||
}
|
||||
|
||||
// SetSize sets the size field.
|
||||
@@ -201,6 +247,34 @@ func (fuo *FileUpdateOne) SetName(s string) *FileUpdateOne {
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetUser sets the user field.
|
||||
func (fuo *FileUpdateOne) SetUser(s string) *FileUpdateOne {
|
||||
fuo.user = &s
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableUser sets the user field if the given value is not nil.
|
||||
func (fuo *FileUpdateOne) SetNillableUser(s *string) *FileUpdateOne {
|
||||
if s != nil {
|
||||
fuo.SetUser(*s)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetGroup sets the group field.
|
||||
func (fuo *FileUpdateOne) SetGroup(s string) *FileUpdateOne {
|
||||
fuo.group = &s
|
||||
return fuo
|
||||
}
|
||||
|
||||
// SetNillableGroup sets the group field if the given value is not nil.
|
||||
func (fuo *FileUpdateOne) SetNillableGroup(s *string) *FileUpdateOne {
|
||||
if s != nil {
|
||||
fuo.SetGroup(*s)
|
||||
}
|
||||
return fuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
|
||||
if fuo.size != nil {
|
||||
@@ -285,6 +359,16 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (f *File, err error) {
|
||||
builder.Set(file.FieldName, *fuo.name)
|
||||
f.Name = *fuo.name
|
||||
}
|
||||
if fuo.user != nil {
|
||||
update = true
|
||||
builder.Set(file.FieldUser, *fuo.user)
|
||||
f.User = fuo.user
|
||||
}
|
||||
if fuo.group != nil {
|
||||
update = true
|
||||
builder.Set(file.FieldGroup, *fuo.group)
|
||||
f.Group = *fuo.group
|
||||
}
|
||||
if update {
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
@@ -324,6 +408,12 @@ func (fuo *FileUpdateOne) gremlin(id string) *dsl.Traversal {
|
||||
if fuo.name != nil {
|
||||
v.Property(dsl.Single, file.FieldName, *fuo.name)
|
||||
}
|
||||
if fuo.user != nil {
|
||||
v.Property(dsl.Single, file.FieldUser, *fuo.user)
|
||||
}
|
||||
if fuo.group != nil {
|
||||
v.Property(dsl.Single, file.FieldGroup, *fuo.group)
|
||||
}
|
||||
v.ValueMap(true)
|
||||
trs = append(trs, v)
|
||||
return dsl.Join(trs...)
|
||||
|
||||
@@ -509,6 +509,30 @@ func TypeHasSuffix(v string) predicate.Group {
|
||||
)
|
||||
}
|
||||
|
||||
// TypeIsNull applies the IsNull predicate on the "type" field.
|
||||
func TypeIsNull() predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldType)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldType)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// TypeNotNull applies the NotNull predicate on the "type" field.
|
||||
func TypeNotNull() predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldType)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldType)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// MaxUsersEQ applies the EQ predicate on the "max_users" field.
|
||||
func MaxUsersEQ(v int) predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
@@ -625,6 +649,30 @@ func MaxUsersNotIn(vs ...int) predicate.Group {
|
||||
)
|
||||
}
|
||||
|
||||
// MaxUsersIsNull applies the IsNull predicate on the "max_users" field.
|
||||
func MaxUsersIsNull() predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldMaxUsers)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldMaxUsers)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// MaxUsersNotNull applies the NotNull predicate on the "max_users" field.
|
||||
func MaxUsersNotNull() predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldMaxUsers)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldMaxUsers)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Group {
|
||||
return predicate.GroupPerDialect(
|
||||
|
||||
@@ -927,7 +927,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) {
|
||||
if guo._type != nil {
|
||||
update = true
|
||||
builder.Set(group.FieldType, *guo._type)
|
||||
*gr.Type = *guo._type
|
||||
gr.Type = guo._type
|
||||
}
|
||||
if guo.max_users != nil {
|
||||
update = true
|
||||
|
||||
@@ -72,6 +72,8 @@ var (
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "size", Type: field.TypeInt},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "user", Type: field.TypeString},
|
||||
{Name: "group", Type: field.TypeString},
|
||||
{Name: "group_file_id", Type: field.TypeInt, Nullable: &nullable},
|
||||
{Name: "user_file_id", Type: field.TypeInt, Nullable: &nullable},
|
||||
}
|
||||
@@ -83,14 +85,14 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "files_groups_files",
|
||||
Columns: []*schema.Column{FilesColumns[3]},
|
||||
Columns: []*schema.Column{FilesColumns[5]},
|
||||
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "files_users_files",
|
||||
Columns: []*schema.Column{FilesColumns[4]},
|
||||
Columns: []*schema.Column{FilesColumns[6]},
|
||||
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
|
||||
@@ -284,6 +284,30 @@ func ValueNotIn(vs ...int) predicate.Node {
|
||||
)
|
||||
}
|
||||
|
||||
// ValueIsNull applies the IsNull predicate on the "value" field.
|
||||
func ValueIsNull() predicate.Node {
|
||||
return predicate.NodePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldValue)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldValue)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// ValueNotNull applies the NotNull predicate on the "value" field.
|
||||
func ValueNotNull() predicate.Node {
|
||||
return predicate.NodePerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldValue)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldValue)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasPrev applies the HasEdge predicate on the "prev" edge.
|
||||
func HasPrev() predicate.Node {
|
||||
return predicate.NodePerDialect(
|
||||
|
||||
@@ -19,5 +19,10 @@ func (File) Fields() []ent.Field {
|
||||
Default(math.MaxInt32).
|
||||
Positive(),
|
||||
field.String("name"),
|
||||
field.String("user").
|
||||
Optional().
|
||||
Nullable(),
|
||||
field.String("group").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,6 +788,30 @@ func NicknameHasSuffix(v string) predicate.User {
|
||||
)
|
||||
}
|
||||
|
||||
// NicknameIsNull applies the IsNull predicate on the "nickname" field.
|
||||
func NicknameIsNull() predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldNickname)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldNickname)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// NicknameNotNull applies the NotNull predicate on the "nickname" field.
|
||||
func NicknameNotNull() predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldNickname)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldNickname)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// PhoneEQ applies the EQ predicate on the "phone" field.
|
||||
func PhoneEQ(v string) predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
@@ -940,6 +964,30 @@ func PhoneHasSuffix(v string) predicate.User {
|
||||
)
|
||||
}
|
||||
|
||||
// PhoneIsNull applies the IsNull predicate on the "phone" field.
|
||||
func PhoneIsNull() predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldPhone)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).HasNot(FieldPhone)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// PhoneNotNull applies the NotNull predicate on the "phone" field.
|
||||
func PhoneNotNull() predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldPhone)))
|
||||
},
|
||||
func(t *dsl.Traversal) {
|
||||
t.HasLabel(Label).Has(FieldPhone)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasCard applies the HasEdge predicate on the "card" edge.
|
||||
func HasCard() predicate.User {
|
||||
return predicate.UserPerDialect(
|
||||
|
||||
@@ -273,6 +273,41 @@ func Predicate(t *testing.T, client *ent.Client) {
|
||||
AllX(ctx)
|
||||
require.Equal(f3.Name, files[0].Name)
|
||||
require.Equal(f4.Name, files[1].Name)
|
||||
|
||||
require.Zero(client.File.Query().Where(file.UserNotNull()).CountX(ctx))
|
||||
require.Equal(4, client.File.Query().Where(file.UserIsNull()).CountX(ctx))
|
||||
require.Zero(client.File.Query().Where(file.GroupNotNull()).CountX(ctx))
|
||||
require.Equal(4, client.File.Query().Where(file.GroupIsNull()).CountX(ctx))
|
||||
|
||||
f1 = f1.Update().SetUser("a8m").SaveX(ctx)
|
||||
require.NotNil(f1.User)
|
||||
require.Equal("a8m", *f1.User)
|
||||
require.Equal(3, client.File.Query().Where(file.UserIsNull()).CountX(ctx))
|
||||
require.Equal(f1.Name, client.File.Query().Where(file.UserNotNull()).OnlyX(ctx).Name)
|
||||
f5 := client.File.Create().SetName("5").SetSize(40).SetUser("mashraki").SaveX(ctx)
|
||||
require.NotNil(f5.User)
|
||||
require.Equal("mashraki", *f5.User)
|
||||
require.Equal(3, client.File.Query().Where(file.UserIsNull()).CountX(ctx))
|
||||
require.Equal(2, client.File.Query().Where(file.UserNotNull()).CountX(ctx))
|
||||
|
||||
require.Equal(5, client.File.Query().Where(file.GroupIsNull()).CountX(ctx))
|
||||
f4 = f4.Update().SetGroup("fbc").SaveX(ctx)
|
||||
require.Equal(1, client.File.Query().Where(file.GroupNotNull()).CountX(ctx))
|
||||
require.Equal(4, client.File.Query().Where(file.GroupIsNull()).CountX(ctx))
|
||||
require.Equal(
|
||||
5,
|
||||
client.File.Query().
|
||||
Where(
|
||||
file.Or(
|
||||
file.GroupIsNull(),
|
||||
file.And(
|
||||
file.GroupNotNull(),
|
||||
file.Name(f4.Name),
|
||||
),
|
||||
),
|
||||
).
|
||||
CountX(ctx),
|
||||
)
|
||||
}
|
||||
|
||||
func Relation(t *testing.T, client *ent.Client) {
|
||||
|
||||
@@ -466,6 +466,24 @@ func AddressHasSuffix(v string) predicate.User {
|
||||
)
|
||||
}
|
||||
|
||||
// AddressIsNull applies the IsNull predicate on the "address" field.
|
||||
func AddressIsNull() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.IsNull(s.C(FieldAddress)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// AddressNotNull applies the NotNull predicate on the "address" field.
|
||||
func AddressNotNull() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NotNull(s.C(FieldAddress)))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// And groups list of predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(
|
||||
|
||||
Reference in New Issue
Block a user