mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: json type support (#38)
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/38 Only `IsNil` and `NotNil` predicates are supported this moment Reviewed By: alexsn Differential Revision: D17444976 fbshipit-source-id: 37336fa0bc7749af995933baee2e23bb7366dd78
This commit is contained in:
committed by
Facebook Github Bot
parent
83d0063437
commit
c3955a08f1
@@ -7,9 +7,8 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/predicate"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their identifier.
|
||||
|
||||
@@ -10,9 +10,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/user"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/user"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
@@ -85,13 +84,13 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
return nil, err
|
||||
}
|
||||
builder := sql.Insert(user.Table).Default(uc.driver.Dialect())
|
||||
if uc.age != nil {
|
||||
builder.Set(user.FieldAge, *uc.age)
|
||||
u.Age = *uc.age
|
||||
if value := uc.age; value != nil {
|
||||
builder.Set(user.FieldAge, *value)
|
||||
u.Age = *value
|
||||
}
|
||||
if uc.name != nil {
|
||||
builder.Set(user.FieldName, *uc.name)
|
||||
u.Name = *uc.name
|
||||
if value := uc.name; value != nil {
|
||||
builder.Set(user.FieldName, *value)
|
||||
u.Name = *value
|
||||
}
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
|
||||
@@ -9,10 +9,9 @@ package ent
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/predicate"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/user"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// UserDelete is the builder for deleting a User entity.
|
||||
|
||||
@@ -12,10 +12,9 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/predicate"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/user"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// UserQuery is the builder for querying User entities.
|
||||
|
||||
@@ -10,10 +10,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/predicate"
|
||||
"github.com/facebookincubator/ent/examples/m2mbidi/ent/user"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
@@ -146,23 +145,19 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
return 0, err
|
||||
}
|
||||
var (
|
||||
update bool
|
||||
res sql.Result
|
||||
builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...))
|
||||
)
|
||||
if value := uu.age; value != nil {
|
||||
update = true
|
||||
builder.Set(user.FieldAge, *value)
|
||||
}
|
||||
if value := uu.addage; value != nil {
|
||||
update = true
|
||||
builder.Add(user.FieldAge, *value)
|
||||
}
|
||||
if value := uu.name; value != nil {
|
||||
update = true
|
||||
builder.Set(user.FieldName, *value)
|
||||
}
|
||||
if update {
|
||||
if !builder.Empty() {
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
return 0, rollback(tx, err)
|
||||
@@ -338,26 +333,22 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
update bool
|
||||
res sql.Result
|
||||
builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...))
|
||||
)
|
||||
if value := uuo.age; value != nil {
|
||||
update = true
|
||||
builder.Set(user.FieldAge, *value)
|
||||
u.Age = *value
|
||||
}
|
||||
if value := uuo.addage; value != nil {
|
||||
update = true
|
||||
builder.Add(user.FieldAge, *value)
|
||||
u.Age += *value
|
||||
}
|
||||
if value := uuo.name; value != nil {
|
||||
update = true
|
||||
builder.Set(user.FieldName, *value)
|
||||
u.Name = *value
|
||||
}
|
||||
if update {
|
||||
if !builder.Empty() {
|
||||
query, args := builder.Query()
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
return nil, rollback(tx, err)
|
||||
|
||||
Reference in New Issue
Block a user