From 4b176495e8f81e77a07fbee427b1f1c680c46db9 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 10 Jul 2019 08:30:42 -0700 Subject: [PATCH] add support for all int types in schema Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/8 Reviewed By: alexsn Differential Revision: D16131257 fbshipit-source-id: 7b362740053c684f70ec69188b2fcee898605436 --- dialect/sql/schema/mysql.go | 17 +- dialect/sql/schema/mysql_test.go | 20 +- dialect/sql/schema/schema.go | 61 +- dialect/sql/schema/schema_test.go | 51 + entc/gen/bindata.go | 73 +- entc/gen/template/dialect/sql/create.tmpl | 2 +- entc/gen/template/ent.tmpl | 9 +- entc/gen/type.go | 11 +- entc/integration/ent/client.go | 55 + entc/integration/ent/example_test.go | 38 + entc/integration/ent/fieldtype.go | 305 +++ entc/integration/ent/fieldtype/fieldtype.go | 62 + entc/integration/ent/fieldtype/where.go | 2076 +++++++++++++++++ entc/integration/ent/fieldtype_create.go | 395 ++++ entc/integration/ent/fieldtype_delete.go | 88 + entc/integration/ent/fieldtype_query.go | 616 +++++ entc/integration/ent/fieldtype_update.go | 848 +++++++ entc/integration/ent/file.go | 3 +- entc/integration/ent/group.go | 14 +- entc/integration/ent/group_create.go | 2 +- entc/integration/ent/groupinfo.go | 3 +- entc/integration/ent/migrate/migrate.go | 27 + entc/integration/ent/schema/fieldtype.go | 33 + entc/integration/ent/tx.go | 3 + entc/integration/ent/user.go | 12 +- entc/integration/integration_test.go | 2 + entc/integration/migrate/entv1/client.go | 99 + entc/integration/migrate/entv1/config.go | 51 + entc/integration/migrate/entv1/ent.go | 357 +++ .../integration/migrate/entv1/example_test.go | 53 + .../migrate/entv1/migrate/migrate.go | 32 + .../migrate/entv1/migrate/schema.go | 41 + entc/integration/migrate/entv1/schema/user.go | 19 + entc/integration/migrate/entv1/tx.go | 101 + entc/integration/migrate/entv1/user.go | 145 ++ entc/integration/migrate/entv1/user/user.go | 33 + entc/integration/migrate/entv1/user/where.go | 448 ++++ entc/integration/migrate/entv1/user_create.go | 128 + entc/integration/migrate/entv1/user_delete.go | 88 + entc/integration/migrate/entv1/user_query.go | 616 +++++ entc/integration/migrate/entv1/user_update.go | 321 +++ entc/integration/migrate/entv2/client.go | 99 + entc/integration/migrate/entv2/config.go | 51 + entc/integration/migrate/entv2/ent.go | 357 +++ .../integration/migrate/entv2/example_test.go | 54 + .../migrate/entv2/migrate/migrate.go | 33 + .../migrate/entv2/migrate/schema.go | 41 + entc/integration/migrate/entv2/schema/user.go | 23 + entc/integration/migrate/entv2/tx.go | 101 + entc/integration/migrate/entv2/user.go | 155 ++ entc/integration/migrate/entv2/user/user.go | 26 + entc/integration/migrate/entv2/user/where.go | 612 +++++ entc/integration/migrate/entv2/user_create.go | 141 ++ entc/integration/migrate/entv2/user_delete.go | 88 + entc/integration/migrate/entv2/user_query.go | 616 +++++ entc/integration/migrate/entv2/user_update.go | 340 +++ entc/integration/migrate/migrate_test.go | 57 + entc/integration/type_test.go | 80 + field/field.go | 34 +- field/field_test.go | 5 + 60 files changed, 10170 insertions(+), 101 deletions(-) create mode 100644 dialect/sql/schema/schema_test.go create mode 100644 entc/integration/ent/fieldtype.go create mode 100644 entc/integration/ent/fieldtype/fieldtype.go create mode 100644 entc/integration/ent/fieldtype/where.go create mode 100644 entc/integration/ent/fieldtype_create.go create mode 100644 entc/integration/ent/fieldtype_delete.go create mode 100644 entc/integration/ent/fieldtype_query.go create mode 100644 entc/integration/ent/fieldtype_update.go create mode 100644 entc/integration/ent/schema/fieldtype.go create mode 100644 entc/integration/migrate/entv1/client.go create mode 100644 entc/integration/migrate/entv1/config.go create mode 100644 entc/integration/migrate/entv1/ent.go create mode 100644 entc/integration/migrate/entv1/example_test.go create mode 100644 entc/integration/migrate/entv1/migrate/migrate.go create mode 100644 entc/integration/migrate/entv1/migrate/schema.go create mode 100644 entc/integration/migrate/entv1/schema/user.go create mode 100644 entc/integration/migrate/entv1/tx.go create mode 100644 entc/integration/migrate/entv1/user.go create mode 100644 entc/integration/migrate/entv1/user/user.go create mode 100644 entc/integration/migrate/entv1/user/where.go create mode 100644 entc/integration/migrate/entv1/user_create.go create mode 100644 entc/integration/migrate/entv1/user_delete.go create mode 100644 entc/integration/migrate/entv1/user_query.go create mode 100644 entc/integration/migrate/entv1/user_update.go create mode 100644 entc/integration/migrate/entv2/client.go create mode 100644 entc/integration/migrate/entv2/config.go create mode 100644 entc/integration/migrate/entv2/ent.go create mode 100644 entc/integration/migrate/entv2/example_test.go create mode 100644 entc/integration/migrate/entv2/migrate/migrate.go create mode 100644 entc/integration/migrate/entv2/migrate/schema.go create mode 100644 entc/integration/migrate/entv2/schema/user.go create mode 100644 entc/integration/migrate/entv2/tx.go create mode 100644 entc/integration/migrate/entv2/user.go create mode 100644 entc/integration/migrate/entv2/user/user.go create mode 100644 entc/integration/migrate/entv2/user/where.go create mode 100644 entc/integration/migrate/entv2/user_create.go create mode 100644 entc/integration/migrate/entv2/user_delete.go create mode 100644 entc/integration/migrate/entv2/user_query.go create mode 100644 entc/integration/migrate/entv2/user_update.go create mode 100644 entc/integration/migrate/migrate_test.go create mode 100644 entc/integration/type_test.go diff --git a/dialect/sql/schema/mysql.go b/dialect/sql/schema/mysql.go index 78b54d251..71f20b2d2 100644 --- a/dialect/sql/schema/mysql.go +++ b/dialect/sql/schema/mysql.go @@ -16,7 +16,11 @@ type MySQL struct { } // Create creates all schema resources in the database. It works in an "append-only" -// mode, which means, it won't delete or change any existing resource in the database. +// mode, which means, it only create tables, append column to tables or modifying column type. +// +// Column can be modified by turning into a NULL from NOT NULL, or having a type conversion not +// resulting data altering. From example, changing varchar(255) to varchar(120) is invalid, but +// changing varchar(120) to varchar(255) is valid. For more info, see the convert function below. func (d *MySQL) Create(ctx context.Context, tables ...*Table) error { tx, err := d.Tx(ctx) if err != nil { @@ -42,7 +46,7 @@ func (d *MySQL) create(ctx context.Context, tx dialect.Tx, tables ...*Table) err if err != nil { return err } - change, err := changeSet(curr, t) + change, err := changeSet(curr, t, version) if err != nil { return err } @@ -178,7 +182,7 @@ type changes struct { // changeSet returns a changes object to be applied on existing table. // It fails if one of the changes is invalid. -func changeSet(curr, new *Table) (*changes, error) { +func changeSet(curr, new *Table, version string) (*changes, error) { change := &changes{} // pks. if len(curr.PrimaryKey) != len(new.PrimaryKey) { @@ -196,10 +200,13 @@ func changeSet(curr, new *Table) (*changes, error) { switch c2, ok := curr.column(c1.Name); { case !ok: change.add = append(change.add, c1) - case c1.Type != c2.Type: - return nil, fmt.Errorf("changing column type for %q is invalid (%s != %s)", c1.Name, c1.Type, c2.Type) case c1.Unique != c2.Unique: return nil, fmt.Errorf("changing column cardinality for %q is invalid", c1.Name) + case c1.MySQLType(version) != c2.MySQLType(version): + if !c2.ConvertibleTo(c1) { + return nil, fmt.Errorf("changing column type for %q is invalid (%s != %s)", c1.Name, c1.MySQLType(version), c2.MySQLType(version)) + } + fallthrough case c1.Charset != "" && c1.Charset != c2.Charset || c1.Collation != "" && c1.Charset != c2.Collation: change.modify = append(change.modify, c1) } diff --git a/dialect/sql/schema/mysql_test.go b/dialect/sql/schema/mysql_test.go index 428aac9c0..2a473916a 100644 --- a/dialect/sql/schema/mysql_test.go +++ b/dialect/sql/schema/mysql_test.go @@ -59,7 +59,7 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0)) - mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` int AUTO_INCREMENT, `name` varchar(255) CHARSET utf8 NULL, `age` int, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). + mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` bigint AUTO_INCREMENT, `name` varchar(255) CHARSET utf8 NULL, `age` bigint, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectCommit() }, @@ -86,7 +86,7 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0)) - mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` int AUTO_INCREMENT, `age` int, `name` varchar(191) UNIQUE, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). + mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` bigint AUTO_INCREMENT, `age` bigint, `name` varchar(191) UNIQUE, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectCommit() }, @@ -134,12 +134,12 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0)) - mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` int AUTO_INCREMENT, `name` varchar(255) NULL, `created_at` timestamp NULL, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). + mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `users`(`id` bigint AUTO_INCREMENT, `name` varchar(255) NULL, `created_at` timestamp NULL, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("pets"). WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0)) - mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `pets`(`id` int AUTO_INCREMENT, `name` varchar(255), `owner_id` int, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). + mock.ExpectExec(escape("CREATE TABLE IF NOT EXISTS `pets`(`id` bigint AUTO_INCREMENT, `name` varchar(255), `owner_id` bigint, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `CONSTRAINT_TYPE` = ? AND `CONSTRAINT_NAME` = ?")). WithArgs("FOREIGN KEY", "pets_owner"). @@ -174,9 +174,9 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT `column_name`, `column_type`, `is_nullable`, `column_key`, `column_default`, `extra`, `character_set_name`, `collation_name` FROM INFORMATION_SCHEMA.COLUMNS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"column_name", "column_type", "is_nullable", "column_key", "column_default", "extra", "character_set_name", "collation_name"}). - AddRow("id", "int(11)", "NO", "PRI", "NULL", "auto_increment", "", ""). + AddRow("id", "bigint(20)", "NO", "PRI", "NULL", "auto_increment", "", ""). AddRow("name", "varchar(255)", "NO", "YES", "NULL", "", "", "")) - mock.ExpectExec(escape("ALTER TABLE `users` ADD COLUMN `age` int")). + mock.ExpectExec(escape("ALTER TABLE `users` ADD COLUMN `age` bigint")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectCommit() }, @@ -206,9 +206,9 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT `column_name`, `column_type`, `is_nullable`, `column_key`, `column_default`, `extra`, `character_set_name`, `collation_name` FROM INFORMATION_SCHEMA.COLUMNS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"column_name", "column_type", "is_nullable", "column_key", "column_default", "extra", "character_set_name", "collation_name"}). - AddRow("id", "int(11)", "NO", "PRI", "NULL", "auto_increment", "", ""). + AddRow("id", "bigint(20)", "NO", "PRI", "NULL", "auto_increment", "", ""). AddRow("name", "varchar(255)", "NO", "YES", "NULL", "", "", ""). - AddRow("age", "int(11)", "NO", "NO", "NULL", "", "", "")) + AddRow("age", "bigint(20)", "NO", "NO", "NULL", "", "", "")) mock.ExpectExec(escape("ALTER TABLE `users` MODIFY COLUMN `name` varchar(255) CHARSET utf8 NULL")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectCommit() @@ -250,9 +250,9 @@ func TestMySQL_Create(t *testing.T) { mock.ExpectQuery(escape("SELECT `column_name`, `column_type`, `is_nullable`, `column_key`, `column_default`, `extra`, `character_set_name`, `collation_name` FROM INFORMATION_SCHEMA.COLUMNS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `TABLE_NAME` = ?")). WithArgs("users"). WillReturnRows(sqlmock.NewRows([]string{"column_name", "column_type", "is_nullable", "column_key", "column_default", "extra", "character_set_name", "collation_name"}). - AddRow("id", "int(11)", "NO", "PRI", "NULL", "auto_increment", "", ""). + AddRow("id", "bigint(20)", "NO", "PRI", "NULL", "auto_increment", "", ""). AddRow("name", "varchar(255)", "NO", "YES", "NULL", "", "", "")) - mock.ExpectExec(escape("ALTER TABLE `users` ADD COLUMN `spouse_id` int")). + mock.ExpectExec(escape("ALTER TABLE `users` ADD COLUMN `spouse_id` bigint")). WillReturnResult(sqlmock.NewResult(0, 1)) mock.ExpectQuery(escape("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE `TABLE_SCHEMA` = (SELECT DATABASE()) AND `CONSTRAINT_TYPE` = ? AND `CONSTRAINT_NAME` = ?")). WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(0)) diff --git a/dialect/sql/schema/schema.go b/dialect/sql/schema/schema.go index 96006ff67..e46ea409c 100644 --- a/dialect/sql/schema/schema.go +++ b/dialect/sql/schema/schema.go @@ -158,14 +158,18 @@ func (c *Column) MySQLType(version string) (t string) { t = "tinyint" case field.TypeUint8: t = "tinyint unsigned" - case field.TypeInt64: - t = "bigint" - case field.TypeUint64: - t = "bigint unsigned" - case field.TypeInt, field.TypeInt16, field.TypeInt32: + case field.TypeInt16: + t = "smallint" + case field.TypeUint16: + t = "smallint unsigned" + case field.TypeInt32: t = "int" - case field.TypeUint, field.TypeUint16, field.TypeUint32: + case field.TypeUint32: t = "int unsigned" + case field.TypeInt, field.TypeInt64: + t = "bigint" + case field.TypeUint, field.TypeUint64: + t = "bigint unsigned" case field.TypeString: size := c.Size if size == 0 { @@ -187,7 +191,7 @@ func (c *Column) MySQLType(version string) (t string) { c.Nullable = &nullable } default: - panic("unsupported type " + c.Type.String()) + panic(fmt.Sprintf("unsupported type %q for column %q", c.Type.String(), c.Name)) } return t } @@ -241,11 +245,17 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error { return r == '(' || r == ')' || r == ' ' }); parts[0] { case "int": - c.Type = field.TypeInt - case "double": - c.Type = field.TypeFloat64 - case "timestamp": - c.Type = field.TypeTime + c.Type = field.TypeInt32 + case "smallint": + c.Type = field.TypeInt16 + if len(parts) == 3 { // smallint(5) unsigned. + c.Type = field.TypeUint16 + } + case "bigint": + c.Type = field.TypeInt64 + if len(parts) == 3 { // bigint(20) unsigned. + c.Type = field.TypeUint64 + } case "tinyint": size, err := strconv.Atoi(parts[1]) if err != nil { @@ -259,6 +269,10 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error { default: c.Type = field.TypeInt8 } + case "double": + c.Type = field.TypeFloat64 + case "timestamp": + c.Type = field.TypeTime case "varchar": c.Type = field.TypeString size, err := strconv.Atoi(parts[1]) @@ -270,6 +284,29 @@ func (c *Column) ScanMySQL(rows *sql.Rows) error { return nil } +// ConvertibleTo reports whether a column can be converted to the new column without altering its data. +func (c *Column) ConvertibleTo(d *Column) bool { + switch { + case c.Type == d.Type: + return c.Size <= d.Size + case c.IntType() && d.IntType() || c.UintType() && d.UintType(): + return c.Type <= d.Type + case c.UintType() && d.IntType(): + // uintX can not be converted to intY, when X > Y. + return c.Type-field.TypeUint8 <= d.Type-field.TypeInt8 + } + return c.FloatType() && d.FloatType() +} + +// IntType reports whether the column is an int type (int8 ... int64). +func (c Column) IntType() bool { return c.Type >= field.TypeInt8 && c.Type <= field.TypeInt64 } + +// UintType reports of the given type is a uint type (int8 ... int64). +func (c Column) UintType() bool { return c.Type >= field.TypeUint8 && c.Type <= field.TypeUint64 } + +// FloatType reports of the given type is a float type (float32, float64). +func (c Column) FloatType() bool { return c.Type == field.TypeFloat32 || c.Type == field.TypeFloat64 } + // unique adds the `UNIQUE` attribute if the column is a unique type. // it is exist in a different function to share the common declaration // between the two dialects. diff --git a/dialect/sql/schema/schema_test.go b/dialect/sql/schema/schema_test.go new file mode 100644 index 000000000..1b282770d --- /dev/null +++ b/dialect/sql/schema/schema_test.go @@ -0,0 +1,51 @@ +package schema + +import ( + "testing" + + "fbc/ent/field" + + "github.com/stretchr/testify/require" +) + +func TestColumn_ConvertibleTo(t *testing.T) { + c1 := &Column{Type: field.TypeString, Size: 10} + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeString, Size: 10})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeString, Size: 255})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString, Size: 9})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeFloat32})) + + c1 = &Column{Type: field.TypeFloat32} + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeFloat32})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeFloat64})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint})) + + c1 = &Column{Type: field.TypeFloat64} + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeFloat32})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeFloat64})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint})) + + c1 = &Column{Type: field.TypeUint} + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeUint})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeInt})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeInt64})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeUint64})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeInt8})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint8})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint16})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint32})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString})) + + c1 = &Column{Type: field.TypeInt} + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeInt})) + require.True(t, c1.ConvertibleTo(&Column{Type: field.TypeInt64})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeInt8})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeInt32})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint8})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint16})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeUint32})) + require.False(t, c1.ConvertibleTo(&Column{Type: field.TypeString})) +} diff --git a/entc/gen/bindata.go b/entc/gen/bindata.go index 720992213..243559afd 100644 --- a/entc/gen/bindata.go +++ b/entc/gen/bindata.go @@ -1,4 +1,4 @@ -// Package gen Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. (@generated) DO NOT EDIT. // sources: // template/base.tmpl // template/builder/create.tmpl @@ -73,32 +73,21 @@ type bindataFileInfo struct { modTime time.Time } -// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } - -// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } - -// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } - -// Mode return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } - -// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 + return false } - -// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -118,7 +107,7 @@ func templateBaseTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/base.tmpl", size: 7712, mode: os.FileMode(420), modTime: time.Unix(1562249110, 0)} + info := bindataFileInfo{name: "template/base.tmpl", size: 7712, mode: os.FileMode(420), modTime: time.Unix(1562276292, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -138,7 +127,7 @@ func templateBuilderCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2706, mode: os.FileMode(420), modTime: time.Unix(1560858190, 0)} + info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2706, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -158,7 +147,7 @@ func templateBuilderDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/delete.tmpl", size: 1903, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/builder/delete.tmpl", size: 1903, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -178,7 +167,7 @@ func templateBuilderQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/query.tmpl", size: 13074, mode: os.FileMode(420), modTime: time.Unix(1561538327, 0)} + info := bindataFileInfo{name: "template/builder/query.tmpl", size: 13074, mode: os.FileMode(420), modTime: time.Unix(1561470397, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -198,7 +187,7 @@ func templateBuilderSetterTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 2911, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 2911, mode: os.FileMode(420), modTime: time.Unix(1555862705, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -218,7 +207,7 @@ func templateBuilderUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/update.tmpl", size: 7109, mode: os.FileMode(420), modTime: time.Unix(1560858190, 0)} + info := bindataFileInfo{name: "template/builder/update.tmpl", size: 7109, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -238,7 +227,7 @@ func templateClientTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/client.tmpl", size: 5596, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/client.tmpl", size: 5596, mode: os.FileMode(420), modTime: time.Unix(1558976196, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -258,7 +247,7 @@ func templateConfigTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/config.tmpl", size: 1080, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/config.tmpl", size: 1080, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -278,7 +267,7 @@ func templateDialectGremlinCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/create.tmpl", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/create.tmpl", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -298,7 +287,7 @@ func templateDialectGremlinDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/delete.tmpl", size: 549, mode: os.FileMode(420), modTime: time.Unix(1560858190, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/delete.tmpl", size: 549, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -318,7 +307,7 @@ func templateDialectGremlinGroupTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/group.tmpl", size: 1151, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/group.tmpl", size: 1151, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -338,7 +327,7 @@ func templateDialectGremlinQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/query.tmpl", size: 2505, mode: os.FileMode(420), modTime: time.Unix(1561538327, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/query.tmpl", size: 2505, mode: os.FileMode(420), modTime: time.Unix(1561481160, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -358,12 +347,12 @@ func templateDialectGremlinUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/update.tmpl", size: 4708, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/update.tmpl", size: 4708, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } -var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x5d\x6f\xdb\x36\x17\xbe\x96\x7e\xc5\x79\x0d\xb7\x90\x02\x87\x49\x7b\x99\x77\x19\xd0\x35\x29\x60\x6c\x6d\xda\x38\xdd\x2e\xda\x62\xa0\xa5\x43\x87\x88\x4c\x39\x24\xed\x38\x30\xf4\xdf\x87\x43\x59\x96\x2c\xcb\x1f\x71\x83\x7a\x1b\xe6\x9b\x44\xf6\xf9\xe2\x73\x1e\x9e\x87\xe2\x6c\x06\x31\x0a\xa9\x10\x5a\xb1\xe4\x09\x46\xf6\xc4\xdc\x27\x27\x91\x46\x6e\xb1\x05\x59\xe6\xcf\x66\xd0\xee\x8f\x65\x12\xa3\x86\xb3\x73\x18\x71\x13\xf1\x04\xda\xac\x17\xa5\x23\x64\xbf\xcc\x7f\x99\x1b\x6a\x8c\x50\x4e\x72\xcb\xc5\xff\x0b\xf7\x2c\xf3\x7d\x31\x56\x11\x04\x4b\xb6\x59\x06\x47\xd5\x2c\x59\x16\x82\xb9\x4f\x7a\x7c\x82\x41\x64\xa7\x10\xa5\xca\xe2\xd4\xb2\xb7\xf9\xdf\x10\x02\x67\xce\x3e\xf0\x21\x42\x96\x75\x00\xb5\x4e\x75\x08\x33\xdf\x9b\x70\x0d\x81\xef\x79\x1a\x0d\x85\x60\xd7\x68\xc6\x89\xf5\x3d\xcf\x39\x5c\x57\x32\x9e\xc3\xcb\x6a\x90\x59\x94\x2a\x21\x07\x67\x50\xab\x8c\xe5\xdf\x67\xbe\x17\xfa\x9e\x9d\xba\x5c\xb4\xb8\xba\x59\xac\xe9\x3f\x76\x33\xa5\x8a\x43\xdf\x93\xc2\x59\xfe\xef\x1c\x94\x4c\xa8\x32\x4f\xa3\x1d\x6b\x45\x8f\x2e\x88\xef\x65\xbe\x57\xc1\x95\xaa\xed\x2a\x83\xda\x3a\x70\xd8\x47\x1e\xdd\xf1\x01\x95\xc6\x6e\x78\x3f\xc1\x90\x5d\xa0\xe0\xe3\xc4\xd6\xb1\x2b\x52\x5f\xe4\xed\x0b\xc2\xd0\xf7\x66\xb3\x63\xd0\x5c\x0d\x10\xda\x7f\x76\xa0\x2d\x28\x41\x9b\xbd\x93\x98\xc4\x86\xba\xe0\x51\x7d\xf5\x38\xe4\xd4\x16\xac\x67\xf5\x38\xb2\xce\x96\x70\xaa\xac\xa0\x28\x97\xf5\x70\xb5\x48\x7a\x16\xd4\x22\x63\xb9\xb2\xae\x2d\x47\xab\x19\x56\x13\x84\x14\x78\x36\x03\x29\xe8\xb7\x0f\xe3\x24\xa1\xd5\x42\x96\x91\x37\x2a\x32\xa9\xf7\x8e\xe2\x14\x34\x14\x45\x03\xe1\x7c\xb7\x7c\xbe\x47\xc0\xd3\x5a\xf3\xe0\xbe\x77\x3f\x46\xfd\xd8\x01\xae\x07\x86\x70\x2a\x16\xf9\x89\xbe\x0e\xca\x56\x9e\x9d\x83\x9d\xb2\xcb\x29\x46\xd4\xe2\x0e\x54\xdc\x3a\xf0\x52\xa3\x09\xff\xbf\xa9\xe5\x3a\x4d\x92\x3e\x8f\xee\x82\x39\x89\x42\x47\x00\x19\x2f\x18\xa5\xd1\xb0\xdf\xb8\xb1\x39\x09\xba\x71\xb0\x95\x45\xcd\x21\x57\xd0\xea\x5e\x80\xe3\x2b\x21\xcc\xba\x17\xac\x6b\x7a\x56\x4b\x35\x80\x2c\x33\x56\x47\xa9\x9a\xb0\x77\xa9\x1e\x72\xdb\x55\x36\xa0\x82\x5e\x9d\x86\x84\x7d\x62\x08\x57\x19\x2f\xfa\xb0\xc2\x2b\xcc\x79\x75\x19\x0f\xb0\xa4\x55\x82\x6a\x85\xa2\xf4\x8c\xf5\xc6\xc3\xcf\x70\x9a\xf3\x8a\xc2\x4a\x01\x5c\xc5\x64\xf6\x59\xc9\xfb\x31\x3a\x07\x4c\xc4\x35\x0a\x47\x81\x93\x23\xb8\x7a\x7d\x05\x0f\xd2\xde\x82\xc1\x44\x80\x46\x81\x1a\x55\x84\x70\x74\xe2\x72\x7b\x9e\x48\x35\xa0\x8c\x1d\x9a\xae\xca\x5d\xea\xc8\x4b\xc8\x8b\xb0\x38\x1c\x25\xdc\x36\x0e\xc3\x13\x42\x0a\xb5\x95\x71\x8b\x56\x7e\x3c\xcf\x59\xa7\x0f\xed\xe3\xcf\xa3\x98\x5b\x6c\xdc\x22\x98\xef\xe6\xca\x3e\x09\x59\x1e\xc7\xf3\xd6\x6d\x2b\x64\x6f\xd3\x64\x3c\x54\x4b\x9b\x0b\x65\x5c\x7a\xfe\x71\x8b\x1a\x03\x4a\x7d\xf9\xa9\x31\x04\xf5\x7d\xc9\x5d\xc6\x61\x58\x52\x9c\x3e\xfb\xd3\x9c\x3e\x5b\x78\x49\x9f\x06\xbc\x7e\x1c\x5c\x1b\xd1\x42\x76\xf3\x38\xc2\x86\xdc\xf4\x6d\x1d\x39\x07\xfc\x1b\x15\x07\x21\xeb\x1a\x9a\x57\xbb\x16\x71\x28\xc0\xb9\x10\x18\x59\x5c\x9e\x34\xd7\xe9\x83\x79\x33\xff\xa1\x56\xd0\xde\x89\xa4\x00\xa9\x6c\x50\xe4\x0b\xe1\xa7\x27\x0c\x83\xad\xe9\x5e\x5e\x6a\xed\xd0\xd4\x5c\x2a\xfb\x8e\xcb\x04\xe3\xd9\xd0\x0c\xce\x40\x0c\x2d\xeb\x8d\xb4\x54\x56\x04\xad\xaf\xad\x3c\xfe\x5c\x16\xbe\xb6\x20\x78\x31\x09\x81\x27\x1a\x79\xfc\x48\x67\x09\xe5\xaa\x03\x9b\x02\x87\x58\x0a\x37\x45\x2c\xe4\x7e\xa5\x5b\x2b\xef\x74\xb6\xb4\xc4\xac\x98\x56\x6e\x38\xd2\x40\x45\xf6\xfe\xf5\x7b\x80\x43\x0e\x20\x8a\xc9\x29\xe5\xe9\x5c\x2b\xfb\xf4\xf0\xca\x3d\x1c\xcf\x8b\xec\x9a\x2e\xf9\xba\x89\x9e\xdb\x17\x16\x64\xbe\x70\x2d\xe6\xfc\x9a\xb9\xb6\xe6\x7c\xb2\x6d\xa3\xe6\x3b\xc1\xac\xf1\xfb\xf8\x6b\xc5\xe9\x4b\x5e\x5c\x96\x7d\xeb\xc0\xae\xe6\x7d\x32\x2f\xb3\xfd\xce\x93\x31\x1a\x27\x64\x4b\x33\xb2\x04\xa3\x26\x2b\xa4\x26\xc7\x1a\x05\xe4\x30\x1b\xb0\xb7\x08\xe8\x34\x4d\x2a\xe8\xa7\xf6\x16\x1e\xf8\xa3\x61\xa5\xce\x54\xd2\x20\xe5\xa9\xa7\xa9\xc2\xe8\x79\x87\xd8\xf4\xcd\x44\xbd\x3a\x28\x4f\x9f\x4d\x28\xf7\xd6\xc9\x3d\x65\xd2\xff\x7b\xf5\xf1\xea\xf5\xfb\xa2\x8f\xa3\x02\xc8\x8f\xf3\xba\x0e\xd2\xd8\x11\xbb\xd2\x41\xb8\xb7\x98\x96\x0b\x7d\x36\x8a\xec\x79\x34\x28\xf9\x41\xfa\x3e\xea\xe4\x43\xef\x89\x22\x5f\x04\xab\xd2\xe5\xbb\xd8\xb2\x9d\x2c\x39\x78\xbb\xea\x7c\xa3\xcc\xef\x9a\xe4\x39\x34\xfe\x7b\x25\x3e\x55\x08\xa9\x80\x55\xa5\x7f\x31\xd9\x4b\xe7\xef\xf0\xd1\xec\xb6\x82\xe2\x38\xb0\xbc\x2d\x2b\xaf\x27\x0b\x89\x28\xd4\x66\x41\xfb\xca\x5b\x57\x8e\x02\x56\xde\xfd\x8a\xf7\xb0\x37\x36\x95\xc1\xee\xe5\x7c\x39\xfd\xb6\xf3\xd1\xcd\x5d\x39\x94\x7d\xac\x14\xbf\x28\x87\x2a\x79\x52\x72\xbf\x41\xf0\x9a\xcf\x1c\xff\x68\x05\xd8\xf7\xb4\xdf\xa0\x1b\x2b\xb0\x1f\x06\x92\x4d\x88\xfc\xb0\x97\xa1\x75\xf0\x94\x5c\xfa\x6f\x6c\xfe\x5b\xc7\xa6\x6a\xbe\x8a\x5b\x6a\xf8\xdb\x74\x38\x94\x36\xd8\x7c\xad\x56\xdc\xa4\xce\xbf\xab\x5f\x7e\x75\xc8\xca\xcf\x7c\xbf\x7c\xb9\xf1\x37\x5e\x79\x57\xcf\x38\xc5\x8d\xd7\x86\x39\xbe\x76\x88\xcf\x0f\x36\x0d\xa4\xd9\x46\x99\x65\x48\xca\xba\xff\x0a\x00\x00\xff\xff\x6d\x9c\x6e\x24\xaa\x17\x00\x00") +var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x5d\x6f\xdb\x36\x14\x7d\x96\x7e\xc5\x9d\xe1\x16\x52\xe0\x30\x69\x1f\xb3\x65\x40\xd7\xa4\x80\xb1\x75\x69\xe3\x74\x7b\x68\x8b\x81\x96\x2e\x1d\x22\x32\xe5\x90\xb4\xe3\xc0\xd0\x7f\x1f\x2e\x65\x59\xb2\x2c\x7f\xc4\x0d\xea\x6d\x98\x5e\x12\xc9\xf7\x8b\xe7\x1e\xde\x43\x69\x36\x83\x18\x85\x54\x08\xad\x58\xf2\x04\x23\x7b\x62\xee\x93\x93\x48\x23\xb7\xd8\x82\x2c\xf3\x67\x33\x68\xf7\xc7\x32\x89\x51\xc3\xd9\x39\x8c\xb8\x89\x78\x02\x6d\xd6\x8b\xd2\x11\xb2\x5f\xe6\xbf\xcc\x0d\x35\x46\x28\x27\xb9\xe5\xe2\xff\x85\x7b\x96\xf9\xbe\x18\xab\x08\x82\x25\xdb\x2c\x83\xa3\x6a\x96\x2c\x0b\xc1\xdc\x27\x3d\x3e\xc1\x20\xb2\x53\x88\x52\x65\x71\x6a\xd9\xdb\xfc\x6f\x08\x81\x33\x67\xbf\xf3\x21\x42\x96\x75\x00\xb5\x4e\x75\x08\x33\xdf\x9b\x70\x0d\x81\xef\x79\x1a\x0d\x85\x60\xd7\x68\xc6\x89\xf5\x3d\xcf\x39\x5c\x57\x32\x9e\xc3\xcb\x6a\x90\x59\x94\x2a\x21\x07\x67\x50\xab\x8c\xe5\xcf\x33\xdf\x0b\x7d\xcf\x4e\x5d\x2e\x5a\x5c\xdd\x2c\xd6\xf4\x1f\xbb\x99\x52\xc5\xa1\xef\x49\xe1\x2c\x7f\x38\x07\x25\x13\xaa\xcc\xd3\x68\xc7\x5a\xd1\xad\x0b\xe2\x7b\x99\xef\x55\x70\xa5\x6a\xbb\xca\xa0\xb6\x0e\x1c\xf6\x81\x47\x77\x7c\x40\xa5\xb1\x1b\xde\x4f\x30\x64\x17\x28\xf8\x38\xb1\x75\xec\x8a\xd4\x17\x79\xfb\x82\x30\xf4\xbd\xd9\xec\x18\x34\x57\x03\x84\xf6\x5f\x1d\x68\x0b\x4a\xd0\x66\xef\x24\x26\xb1\xa1\x2e\x78\x54\x5f\x3d\x0e\x39\xb5\x05\xeb\x59\x3d\x8e\xac\xb3\x25\x9c\x2a\x2b\x28\xca\x65\x3d\x5c\x2d\x92\xee\x05\xb5\xc8\x58\xae\xac\x6b\xcb\xd1\x6a\x86\xd5\x04\x21\x05\xae\x77\x87\x2c\x0b\xa2\x89\xa2\x45\xe0\x50\x97\x02\x54\x6a\xdd\xe3\x71\x92\x10\x32\x90\x65\x94\x09\x15\x85\xdb\x25\xa5\xef\x11\xf6\xb4\xdc\xdc\xc7\xf7\xee\xc7\xa8\x1f\x3b\xc0\xf5\xc0\x10\x54\xc5\x3a\x3f\xd2\xe3\xa0\xec\xe6\xd9\x39\xd8\x29\xbb\x9c\x62\x44\x5d\xee\x40\xc5\xad\x03\x2f\x35\x9a\xf0\xc7\x4d\x5d\xd7\x69\x92\xf4\x79\x74\x17\xcc\x79\x14\x3a\x0e\xc8\x78\x41\x2a\x8d\x86\xfd\xc6\x8d\xcd\x79\xd0\x8d\x83\xad\x44\x6a\x0e\xb9\x02\x67\xf7\x62\x01\x5e\x9b\x75\x2f\x58\xd7\xf4\xac\x96\x6a\x00\x59\x66\xac\x8e\x52\x35\x61\xef\x52\x3d\xe4\xb6\xab\x6c\x40\x05\xbd\x3a\x0d\x09\xd2\xc4\x10\xba\x32\x5e\xc0\xbb\x42\x2d\xcc\xa9\x75\x19\x0f\xb0\x64\x56\x82\x6a\x85\xa5\x74\x8f\xf5\xde\xc3\xcf\x70\x9a\x53\x8b\xc2\x4a\x01\x5c\xc5\x64\xf6\x49\xc9\xfb\x31\x3a\x07\x4c\xc4\x35\x0a\xd7\xd9\x93\x23\xb8\x7a\x7d\x05\x0f\xd2\xde\x82\xc1\x44\x80\x46\x81\x1a\x55\x84\x70\x74\xe2\x72\x7b\x9e\x48\x35\xa0\x8c\x1d\x9a\xae\xca\x5d\xea\xc8\x4b\xc8\x8b\xb0\x38\x1c\x25\xdc\x36\xce\xc3\x13\x42\x0a\xb5\x95\x71\x8b\x56\x7e\x3c\xcf\x59\xa7\x0f\x6d\xe5\x4f\xa3\x98\x5b\x6c\xdc\x25\x98\x6f\xe8\xca\x56\x09\x59\x1e\xc7\xf3\xd6\xed\x2c\x64\x6f\xd3\x64\x3c\x54\x4b\xfb\x0b\x65\x5c\x7a\xfe\x79\x8b\x1a\x03\x4a\x7d\xf9\xb1\x31\x04\xf5\x7d\xc9\x5d\xc6\x61\x58\x52\x9c\xae\xfd\x69\x4e\xd7\x16\x5e\xd2\xd5\x80\xd7\xf7\x83\x6b\x23\x5a\xc8\x6e\x1e\x47\xd8\x90\x9b\x9e\xd6\x91\x73\xc0\xbf\x51\x71\x10\xb2\xae\xa1\x31\xb4\x6b\x11\x87\x02\x9c\x0b\x81\x91\xc5\xe5\x49\x73\x9d\x3e\x98\x37\xf3\x1f\x6a\x05\xed\x9d\x48\x0a\x90\xca\x06\x45\xbe\x10\x7e\x7a\xc2\x30\xd8\x9a\xee\xe5\xa5\xd6\x0e\x4d\xcd\xa5\xb2\xef\xb8\x4c\x30\x9e\x0d\xcd\xe0\x0c\xc4\xd0\xb2\xde\x48\x4b\x65\x45\xd0\xfa\xd2\xca\xe3\xcf\x75\xe3\x4b\x0b\x82\x17\x93\x10\x78\xa2\x91\xc7\x8f\x74\x9c\x50\xae\x3a\xb0\x29\x70\x88\xa5\x70\x53\xc4\x42\xee\x57\xba\xb5\xf2\x4e\x67\x4b\x4b\xcc\x8a\x69\xe5\x86\x23\x0d\x54\x64\xef\x5f\xbf\x07\x38\xe4\x00\xa2\x98\x9c\x52\x9e\xce\x25\xb0\x4f\x37\xaf\xdc\xcd\xf1\xbc\xc8\xae\xe9\x92\xaf\x9b\xe8\xb9\x7d\x61\x41\xe6\x0b\xd7\x62\xce\xaf\x99\x6b\x6b\x8e\x28\xdb\x36\x6a\xbe\x13\xcc\x1a\xbf\x0f\xbf\x56\x9c\x3e\xe7\xc5\x65\xd9\xd7\x0e\xec\x6a\xde\x27\xf3\x32\xdb\x1f\x3c\x19\xa3\x71\x42\xb6\x34\x23\x4b\x30\x6a\xb2\x42\x6a\x72\xac\x51\x40\x0e\xb3\x01\x7b\x8b\x80\x4e\xd3\xa4\x82\x7e\x6a\x6f\xe1\x81\x3f\x1a\x56\xea\x4c\x25\x0d\x52\x9e\x7a\x9a\x2a\x8c\x9e\x77\x88\x4d\xdf\x4c\xd4\xab\x83\xf2\xf4\xd9\x84\x72\x6f\x9d\xdc\x53\x26\xfd\x7f\x56\x1f\xaf\x5e\xbf\x2f\xfa\x38\x2a\x80\xfc\x30\xaf\xeb\x20\x8d\x1d\xb1\x2b\x1d\x84\x7b\x8b\x69\xb9\xd0\x67\xa3\xc8\x9e\x47\x83\x92\x1f\xa4\xef\xa3\x4e\x3e\xf4\x9e\x28\xf2\x45\xb0\x2a\x5d\xbe\x89\x2d\xdb\xc9\x92\x83\xb7\xab\xce\x37\xca\xfc\xae\x49\x9e\x43\xe3\xbf\x55\xe2\x53\x85\x90\x0a\x58\x55\xfa\x17\x93\xbd\x74\xfe\x0e\x1f\xcd\x6e\x2b\x28\x8e\x03\xcb\xdb\xb2\xf2\x7a\xb2\x90\x88\x42\x6d\x16\xb4\xaf\xbc\x75\xe5\x28\x60\xe5\xdd\xaf\x78\x0f\x7b\x63\x53\x19\xec\x5e\xce\xe7\xd3\xaf\x3b\x1f\xdd\xdc\x57\x87\xb2\x8f\x95\xe2\x17\xe5\x50\x25\x4f\x4a\xee\x37\x08\x5e\xf3\x99\xe3\x5f\xad\x00\xfb\x9e\xf6\x1b\x74\x63\x05\xf6\xc3\x40\xb2\x09\x91\xef\xf6\x32\xb4\x0e\x9e\x92\x4b\xff\x8f\xcd\xff\xea\xd8\x54\xcd\x9f\xe2\x96\x1a\xfe\x36\x1d\x0e\xa5\x0d\x36\x7f\x56\x2b\x3e\xa6\xce\x9f\xd5\x3f\x7e\x75\xc8\xca\xcf\x7c\xbf\x7c\xb9\xf1\x37\x7e\xf5\xae\x9e\x71\x8a\x2f\x5e\x1b\xe6\xf8\xda\x21\x3e\x3f\xd8\x34\x90\x66\x1b\x65\x96\x21\x29\xeb\xfe\x3b\x00\x00\xff\xff\x43\x26\xae\xa1\xad\x17\x00\x00") func templateDialectSqlCreateTmplBytes() ([]byte, error) { return bindataRead( @@ -378,7 +367,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6058, mode: os.FileMode(420), modTime: time.Unix(1562007725, 0)} + info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6061, mode: os.FileMode(420), modTime: time.Unix(1562330003, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -398,7 +387,7 @@ func templateDialectSqlDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/delete.tmpl", size: 493, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/dialect/sql/delete.tmpl", size: 493, mode: os.FileMode(420), modTime: time.Unix(1558541632, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -418,7 +407,7 @@ func templateDialectSqlGroupTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/group.tmpl", size: 835, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/dialect/sql/group.tmpl", size: 835, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -438,7 +427,7 @@ func templateDialectSqlQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 2732, mode: os.FileMode(420), modTime: time.Unix(1561538327, 0)} + info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 2732, mode: os.FileMode(420), modTime: time.Unix(1561476415, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -458,12 +447,12 @@ func templateDialectSqlUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 11248, mode: os.FileMode(420), modTime: time.Unix(1562007725, 0)} + info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 11248, mode: os.FileMode(420), modTime: time.Unix(1561989286, 0)} a := &asset{bytes: bytes, info: info} return a, nil } -var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x4b\x8f\xe3\xb8\xf1\x3f\x5b\x9f\xa2\x56\xf0\x2c\x24\xc3\x2d\xef\xe1\x8f\xff\xa1\x17\x3e\x24\xe3\x2c\xe0\x43\x66\x93\x79\x6c\x0e\x83\xc1\x0c\x5b\x2a\xd9\x4c\x4b\xa4\x87\xa4\xdc\xdd\x50\xf4\xdd\x83\x22\x25\x99\x92\x35\x6d\xcf\x74\x80\x5c\x72\xb2\x45\x16\xeb\xf1\xab\x27\x59\xd7\x90\x61\xce\x05\x42\x58\xca\x0c\x8b\x10\x9a\x26\x08\xea\x1a\xe6\x87\xfb\x1d\xdc\xae\xe1\x8e\x69\x84\x79\xf2\x5a\x8a\x9c\xef\x92\xbf\xb1\xf4\x9e\xed\x90\x88\xea\x1a\x0c\x96\x87\x82\x19\x84\x70\x8f\x2c\x43\x15\xba\x53\x2d\x87\xd3\x2e\x2f\x0f\x52\x99\x10\xe6\x76\x6b\xb5\x02\xe2\x9f\xbc\x61\x25\x31\x02\xae\xc1\xec\x11\xac\x78\x40\x61\xb8\x79\x82\x5c\x2a\xbb\x38\x20\xd4\xe9\x1e\x4b\x96\x04\xe6\xe9\x30\xde\x31\xaa\x4a\x0d\xd4\xc1\x2c\xb5\x7a\x06\xb3\xd5\x0a\xb6\x1b\x90\xb9\xe5\x82\xc2\x24\xc1\x6c\xbb\x71\x87\xb6\x9b\xe4\x3d\x71\x68\x1a\xf8\xf2\x4f\x2d\xc5\x6d\xc8\xb3\xa5\x2c\x39\xe9\x6b\x9e\xc2\x2f\xc1\xac\xae\x41\x31\xb1\x43\x98\x7f\x5e\xc2\x3c\x27\x18\xe6\xc9\x6f\x1c\x8b\x4c\xc3\x4d\xd3\x04\xb3\x99\xb3\xe1\xc0\x74\xca\x0a\x98\xe7\xbd\x22\x7b\x49\x34\x24\xf3\xc8\x8a\x0a\x3b\x05\x42\x12\xdc\x53\x85\x90\x13\xaf\x24\x00\x00\x98\x4d\xf2\xa9\x6b\xe0\xb9\x5d\xa8\x8a\x82\xdd\x15\xb4\xb8\xa8\x6b\x40\x91\x41\xd3\x38\x6e\xbd\x11\xee\xf3\x9d\xc5\xe0\x3d\x23\xfc\x9d\x0d\x44\x6c\xd5\x1d\xda\x83\xce\x9e\xbf\x64\x3b\xec\xcc\xa9\xeb\xd5\x02\xf8\x4e\x48\x85\xb0\x43\x81\x8a\x19\x2e\x76\x80\xd9\x0e\x9d\xae\x1a\x16\xab\x96\xf2\x06\x1e\xb8\xd9\xc3\x1c\x3d\x89\x8e\xcb\x08\x15\xbc\x84\x0a\xe9\x7d\x22\x22\x61\x09\xbc\xef\x89\x34\x1a\x30\x12\x04\x2f\x96\xc0\x44\x06\x7a\x2f\xab\x22\x83\x3b\x84\xea\x90\x31\x83\x19\x94\x4c\x54\xac\x28\x9e\x12\x92\x3d\x29\xd8\xc1\x28\xa4\xa1\xc5\x0f\x82\x7f\xad\x68\xf9\xe3\xa7\x1e\xc9\x85\xd3\x81\xa0\xec\x0f\x7d\x71\x6b\x23\x3c\xc7\x80\x76\xff\xdb\x6c\x51\x98\x22\x3f\xa2\x72\xd8\xbe\xed\xbe\xda\x78\xff\x4d\xc9\xf2\x2d\xea\x83\x14\x1a\x41\xa7\x4c\x38\x34\x76\x0a\xcb\x82\x0b\x50\xdd\x56\xc6\x0c\x03\x2e\x8c\x1c\x84\x77\x12\xe4\x95\x48\x21\x1a\xc8\x69\x1a\x58\xf8\x44\xf1\x40\x48\xa4\x50\xc3\xa2\xe5\x9f\x74\xab\x31\xa0\x52\x52\x51\x9e\x1c\x4b\x76\x58\xd2\x27\x29\xac\x50\x27\x6f\x91\x65\x7f\x10\xf0\x7f\x65\x87\x28\x0e\x66\x3c\xb7\xbb\x3f\xad\xc9\x03\x74\x62\xa6\xd0\x54\x4a\xd0\x6a\x30\xb3\x18\xdc\xc0\x9c\x6c\x21\x0e\x07\xc5\x85\x81\xf0\x18\x0e\x34\x0c\x66\x47\xa6\xac\x29\x96\x6e\x90\xa8\x94\x8e\x70\x96\x90\xdf\xca\xc8\x67\x53\xd2\x05\x1f\xe9\xf3\x4c\x22\x6d\xf5\x7b\x6e\x97\xb8\x30\xff\xff\x7f\xe4\xc0\x42\xa3\xcb\xa5\x6b\x33\xad\x5f\xed\xb4\x1c\x64\xf5\xb9\xc2\x8e\xd8\x82\xd5\xa2\x79\xbb\x06\x02\x3e\xd9\x60\x2a\x33\x8c\x7e\xf6\xa0\x89\x7f\xbd\x88\xf7\x00\xdb\x64\xbb\x81\xb5\x8f\x6d\xb2\xdd\x3c\x5f\xb9\xfa\xfc\x1d\xb0\x99\x2c\x3f\xc4\xf8\x66\x0c\x9c\xe1\xa5\x4d\xa2\xc7\xc8\x97\x3a\x09\xfb\x12\x7e\x89\xc1\xc7\xf8\xe6\xc2\x01\x0f\x2d\x3f\xcf\x5a\x08\x04\x2f\x02\x2f\x91\xe4\x83\xf6\x92\x48\x7f\x2d\xfe\x93\x09\x24\x1f\x74\xa4\x48\xc2\x42\x7f\x2d\x12\xfa\xf4\xb2\xe6\x64\xc8\x8b\x42\x9e\x80\xa5\xa8\xdf\xea\x77\x46\x51\xa1\xb5\x51\x39\x88\x49\x3f\x2b\x3c\x70\x5e\x98\x07\x52\x0d\x22\x7d\x9e\x27\xbf\x1f\x0c\x97\x82\x15\x7d\xac\xd3\xa6\x27\xf7\xa4\xd0\x79\x1a\x9c\x45\xf9\x6a\x65\x3d\x22\x55\x86\x0a\xf6\xa8\xd0\x2b\xda\xd6\x55\xa4\x0c\xd3\xc0\x85\xfd\xb4\x85\xd6\x1b\x29\x92\xd7\xb2\xa8\x4a\xa1\xbf\x24\x7e\xc2\x90\x33\x92\x77\x29\x13\x11\x59\xf7\xf3\x30\xe2\x97\x9d\xc5\x17\x40\x19\x9e\x9b\x8e\xd9\x8e\x55\x67\xd0\x0f\x67\xe4\x84\x7b\xb5\x51\xa9\x14\xc7\x64\x6b\x24\x8b\x86\x26\xc4\x43\x98\x4f\x1b\x83\x9c\xb8\x64\xe1\x29\x5f\xbd\x3a\xd6\x59\x34\x4a\x64\x0b\xc8\x58\xf9\x6f\xd4\x81\x11\x6e\xe7\x34\x3d\x6a\xce\x04\xcb\x9b\xe7\x70\x11\xee\xe4\x0f\x56\xf0\xcc\xc2\xfa\x7d\xda\xd8\xbc\xcb\x21\x7c\xa5\x93\x57\x3a\x6c\xa5\x44\x43\xea\x18\xfe\xe5\xc7\xb2\x05\xaa\x53\xae\x19\xfb\xf9\xa4\xbe\xc3\xc9\x4b\x89\xe0\x7a\xd5\x5e\xac\xd9\x08\xc4\xeb\xc5\x5e\x72\x8f\x6f\xab\xff\x7f\x58\x5c\x9f\x99\x11\xdb\xaa\x3c\xb7\x45\xf4\xd4\xec\xff\x5e\xa1\x7a\x0a\x4f\x06\x62\x6b\x60\xe3\x2a\x41\x7f\xa2\x69\xe0\x6b\x85\x8a\xa3\xfe\xc6\xd4\xe7\xcf\x83\xa7\x92\x3d\xbb\xaa\x66\x7b\x52\xa2\x18\xc6\xe3\x5c\xd3\x58\x25\xfd\xe4\x75\x4d\xb7\x63\xf0\xba\xe0\x28\x4c\x0d\x63\xb4\xdd\x35\xa2\x89\x13\x9f\xff\x88\x28\xa6\x22\x70\x4a\x52\x6a\x4f\x1f\xec\x64\x0a\x4e\x94\x06\x06\x77\x15\x2f\xa8\x18\xd2\x7d\xc6\x8e\xad\x54\x0e\xcc\x9e\xeb\x91\xb1\xab\x15\xbc\x91\x86\xaa\x24\x33\x4b\x78\x92\x15\x08\xc4\x8c\xe6\xdf\x94\x15\xc5\x90\xf8\x83\x78\x50\x34\xa3\xc1\x1d\xe6\x34\xb0\x13\x45\xcf\xb6\x44\xb3\x97\xd9\x92\x42\xf9\x4c\x0c\x49\x79\x60\xba\x55\x0f\x33\xc8\x95\x2c\x81\x81\x51\x4c\x68\x96\x52\xd4\xbb\x51\x9b\x9c\xe1\x2d\xda\x43\xa9\x2c\x4b\x6e\x68\xec\x96\x0a\x94\x2c\x0a\xcc\xe0\x8e\xa5\xf7\x57\xf6\x56\x87\x4c\xe7\xa2\x6e\xdd\xad\xfe\x2e\x90\x3c\xf4\x63\x0e\xea\x59\x9c\xbb\xa7\xf5\x89\x85\x0b\x2a\xfb\xa3\xbb\xfb\x20\x5d\x32\x09\xec\x4b\x80\x00\xcb\x0d\x2a\xe0\x8e\x30\x2d\xa4\xc6\x6c\x49\x6c\xb5\x74\xe7\xc9\x3d\x02\x1f\x4d\x1f\xe3\x0f\xbc\x28\xa8\xe1\xe1\x23\xa6\x15\xe1\x65\xf6\x4a\x56\xbb\xbd\x95\x9c\x29\xab\xdd\xc3\x9e\xa7\x7b\x48\x15\x32\x47\x30\x80\xfb\x5a\x44\xbb\x30\x18\xac\x13\x90\xe6\x71\x09\xf2\x9e\x32\x75\x1a\xb5\xc4\x69\x91\x44\x0b\xf3\xb8\xb1\x7f\xdd\xbc\xff\x93\xbc\xb7\x99\x72\x60\x82\xa7\x51\xd8\x3d\x02\x34\xcd\xed\xd9\x85\x9d\xae\x54\x03\x9c\x58\x77\x75\x0f\xe3\xc9\xde\x38\x90\x0c\x6b\x30\x8f\x49\xa6\x8e\xbd\xd3\x47\xe4\xad\xeb\xda\xf6\xc9\xcb\x43\x81\x25\x0a\xe3\xbc\x97\x97\x26\x71\x3b\xa8\xae\xc4\xca\x91\x47\x31\x0d\x63\xc4\xb1\x0e\x66\x77\x95\xed\xa2\x77\x4f\x06\x75\xf2\x06\x1f\xfe\x5c\xe5\x39\xaa\x48\xf0\x22\xb6\x9b\xc9\x3f\x14\x37\xd8\x1e\x0c\x7d\x76\x51\x38\x41\x61\x95\x72\x0d\x20\x0a\x79\xb6\x7e\x75\x5c\x86\xcb\x33\xfc\xb7\x9b\x38\x1e\x74\x73\xfe\x6c\x37\xdf\x19\x98\x73\xf8\xa5\xed\x08\x67\x4a\x2d\x81\x34\x39\xef\x65\x93\x73\x00\xcf\xe1\x38\x15\x12\x53\x4d\xe3\x57\x38\xfa\x63\xcf\xb9\xe8\x81\xb5\x83\x5b\xd0\xfa\xd5\x31\x5c\xc2\xe2\x48\x76\xba\x5e\x3b\xea\x6b\xdf\xcb\xea\x1a\x7d\xe3\x31\x0c\xfe\xff\x33\xd8\x62\x42\xad\x8d\x3b\xda\xec\x82\xc3\x75\xc1\x9b\xa9\xf1\x8d\x82\x91\x67\x7d\x5d\xa7\x28\xa4\x16\xa8\xf0\xa0\x50\xa3\x30\xcc\x96\x8a\xb6\x8d\x6d\x37\xdd\xfb\xce\x55\xb1\xc9\xb3\x28\xb6\xdc\xea\x60\xc6\xb3\x25\x7c\x26\x2f\x75\xf3\xe2\x9f\x8c\xe4\x63\x06\x14\x45\xbd\x01\x3c\x0b\x9a\xc0\x33\xd7\x3e\x46\xe8\x82\xa7\xb6\x83\x1f\x8a\x4a\x11\x52\x7e\x07\x38\x11\xb8\x54\x66\x70\x60\x4a\xdb\x48\x71\xcb\x32\x1f\x35\xa7\xfe\xbd\xad\x3f\xf6\xf1\xd3\xc0\x88\x17\xbc\x71\x74\x2c\x9f\x05\xab\x23\xfa\x2f\xbe\x71\x5c\x7f\xdf\xfb\xf8\xe9\x7f\x8f\x1c\x3f\xfc\xc8\x41\x73\xd2\xe7\xa5\xab\x54\x0e\x0a\x1f\x5a\x3a\xb0\x18\x47\xc8\x1a\xd8\xe1\x80\x22\x8b\xc6\x3b\x4b\x18\x4c\x12\xb6\x92\x6d\x37\xb7\x70\x3c\xdd\x1b\x2f\x5e\x1b\x27\xf1\xbe\x7d\xfe\x75\xe4\x38\x59\xa3\x46\x4f\x22\xd3\x44\x3d\x9e\x9d\x7e\xfd\x4b\xc8\xcc\x8d\x9b\x2f\x7d\x11\xf9\x91\x74\x7b\xf6\x45\x24\xb7\xd3\xe0\x03\xb5\xd0\x47\x13\xc5\xd6\x45\xd7\x64\xcd\xcc\xf7\xeb\xed\x7a\xe4\x2a\x22\x38\x45\x93\x7f\xc7\x19\x68\x74\x1e\x4e\x83\x78\xb2\xed\xe7\x7b\xe2\xc5\x8f\xd4\x09\xb4\xa7\x21\x1b\x22\xe6\xe6\x9c\x28\xcd\x77\xed\xdf\xb8\x43\x89\x0f\x63\x7a\xc0\x22\x38\xbb\xef\x7d\xe4\x9f\xda\x99\x09\xd6\x90\xe6\x3b\x52\xc7\xbf\x6d\xfc\x3b\x00\x00\xff\xff\xef\xee\x8f\x73\xb8\x19\x00\x00") +var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\xcd\x8f\xdb\xb8\x15\x3f\x5b\x7f\xc5\x5b\xc1\x59\x48\x86\x47\xde\x43\xd1\xc3\x2c\x7c\x68\xe3\x2e\xe0\x43\xb3\x6d\x3e\xb6\x87\x20\x48\x38\xd2\x93\xcd\x46\x22\x1d\x92\xb2\x67\xe0\xea\x7f\x2f\x1e\x29\xc9\xa4\xec\x8c\xbd\x49\x81\x5e\xf6\x64\x8b\x7c\x7c\x1f\xbf\xf7\x49\x1e\x8f\x50\x60\xc9\x05\x42\x5c\xcb\x02\xab\x18\xda\x36\x8a\x8e\x47\x98\xee\x3e\x6f\xe0\x7e\x09\x0f\x4c\x23\x4c\xb3\x97\x52\x94\x7c\x93\xfd\x83\xe5\x9f\xd9\x06\x89\xe8\x78\x04\x83\xf5\xae\x62\x06\x21\xde\x22\x2b\x50\xc5\xee\x54\xc7\xe1\xb4\xcb\xeb\x9d\x54\x26\x86\xa9\xdd\x5a\x2c\x80\xf8\x67\xaf\x58\x4d\x8c\x80\x6b\x30\x5b\x04\x2b\x1e\x50\x18\x6e\x9e\xa0\x94\xca\x2e\x06\x84\x3a\xdf\x62\xcd\xb2\xc8\x3c\xed\xc6\x3b\x46\x35\xb9\x81\x63\x34\xc9\xad\x9e\xd1\x64\xb1\x80\xf5\x0a\x64\x69\xb9\xa0\x30\x59\x34\x59\xaf\xdc\xa1\xf5\x2a\x7b\x4b\x1c\xda\x16\x3e\xfd\x5b\x4b\x71\x1f\xf3\x62\x2e\x6b\x4e\xfa\x9a\xa7\xf8\x53\x34\x39\x1e\x41\x31\xb1\x41\x98\x7e\x9c\xc3\xb4\x24\x18\xa6\xd9\x2f\x1c\xab\x42\xc3\x5d\xdb\x46\x93\x89\xb3\x61\xc7\x74\xce\x2a\x98\x96\x83\x22\x5b\x49\x34\x24\x73\xcf\xaa\x06\x7b\x05\x62\x12\x3c\x50\xc5\x50\x12\xaf\x2c\x02\x00\x98\x5c\xe4\x73\x3c\x02\x2f\xed\x42\x53\x55\xec\xa1\xa2\xc5\xd9\xf1\x08\x28\x0a\x68\x5b\xc7\x6d\x30\xc2\x7d\xbe\xb1\x18\xbc\x65\x84\xbf\xb3\x81\x88\xad\xba\xa1\x3d\xe8\xec\xf9\x5b\xb1\xc1\xde\x9c\xe3\x71\x31\x03\xbe\x11\x52\x21\x6c\x50\xa0\x62\x86\x8b\x0d\x60\xb1\x41\xa7\xab\x86\xd9\xa2\xa3\xbc\x83\x03\x37\x5b\x98\xa2\x27\xd1\x71\x19\xa1\x82\xd7\x50\x21\xbd\x4f\x44\x24\x2c\x83\xb7\x03\x91\x46\x03\x46\x82\xe0\xd5\x1c\x98\x28\x40\x6f\x65\x53\x15\xf0\x80\xd0\xec\x0a\x66\xb0\x80\x9a\x89\x86\x55\xd5\x53\x46\xb2\x2f\x0a\x76\x30\x0a\x69\x68\xf1\x9d\xe0\x5f\x1a\x5a\x7e\xff\x61\x40\x72\xe6\x74\x20\x28\x87\x43\x9f\xdc\xda\x08\xcf\x31\xa0\xfd\xff\x2e\x5b\x14\xe6\xc8\xf7\xa8\x1c\xb6\xaf\xfb\xaf\x2e\xde\x7f\x51\xb2\x7e\x8d\x7a\x27\x85\x46\xd0\x39\x13\x0e\x8d\x8d\xc2\xba\xe2\x02\x54\xbf\x55\x30\xc3\x80\x0b\x23\x83\xf0\xce\xa2\xb2\x11\x39\x24\x81\x9c\xb6\x85\x99\x4f\x94\x06\x42\x12\x85\x1a\x66\x1d\xff\xac\x5f\x4d\x01\x95\x92\x8a\xf2\x64\x5f\xb3\xdd\x9c\x3e\x49\x61\x85\x3a\x7b\x8d\xac\xf8\x8d\x80\xff\x3b\xdb\x25\x69\x34\xe1\xa5\xdd\xfd\x61\x49\x1e\xa0\x13\x13\x85\xa6\x51\x82\x56\xa3\x89\xc5\xe0\x0e\xa6\x64\x0b\x71\xd8\x29\x2e\x0c\xc4\xfb\x38\xd0\x30\x9a\xec\x99\xb2\xa6\x58\xba\x20\x51\x29\x1d\xe1\x2c\x21\xbf\x96\x91\xcf\xa6\xa4\x0b\x3e\xd2\xe7\x99\x44\x5a\xeb\xb7\xdc\x2e\x71\x61\xfe\xfc\x27\x72\x60\xa5\xd1\xe5\xd2\xad\x99\x36\xac\xf6\x5a\x06\x59\x7d\xae\xb0\x23\xb6\x60\x75\x68\xde\x2f\x81\x80\xcf\x56\x98\xcb\x02\x93\x1f\x3d\x68\xd2\x9f\xaf\xe2\x1d\x60\x9b\xad\x57\xb0\xf4\xb1\xcd\xd6\xab\xe7\x2b\xd7\x90\xbf\x01\x9b\x8b\xe5\x87\x18\xdf\x8d\x81\x33\xbc\xb6\x49\xf4\x98\xf8\x52\x2f\xc2\x3e\x87\x9f\x52\xf0\x31\xbe\xbb\x72\xc0\x43\xcb\xcf\xb3\x0e\x02\xc1\xab\xc8\x4b\x24\x79\xd0\x5e\x12\xe9\x2f\xd5\xff\x32\x81\xe4\x41\x27\x8a\x24\xcc\xf4\x97\x2a\xa3\x4f\x2f\x6b\x4e\x86\x7c\x57\xc8\x13\xb0\x14\xf5\x6b\xfd\xc6\x28\x2a\xb4\x36\x2a\x83\x98\xf4\xb3\xc2\x03\xe7\x3b\xf3\x40\xaa\x20\xd2\xa7\x65\xf6\xeb\xce\x70\x29\x58\x35\xc4\x3a\x6d\x7a\x72\x4f\x0a\x9d\xa7\xc1\x59\x94\x2f\x16\xd6\x23\x52\x15\xa8\x60\x8b\x0a\xbd\xa2\x6d\x5d\x45\xca\x30\x0d\x5c\xd8\x4f\x5b\x68\xbd\x91\x22\x7b\x29\xab\xa6\x16\xfa\x53\xe6\x27\x0c\x39\x23\x7b\x93\x33\x91\x90\x75\x3f\x86\x11\x3f\xef\x2d\xbe\x02\x4a\x78\xee\x72\xcc\xf6\xac\x7a\x83\xbe\x39\x23\x2f\xb8\x57\x1b\x95\x4b\xb1\xcf\xd6\x46\xb2\x24\x34\x21\x0d\x61\x3e\x6d\x04\x39\x71\xcd\xc2\x53\xbe\x7a\x75\xac\xb7\x68\x94\xc8\x16\x90\xb1\xf2\x5f\xa9\x03\x23\xdc\xce\x69\x06\xd4\x9c\x09\x96\x37\x2f\xe1\x2a\xdc\xd9\x6f\xac\xe2\x85\x85\xf5\x76\x6d\x04\x1e\x92\x20\x16\x53\x77\x7c\x76\xe3\x79\x5a\xa6\xb4\x2d\x21\x7e\xa1\xb3\x17\x3a\xee\x94\x4c\x42\xe2\x14\xfe\xe3\xa7\x82\xc5\xb9\xb7\xad\x1d\x87\xc9\xc9\x7a\x07\xb3\x97\x51\xd1\xed\x96\x7d\xb7\x66\x23\x1f\xdc\x2e\xf6\x9a\x77\x7d\x5b\xfd\xff\x61\x6d\x7e\x66\xc4\xec\x8a\xfa\xd4\xd6\xe0\xd3\xac\xf0\xcf\x06\xd5\x53\x7c\x32\x10\x3b\x03\x5b\x57\x48\x86\x13\x6d\x0b\x5f\x1a\x54\x1c\xf5\x57\x86\x46\x7f\x9c\x3c\x55\xfc\xc9\x4d\x25\xdf\x93\x92\xa4\x30\x9e\x06\xdb\xd6\x2a\xe9\xe7\xbe\xeb\xd9\x3d\x83\x97\x15\x47\x61\x8e\x30\x46\xdb\xdd\x42\xda\x34\xf3\xf9\x8f\x88\x52\xaa\x21\xa7\x1c\xa7\xee\xf6\xce\x0e\xb6\xe0\x44\x69\x60\xf0\xd0\xf0\x8a\x6a\x29\x5d\x87\xec\xd4\x4b\xd5\xc4\x6c\xb9\x1e\x19\xbb\x58\xc0\x2b\x69\xa8\xc8\x32\x33\x87\x27\xd9\x80\x40\x2c\x68\x7c\xce\x59\x55\x85\xc4\xef\xc4\x41\xd1\x88\x07\x0f\x58\xd2\xbc\x4f\x14\x03\xdb\x1a\xcd\x56\x16\x73\x0a\xe5\x33\x31\x24\xe5\xc0\x74\xa7\x1e\x16\x50\x2a\x59\x03\x03\xa3\x98\xd0\x2c\xa7\xa8\x77\x93\x3a\x39\xc3\x5b\xb4\x87\x72\x59\xd7\xdc\xd0\xd4\x2e\x15\x28\x59\x55\x58\xc0\x03\xcb\x3f\xdf\xd8\x9a\x1d\x32\xbd\x8b\xfa\x75\xb7\xfa\xab\x40\xf2\xd0\xb7\x39\x68\x60\x71\xee\x9e\xce\x27\x16\x2e\x68\xec\x8f\xee\xaf\x93\x74\x47\x25\xb0\xaf\x01\x02\xac\x34\xa8\x80\x3b\xc2\xbc\x92\x1a\x8b\x39\xb1\xd5\xd2\x9d\x27\xf7\x08\x7c\x34\x43\x8c\x1f\x78\x55\x51\xbf\xc4\x47\xcc\x1b\xc2\xcb\x6c\x95\x6c\x36\x5b\x2b\xb9\x50\x56\xbb\xc3\x96\xe7\x5b\xc8\x15\x32\x47\x10\xc0\x7d\x2b\xa2\x7d\x18\x04\xeb\x04\xa4\x79\x9c\x83\xfc\x4c\x99\x7a\x19\xb5\xcc\x69\x91\x25\x33\xf3\xb8\xb2\x7f\xdd\x75\xe1\x07\xf9\xd9\x66\xca\x8e\x09\x9e\x27\x71\xff\x86\xd0\xb6\xf7\x67\xf7\x7d\xba\x91\x05\x38\xb1\xfe\xe6\x1f\xa7\x17\x5b\x6b\x20\x19\x96\x60\x1e\xb3\x42\xed\x07\xa7\x8f\xc8\x3b\xd7\x75\xdd\x97\xd7\xbb\x0a\x6b\x14\xc6\x79\xaf\xac\x4d\xe6\x76\x50\xdd\x88\x95\x23\x4f\x52\x9a\xe5\x88\xe3\x31\x9a\x3c\x34\xb6\x09\x3f\x3c\x19\xd4\xd9\x2b\x3c\xfc\xb5\x29\x4b\x54\x89\xe0\x55\x6a\x37\xb3\x7f\x29\x6e\xb0\x3b\x18\xfb\xec\x92\xf8\x02\x85\x55\xca\x35\x80\x24\xe6\xc5\xf2\xc5\x7e\x1e\xcf\xcf\xf0\x5f\xaf\xd2\x34\x18\x06\xf8\xef\x1c\x06\x78\x09\xfb\x4b\x8e\xbd\x54\xfa\x7f\x86\xbd\x3f\xfb\x0c\x5c\x37\x06\xa6\x1c\x7e\x82\xb6\x3d\x33\x73\x0e\x71\xea\x4f\x87\x93\xe7\xed\x0c\xae\x4f\xcb\x17\xfb\x78\x0e\xb3\x7d\x6a\x5b\xfa\x85\x8e\x76\x8d\x55\xa0\x9a\xc5\xce\xbf\xc2\x05\x52\x6e\x31\xdf\xea\xf1\xb5\xde\x77\x66\x79\x4a\x4e\xed\x82\x91\x36\xfb\x88\x71\xad\xf1\xee\xd2\x48\x48\x11\xca\x8b\xa1\xd8\x53\x68\x52\x5f\x54\xb8\x53\xa8\x51\x18\x66\xeb\x47\xd7\xdb\xd6\xab\xfe\xcd\xe8\xa6\x80\xe5\x45\x92\x5a\x6e\xc7\x68\xc2\x8b\x39\x7c\x24\xa7\xf7\x33\xe8\x5f\x8c\xe4\x63\x06\x14\x5a\x83\x01\xbc\x88\xda\xc8\x33\xd7\x3e\x70\xe8\x8a\xe7\xb6\xad\xef\xaa\x46\x11\x52\x7e\x5b\x38\x11\xb8\xfc\x66\xb0\x63\x4a\xdb\xc0\x73\xcb\xb2\x1c\x75\xac\xe1\x0d\x6f\x38\xf6\xfe\x43\x60\xc4\x77\xbc\x9b\xf4\x2c\x9f\x05\xab\x27\xfa\x3f\xbe\x9b\xdc\x7e\x87\x7c\xff\xe1\x8f\x87\x93\x6f\x7e\x38\xa1\xe1\xe9\xe3\xdc\x15\x3e\x07\x85\x0f\x2d\x1d\x18\x5f\x1f\x60\x09\x6c\xb7\x43\x51\x24\xe3\x9d\x39\x04\xe3\x85\x2d\x8c\xeb\xd5\x3d\xec\x4f\x77\xd1\xab\x57\xd1\x8b\x78\xdf\x3f\xff\xe2\xb2\xbf\x58\xa3\x46\xcf\x2c\x97\x89\x06\x3c\x7b\xfd\x86\xd7\x95\x89\x9b\x41\xbf\xf7\x95\xe5\x5b\xd2\xed\xd9\x57\x96\xd2\x8e\x88\x07\xea\xab\x8f\x26\x49\xad\x8b\x6e\xc9\x9a\x89\xef\xd7\xfb\xe5\xc8\x55\x44\x70\x8a\x26\xff\xe2\x13\x68\x74\x1e\x4e\x41\x3c\xd9\xce\xf4\x7b\xe2\xc5\x8f\xd4\x0b\x68\x5f\x86\x2c\x44\xcc\x0d\x3f\x49\x5e\x6e\xba\xbf\x69\x8f\x12\x0f\x63\x3a\x60\x11\x9d\x5d\x02\xdf\xf3\x0f\xdd\x20\x05\x4b\xc8\xcb\x0d\xa9\xe3\x5f\x41\xfe\x1b\x00\x00\xff\xff\x62\x83\xe6\xa5\x0c\x1a\x00\x00") func templateEntTmplBytes() ([]byte, error) { return bindataRead( @@ -478,7 +467,7 @@ func templateEntTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/ent.tmpl", size: 6584, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/ent.tmpl", size: 6668, mode: os.FileMode(420), modTime: time.Unix(1562329488, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -498,7 +487,7 @@ func templateExampleTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/example.tmpl", size: 2407, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/example.tmpl", size: 2407, mode: os.FileMode(420), modTime: time.Unix(1560602349, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -518,7 +507,7 @@ func templateHeaderTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/header.tmpl", size: 101, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/header.tmpl", size: 101, mode: os.FileMode(420), modTime: time.Unix(1554626550, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -538,7 +527,7 @@ func templateImportTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/import.tmpl", size: 558, mode: os.FileMode(420), modTime: time.Unix(1561538327, 0)} + info := bindataFileInfo{name: "template/import.tmpl", size: 558, mode: os.FileMode(420), modTime: time.Unix(1561475554, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -558,7 +547,7 @@ func templateMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/meta.tmpl", size: 3550, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/meta.tmpl", size: 3550, mode: os.FileMode(420), modTime: time.Unix(1558789265, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -578,7 +567,7 @@ func templateMigrateMigrateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/migrate/migrate.tmpl", size: 2660, mode: os.FileMode(420), modTime: time.Unix(1562007725, 0)} + info := bindataFileInfo{name: "template/migrate/migrate.tmpl", size: 2660, mode: os.FileMode(420), modTime: time.Unix(1561902105, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -598,7 +587,7 @@ func templateMigrateSchemaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 936, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 936, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -618,7 +607,7 @@ func templateTxTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/tx.tmpl", size: 3426, mode: os.FileMode(420), modTime: time.Unix(1560858190, 0)} + info := bindataFileInfo{name: "template/tx.tmpl", size: 3426, mode: os.FileMode(420), modTime: time.Unix(1560345874, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -638,7 +627,7 @@ func templateWhereTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/where.tmpl", size: 6958, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/where.tmpl", size: 6958, mode: os.FileMode(420), modTime: time.Unix(1559829316, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/create.tmpl b/entc/gen/template/dialect/sql/create.tmpl index 5cb8d7364..987a7fca1 100644 --- a/entc/gen/template/dialect/sql/create.tmpl +++ b/entc/gen/template/dialect/sql/create.tmpl @@ -15,7 +15,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name {{- range $_, $f := $.Fields }} if {{ $receiver }}.{{- $f.StructField }} != nil { builder.Set({{ $.Package }}.{{ $f.Constant }}, *{{ $receiver }}.{{ $f.StructField }}) - {{ if $f.Nullable }}*{{ end }}{{ $.Receiver }}.{{ pascal $f.Name }} = *{{ $receiver }}.{{ $f.StructField }} + {{ $.Receiver }}.{{ pascal $f.Name }} = {{ if not $f.Nullable }}*{{ end }}{{ $receiver }}.{{ $f.StructField }} } {{- end }} query, args := builder.Query() diff --git a/entc/gen/template/ent.tmpl b/entc/gen/template/ent.tmpl index 25e9b442e..ad99f729f 100644 --- a/entc/gen/template/ent.tmpl +++ b/entc/gen/template/ent.tmpl @@ -73,7 +73,8 @@ func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error { {{ $receiver }}.{{ pascal $f.Name }} = &{{ $scan }}.{{ pascal $f.Name }} {{- else }} if {{ $scan }}.{{- pascal $f.Name }}.Valid { - {{ $receiver }}.{{ pascal $f.Name }} = &{{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }} + {{ $receiver }}.{{ pascal $f.Name }} = new({{ $f.Type }}) + *{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }} } {{- end }} {{- else if $f.Optional }} @@ -117,15 +118,13 @@ func ({{ $receiver }} *{{ $.Name }}) String() string { buf.WriteString("{{ $.Name }}(") buf.WriteString(fmt.Sprintf("id=%v,", {{ $receiver }}.ID)) {{- range $i, $f := $.Fields }} - {{- if gt $i 0 }} - buf.WriteString(", ") - {{- end }} {{- if $f.Nullable }} if v := {{ $receiver }}.{{ pascal $f.Name }}; v != nil { + {{- if gt $i 0 }}buf.WriteString(", "){{ end }} buf.WriteString(fmt.Sprintf("{{ $f.Name }}=%v", *v)) } {{- else }} - buf.WriteString(fmt.Sprintf("{{ $f.Name }}=%v", {{ $receiver }}.{{ pascal $f.Name }})) + buf.WriteString(fmt.Sprintf("{{ if gt $i 0 }}, {{ end }}{{ $f.Name }}=%v", {{ $receiver }}.{{ pascal $f.Name }})) {{- end }} {{- end }} buf.WriteString(")") diff --git a/entc/gen/type.go b/entc/gen/type.go index f3e697537..ea64515d9 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -279,7 +279,7 @@ func (f Field) NullType() string { return "sql.NullBool" case field.TypeTime: return "sql.NullTime" - case field.TypeInt, field.TypeInt64: + case field.TypeInt, field.TypeInt8, field.TypeInt16, field.TypeInt32, field.TypeInt64: return "sql.NullInt64" case field.TypeFloat64: return "sql.NullFloat64" @@ -293,10 +293,12 @@ func (f Field) NullTypeField(rec string) string { switch f.Type { case field.TypeString, field.TypeBool, field.TypeInt64, field.TypeFloat64: return fmt.Sprintf("%s.%s", rec, strings.Title(f.Type.String())) - case field.TypeInt: - return fmt.Sprintf("int(%s.Int64)", rec) case field.TypeTime: return fmt.Sprintf("%s.Time", rec) + case field.TypeFloat32: + return fmt.Sprintf("%s(%s.Float32)", f.Type.String(), rec) + case field.TypeInt, field.TypeInt8, field.TypeInt16, field.TypeInt32: + return fmt.Sprintf("%s(%s.Int64)", f.Type.String(), rec) } return rec } @@ -308,6 +310,9 @@ func (f Field) Column() *schema.Column { c.Type = field.TypeInt c.Increment = true } + if cs, ok := f.def.(field.Sizer); ok { + c.Size = cs.Size() + } if cs, ok := f.def.(field.Charseter); ok { c.Charset = cs.Charset() } diff --git a/entc/integration/ent/client.go b/entc/integration/ent/client.go index 1336ee1ee..5f355e38b 100644 --- a/entc/integration/ent/client.go +++ b/entc/integration/ent/client.go @@ -14,6 +14,7 @@ import ( "fbc/ent/entc/integration/ent/card" "fbc/ent/entc/integration/ent/comment" + "fbc/ent/entc/integration/ent/fieldtype" "fbc/ent/entc/integration/ent/file" "fbc/ent/entc/integration/ent/group" "fbc/ent/entc/integration/ent/groupinfo" @@ -31,6 +32,8 @@ type Client struct { Card *CardClient // Comment is the client for interacting with the Comment builders. Comment *CommentClient + // FieldType is the client for interacting with the FieldType builders. + FieldType *FieldTypeClient // File is the client for interacting with the File builders. File *FileClient // Group is the client for interacting with the Group builders. @@ -54,6 +57,7 @@ func NewClient(opts ...Option) *Client { Schema: migrate.NewSchema(c.driver), Card: NewCardClient(c), Comment: NewCommentClient(c), + FieldType: NewFieldTypeClient(c), File: NewFileClient(c), Group: NewGroupClient(c), GroupInfo: NewGroupInfoClient(c), @@ -77,6 +81,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { config: cfg, Card: NewCardClient(cfg), Comment: NewCommentClient(cfg), + FieldType: NewFieldTypeClient(cfg), File: NewFileClient(cfg), Group: NewGroupClient(cfg), GroupInfo: NewGroupInfoClient(cfg), @@ -203,6 +208,56 @@ func (c *CommentClient) Query() *CommentQuery { return &CommentQuery{config: c.config} } +// FieldTypeClient is a client for the FieldType schema. +type FieldTypeClient struct { + config +} + +// NewFieldTypeClient returns a client for the FieldType from the given config. +func NewFieldTypeClient(c config) *FieldTypeClient { + return &FieldTypeClient{config: c} +} + +// Create returns a create builder for FieldType. +func (c *FieldTypeClient) Create() *FieldTypeCreate { + return &FieldTypeCreate{config: c.config} +} + +// Update returns an update builder for FieldType. +func (c *FieldTypeClient) Update() *FieldTypeUpdate { + return &FieldTypeUpdate{config: c.config} +} + +// UpdateOne returns an update builder for the given entity. +func (c *FieldTypeClient) UpdateOne(ft *FieldType) *FieldTypeUpdateOne { + return c.UpdateOneID(ft.ID) +} + +// UpdateOneID returns an update builder for the given id. +func (c *FieldTypeClient) UpdateOneID(id string) *FieldTypeUpdateOne { + return &FieldTypeUpdateOne{config: c.config, id: id} +} + +// Delete returns a delete builder for FieldType. +func (c *FieldTypeClient) Delete() *FieldTypeDelete { + return &FieldTypeDelete{config: c.config} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *FieldTypeClient) DeleteOne(ft *FieldType) *FieldTypeDeleteOne { + return c.DeleteOneID(ft.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *FieldTypeClient) DeleteOneID(id string) *FieldTypeDeleteOne { + return &FieldTypeDeleteOne{c.Delete().Where(fieldtype.ID(id))} +} + +// Create returns a query builder for FieldType. +func (c *FieldTypeClient) Query() *FieldTypeQuery { + return &FieldTypeQuery{config: c.config} +} + // FileClient is a client for the File schema. type FileClient struct { config diff --git a/entc/integration/ent/example_test.go b/entc/integration/ent/example_test.go index 1c282a4d5..ddf39e1a4 100644 --- a/entc/integration/ent/example_test.go +++ b/entc/integration/ent/example_test.go @@ -74,6 +74,44 @@ func ExampleComment() { // Output: } +func ExampleFieldType() { + if endpoint == nil { + return + } + ctx := context.Background() + conn, err := gremlin.NewClient(gremlin.Config{Endpoint: *endpoint}) + if err != nil { + log.Fatalf("failed creating database client: %v", err) + } + client := NewClient(Driver(dialect.NewGremlin(conn))) + + // creating vertices for the fieldtype's edges. + + // create fieldtype vertex with its edges. + ft := client.FieldType. + Create(). + SetInt(1). + SetInt8(1). + SetInt16(1). + SetInt32(1). + SetInt64(1). + SetOptionalInt(1). + SetOptionalInt8(1). + SetOptionalInt16(1). + SetOptionalInt32(1). + SetOptionalInt64(1). + SetNullableInt(1). + SetNullableInt8(1). + SetNullableInt16(1). + SetNullableInt32(1). + SetNullableInt64(1). + SaveX(ctx) + log.Println("fieldtype created:", ft) + + // query edges. + + // Output: +} func ExampleFile() { if endpoint == nil { return diff --git a/entc/integration/ent/fieldtype.go b/entc/integration/ent/fieldtype.go new file mode 100644 index 000000000..59aebb90a --- /dev/null +++ b/entc/integration/ent/fieldtype.go @@ -0,0 +1,305 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "bytes" + "fmt" + "strconv" + + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" +) + +// FieldType is the model entity for the FieldType schema. +type FieldType struct { + config + // ID of the ent. + ID string `json:"id,omitempty"` + // Int holds the value of the "int" field. + Int int `json:"int,omitempty"` + // Int8 holds the value of the "int8" field. + Int8 int8 `json:"int8,omitempty"` + // Int16 holds the value of the "int16" field. + Int16 int16 `json:"int16,omitempty"` + // Int32 holds the value of the "int32" field. + Int32 int32 `json:"int32,omitempty"` + // Int64 holds the value of the "int64" field. + Int64 int64 `json:"int64,omitempty"` + // OptionalInt holds the value of the "optional_int" field. + OptionalInt int `json:"optional_int,omitempty"` + // OptionalInt8 holds the value of the "optional_int8" field. + OptionalInt8 int8 `json:"optional_int8,omitempty"` + // OptionalInt16 holds the value of the "optional_int16" field. + OptionalInt16 int16 `json:"optional_int16,omitempty"` + // OptionalInt32 holds the value of the "optional_int32" field. + OptionalInt32 int32 `json:"optional_int32,omitempty"` + // OptionalInt64 holds the value of the "optional_int64" field. + OptionalInt64 int64 `json:"optional_int64,omitempty"` + // NullableInt holds the value of the "nullable_int" field. + NullableInt *int `json:"nullable_int,omitempty"` + // NullableInt8 holds the value of the "nullable_int8" field. + NullableInt8 *int8 `json:"nullable_int8,omitempty"` + // NullableInt16 holds the value of the "nullable_int16" field. + NullableInt16 *int16 `json:"nullable_int16,omitempty"` + // NullableInt32 holds the value of the "nullable_int32" field. + NullableInt32 *int32 `json:"nullable_int32,omitempty"` + // NullableInt64 holds the value of the "nullable_int64" field. + NullableInt64 *int64 `json:"nullable_int64,omitempty"` +} + +// FromResponse scans the gremlin response data into FieldType. +func (ft *FieldType) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vft struct { + ID string `json:"id,omitempty"` + Int int `json:"int,omitempty"` + Int8 int8 `json:"int8,omitempty"` + Int16 int16 `json:"int16,omitempty"` + Int32 int32 `json:"int32,omitempty"` + Int64 int64 `json:"int64,omitempty"` + OptionalInt int `json:"optional_int,omitempty"` + OptionalInt8 int8 `json:"optional_int8,omitempty"` + OptionalInt16 int16 `json:"optional_int16,omitempty"` + OptionalInt32 int32 `json:"optional_int32,omitempty"` + OptionalInt64 int64 `json:"optional_int64,omitempty"` + NullableInt *int `json:"nullable_int,omitempty"` + NullableInt8 *int8 `json:"nullable_int8,omitempty"` + NullableInt16 *int16 `json:"nullable_int16,omitempty"` + NullableInt32 *int32 `json:"nullable_int32,omitempty"` + NullableInt64 *int64 `json:"nullable_int64,omitempty"` + } + if err := vmap.Decode(&vft); err != nil { + return err + } + ft.ID = vft.ID + ft.Int = vft.Int + ft.Int8 = vft.Int8 + ft.Int16 = vft.Int16 + ft.Int32 = vft.Int32 + ft.Int64 = vft.Int64 + ft.OptionalInt = vft.OptionalInt + ft.OptionalInt8 = vft.OptionalInt8 + ft.OptionalInt16 = vft.OptionalInt16 + ft.OptionalInt32 = vft.OptionalInt32 + ft.OptionalInt64 = vft.OptionalInt64 + ft.NullableInt = vft.NullableInt + ft.NullableInt8 = vft.NullableInt8 + ft.NullableInt16 = vft.NullableInt16 + ft.NullableInt32 = vft.NullableInt32 + ft.NullableInt64 = vft.NullableInt64 + return nil +} + +// FromRows scans the sql response data into FieldType. +func (ft *FieldType) FromRows(rows *sql.Rows) error { + var vft struct { + ID int + Int int + Int8 int8 + Int16 int16 + Int32 int32 + Int64 int64 + OptionalInt sql.NullInt64 + OptionalInt8 sql.NullInt64 + OptionalInt16 sql.NullInt64 + OptionalInt32 sql.NullInt64 + OptionalInt64 sql.NullInt64 + NullableInt sql.NullInt64 + NullableInt8 sql.NullInt64 + NullableInt16 sql.NullInt64 + NullableInt32 sql.NullInt64 + NullableInt64 sql.NullInt64 + } + // the order here should be the same as in the `fieldtype.Columns`. + if err := rows.Scan( + &vft.ID, + &vft.Int, + &vft.Int8, + &vft.Int16, + &vft.Int32, + &vft.Int64, + &vft.OptionalInt, + &vft.OptionalInt8, + &vft.OptionalInt16, + &vft.OptionalInt32, + &vft.OptionalInt64, + &vft.NullableInt, + &vft.NullableInt8, + &vft.NullableInt16, + &vft.NullableInt32, + &vft.NullableInt64, + ); err != nil { + return err + } + ft.ID = strconv.Itoa(vft.ID) + ft.Int = vft.Int + ft.Int8 = vft.Int8 + ft.Int16 = vft.Int16 + ft.Int32 = vft.Int32 + ft.Int64 = vft.Int64 + ft.OptionalInt = int(vft.OptionalInt.Int64) + ft.OptionalInt8 = int8(vft.OptionalInt8.Int64) + ft.OptionalInt16 = int16(vft.OptionalInt16.Int64) + ft.OptionalInt32 = int32(vft.OptionalInt32.Int64) + ft.OptionalInt64 = vft.OptionalInt64.Int64 + if vft.NullableInt.Valid { + ft.NullableInt = new(int) + *ft.NullableInt = int(vft.NullableInt.Int64) + } + if vft.NullableInt8.Valid { + ft.NullableInt8 = new(int8) + *ft.NullableInt8 = int8(vft.NullableInt8.Int64) + } + if vft.NullableInt16.Valid { + ft.NullableInt16 = new(int16) + *ft.NullableInt16 = int16(vft.NullableInt16.Int64) + } + if vft.NullableInt32.Valid { + ft.NullableInt32 = new(int32) + *ft.NullableInt32 = int32(vft.NullableInt32.Int64) + } + if vft.NullableInt64.Valid { + ft.NullableInt64 = new(int64) + *ft.NullableInt64 = vft.NullableInt64.Int64 + } + return nil +} + +// Update returns a builder for updating this FieldType. +// Note that, you need to call FieldType.Unwrap() before calling this method, if this FieldType +// was returned from a transaction, and the transaction was committed or rolled back. +func (ft *FieldType) Update() *FieldTypeUpdateOne { + return (&FieldTypeClient{ft.config}).UpdateOne(ft) +} + +// Unwrap unwraps the entity that was returned from a transaction after it was closed, +// so that all next queries will be executed through the driver which created the transaction. +func (ft *FieldType) Unwrap() *FieldType { + tx, ok := ft.config.driver.(*txDriver) + if !ok { + panic("ent: FieldType is not a transactional entity") + } + ft.config.driver = tx.drv + return ft +} + +// String implements the fmt.Stringer. +func (ft *FieldType) String() string { + buf := bytes.NewBuffer(nil) + buf.WriteString("FieldType(") + buf.WriteString(fmt.Sprintf("id=%v,", ft.ID)) + buf.WriteString(fmt.Sprintf("int=%v", ft.Int)) + buf.WriteString(fmt.Sprintf(", int8=%v", ft.Int8)) + buf.WriteString(fmt.Sprintf(", int16=%v", ft.Int16)) + buf.WriteString(fmt.Sprintf(", int32=%v", ft.Int32)) + buf.WriteString(fmt.Sprintf(", int64=%v", ft.Int64)) + buf.WriteString(fmt.Sprintf(", optional_int=%v", ft.OptionalInt)) + buf.WriteString(fmt.Sprintf(", optional_int8=%v", ft.OptionalInt8)) + buf.WriteString(fmt.Sprintf(", optional_int16=%v", ft.OptionalInt16)) + buf.WriteString(fmt.Sprintf(", optional_int32=%v", ft.OptionalInt32)) + buf.WriteString(fmt.Sprintf(", optional_int64=%v", ft.OptionalInt64)) + if v := ft.NullableInt; v != nil { + buf.WriteString(", ") + buf.WriteString(fmt.Sprintf("nullable_int=%v", *v)) + } + if v := ft.NullableInt8; v != nil { + buf.WriteString(", ") + buf.WriteString(fmt.Sprintf("nullable_int8=%v", *v)) + } + if v := ft.NullableInt16; v != nil { + buf.WriteString(", ") + buf.WriteString(fmt.Sprintf("nullable_int16=%v", *v)) + } + if v := ft.NullableInt32; v != nil { + buf.WriteString(", ") + buf.WriteString(fmt.Sprintf("nullable_int32=%v", *v)) + } + if v := ft.NullableInt64; v != nil { + buf.WriteString(", ") + buf.WriteString(fmt.Sprintf("nullable_int64=%v", *v)) + } + buf.WriteString(")") + return buf.String() +} + +// id returns the int representation of the ID field. +func (ft *FieldType) id() int { + id, _ := strconv.Atoi(ft.ID) + return id +} + +// FieldTypes is a parsable slice of FieldType. +type FieldTypes []*FieldType + +// FromResponse scans the gremlin response data into FieldTypes. +func (ft *FieldTypes) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vft []struct { + ID string `json:"id,omitempty"` + Int int `json:"int,omitempty"` + Int8 int8 `json:"int8,omitempty"` + Int16 int16 `json:"int16,omitempty"` + Int32 int32 `json:"int32,omitempty"` + Int64 int64 `json:"int64,omitempty"` + OptionalInt int `json:"optional_int,omitempty"` + OptionalInt8 int8 `json:"optional_int8,omitempty"` + OptionalInt16 int16 `json:"optional_int16,omitempty"` + OptionalInt32 int32 `json:"optional_int32,omitempty"` + OptionalInt64 int64 `json:"optional_int64,omitempty"` + NullableInt *int `json:"nullable_int,omitempty"` + NullableInt8 *int8 `json:"nullable_int8,omitempty"` + NullableInt16 *int16 `json:"nullable_int16,omitempty"` + NullableInt32 *int32 `json:"nullable_int32,omitempty"` + NullableInt64 *int64 `json:"nullable_int64,omitempty"` + } + if err := vmap.Decode(&vft); err != nil { + return err + } + for _, v := range vft { + *ft = append(*ft, &FieldType{ + ID: v.ID, + Int: v.Int, + Int8: v.Int8, + Int16: v.Int16, + Int32: v.Int32, + Int64: v.Int64, + OptionalInt: v.OptionalInt, + OptionalInt8: v.OptionalInt8, + OptionalInt16: v.OptionalInt16, + OptionalInt32: v.OptionalInt32, + OptionalInt64: v.OptionalInt64, + NullableInt: v.NullableInt, + NullableInt8: v.NullableInt8, + NullableInt16: v.NullableInt16, + NullableInt32: v.NullableInt32, + NullableInt64: v.NullableInt64, + }) + } + return nil +} + +// FromRows scans the sql response data into FieldTypes. +func (ft *FieldTypes) FromRows(rows *sql.Rows) error { + for rows.Next() { + vft := &FieldType{} + if err := vft.FromRows(rows); err != nil { + return err + } + *ft = append(*ft, vft) + } + return nil +} + +func (ft FieldTypes) config(cfg config) { + for i := range ft { + ft[i].config = cfg + } +} diff --git a/entc/integration/ent/fieldtype/fieldtype.go b/entc/integration/ent/fieldtype/fieldtype.go new file mode 100644 index 000000000..f939de7d3 --- /dev/null +++ b/entc/integration/ent/fieldtype/fieldtype.go @@ -0,0 +1,62 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package fieldtype + +const ( + // Label holds the string label denoting the fieldtype type in the database. + Label = "field_type" + // FieldInt holds the string denoting the int vertex property in the database. + FieldInt = "int" + // FieldInt8 holds the string denoting the int8 vertex property in the database. + FieldInt8 = "int8" + // FieldInt16 holds the string denoting the int16 vertex property in the database. + FieldInt16 = "int16" + // FieldInt32 holds the string denoting the int32 vertex property in the database. + FieldInt32 = "int32" + // FieldInt64 holds the string denoting the int64 vertex property in the database. + FieldInt64 = "int64" + // FieldOptionalInt holds the string denoting the optional_int vertex property in the database. + FieldOptionalInt = "optional_int" + // FieldOptionalInt8 holds the string denoting the optional_int8 vertex property in the database. + FieldOptionalInt8 = "optional_int8" + // FieldOptionalInt16 holds the string denoting the optional_int16 vertex property in the database. + FieldOptionalInt16 = "optional_int16" + // FieldOptionalInt32 holds the string denoting the optional_int32 vertex property in the database. + FieldOptionalInt32 = "optional_int32" + // FieldOptionalInt64 holds the string denoting the optional_int64 vertex property in the database. + FieldOptionalInt64 = "optional_int64" + // FieldNullableInt holds the string denoting the nullable_int vertex property in the database. + FieldNullableInt = "nullable_int" + // FieldNullableInt8 holds the string denoting the nullable_int8 vertex property in the database. + FieldNullableInt8 = "nullable_int8" + // FieldNullableInt16 holds the string denoting the nullable_int16 vertex property in the database. + FieldNullableInt16 = "nullable_int16" + // FieldNullableInt32 holds the string denoting the nullable_int32 vertex property in the database. + FieldNullableInt32 = "nullable_int32" + // FieldNullableInt64 holds the string denoting the nullable_int64 vertex property in the database. + FieldNullableInt64 = "nullable_int64" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // Table holds the table name of the fieldtype in the database. + Table = "field_types" +) + +// Columns holds all SQL columns are fieldtype fields. +var Columns = []string{ + FieldID, + FieldInt, + FieldInt8, + FieldInt16, + FieldInt32, + FieldInt64, + FieldOptionalInt, + FieldOptionalInt8, + FieldOptionalInt16, + FieldOptionalInt32, + FieldOptionalInt64, + FieldNullableInt, + FieldNullableInt8, + FieldNullableInt16, + FieldNullableInt32, + FieldNullableInt64, +} diff --git a/entc/integration/ent/fieldtype/where.go b/entc/integration/ent/fieldtype/where.go new file mode 100644 index 000000000..ed27ef914 --- /dev/null +++ b/entc/integration/ent/fieldtype/where.go @@ -0,0 +1,2076 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package fieldtype + +import ( + "strconv" + + "fbc/ent" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/p" +) + +// ID filters vertices based on their identifier. +func ID(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(id) + }, + } +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.EQ(id)) + }, + } +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.NEQ(id)) + }, + } +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GT(id)) + }, + } +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GTE(id)) + }, + } +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LT(id)) + }, + } +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LTE(id)) + }, + } +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.In(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Within(v...)) + }, + } +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Without(v...)) + }, + } +} + +// Int applies equality check predicate on the "int" field. It's identical to IntEQ. +func Int(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.EQ(v)) + }, + } +} + +// Int8 applies equality check predicate on the "int8" field. It's identical to Int8EQ. +func Int8(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.EQ(v)) + }, + } +} + +// Int16 applies equality check predicate on the "int16" field. It's identical to Int16EQ. +func Int16(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.EQ(v)) + }, + } +} + +// Int32 applies equality check predicate on the "int32" field. It's identical to Int32EQ. +func Int32(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.EQ(v)) + }, + } +} + +// Int64 applies equality check predicate on the "int64" field. It's identical to Int64EQ. +func Int64(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.EQ(v)) + }, + } +} + +// OptionalInt applies equality check predicate on the "optional_int" field. It's identical to OptionalIntEQ. +func OptionalInt(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.EQ(v)) + }, + } +} + +// OptionalInt8 applies equality check predicate on the "optional_int8" field. It's identical to OptionalInt8EQ. +func OptionalInt8(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.EQ(v)) + }, + } +} + +// OptionalInt16 applies equality check predicate on the "optional_int16" field. It's identical to OptionalInt16EQ. +func OptionalInt16(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.EQ(v)) + }, + } +} + +// OptionalInt32 applies equality check predicate on the "optional_int32" field. It's identical to OptionalInt32EQ. +func OptionalInt32(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.EQ(v)) + }, + } +} + +// OptionalInt64 applies equality check predicate on the "optional_int64" field. It's identical to OptionalInt64EQ. +func OptionalInt64(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.EQ(v)) + }, + } +} + +// NullableInt applies equality check predicate on the "nullable_int" field. It's identical to NullableIntEQ. +func NullableInt(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.EQ(v)) + }, + } +} + +// NullableInt8 applies equality check predicate on the "nullable_int8" field. It's identical to NullableInt8EQ. +func NullableInt8(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.EQ(v)) + }, + } +} + +// NullableInt16 applies equality check predicate on the "nullable_int16" field. It's identical to NullableInt16EQ. +func NullableInt16(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.EQ(v)) + }, + } +} + +// NullableInt32 applies equality check predicate on the "nullable_int32" field. It's identical to NullableInt32EQ. +func NullableInt32(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.EQ(v)) + }, + } +} + +// NullableInt64 applies equality check predicate on the "nullable_int64" field. It's identical to NullableInt64EQ. +func NullableInt64(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.EQ(v)) + }, + } +} + +// IntEQ applies the EQ predicate on the "int" field. +func IntEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.EQ(v)) + }, + } +} + +// IntNEQ applies the NEQ predicate on the "int" field. +func IntNEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.NEQ(v)) + }, + } +} + +// IntGT applies the GT predicate on the "int" field. +func IntGT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.GT(v)) + }, + } +} + +// IntGTE applies the GTE predicate on the "int" field. +func IntGTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.GTE(v)) + }, + } +} + +// IntLT applies the LT predicate on the "int" field. +func IntLT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.LT(v)) + }, + } +} + +// IntLTE applies the LTE predicate on the "int" field. +func IntLTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.LTE(v)) + }, + } +} + +// IntIn applies the In predicate on the "int" field. +func IntIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.Within(v...)) + }, + } +} + +// IntNotIn applies the NotIn predicate on the "int" field. +func IntNotIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt, p.Without(v...)) + }, + } +} + +// Int8EQ applies the EQ predicate on the "int8" field. +func Int8EQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.EQ(v)) + }, + } +} + +// Int8NEQ applies the NEQ predicate on the "int8" field. +func Int8NEQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.NEQ(v)) + }, + } +} + +// Int8GT applies the GT predicate on the "int8" field. +func Int8GT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.GT(v)) + }, + } +} + +// Int8GTE applies the GTE predicate on the "int8" field. +func Int8GTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.GTE(v)) + }, + } +} + +// Int8LT applies the LT predicate on the "int8" field. +func Int8LT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.LT(v)) + }, + } +} + +// Int8LTE applies the LTE predicate on the "int8" field. +func Int8LTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.LTE(v)) + }, + } +} + +// Int8In applies the In predicate on the "int8" field. +func Int8In(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.Within(v...)) + }, + } +} + +// Int8NotIn applies the NotIn predicate on the "int8" field. +func Int8NotIn(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt8, p.Without(v...)) + }, + } +} + +// Int16EQ applies the EQ predicate on the "int16" field. +func Int16EQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.EQ(v)) + }, + } +} + +// Int16NEQ applies the NEQ predicate on the "int16" field. +func Int16NEQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.NEQ(v)) + }, + } +} + +// Int16GT applies the GT predicate on the "int16" field. +func Int16GT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.GT(v)) + }, + } +} + +// Int16GTE applies the GTE predicate on the "int16" field. +func Int16GTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.GTE(v)) + }, + } +} + +// Int16LT applies the LT predicate on the "int16" field. +func Int16LT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.LT(v)) + }, + } +} + +// Int16LTE applies the LTE predicate on the "int16" field. +func Int16LTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.LTE(v)) + }, + } +} + +// Int16In applies the In predicate on the "int16" field. +func Int16In(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.Within(v...)) + }, + } +} + +// Int16NotIn applies the NotIn predicate on the "int16" field. +func Int16NotIn(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt16, p.Without(v...)) + }, + } +} + +// Int32EQ applies the EQ predicate on the "int32" field. +func Int32EQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.EQ(v)) + }, + } +} + +// Int32NEQ applies the NEQ predicate on the "int32" field. +func Int32NEQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.NEQ(v)) + }, + } +} + +// Int32GT applies the GT predicate on the "int32" field. +func Int32GT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.GT(v)) + }, + } +} + +// Int32GTE applies the GTE predicate on the "int32" field. +func Int32GTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.GTE(v)) + }, + } +} + +// Int32LT applies the LT predicate on the "int32" field. +func Int32LT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.LT(v)) + }, + } +} + +// Int32LTE applies the LTE predicate on the "int32" field. +func Int32LTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.LTE(v)) + }, + } +} + +// Int32In applies the In predicate on the "int32" field. +func Int32In(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.Within(v...)) + }, + } +} + +// Int32NotIn applies the NotIn predicate on the "int32" field. +func Int32NotIn(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt32, p.Without(v...)) + }, + } +} + +// Int64EQ applies the EQ predicate on the "int64" field. +func Int64EQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.EQ(v)) + }, + } +} + +// Int64NEQ applies the NEQ predicate on the "int64" field. +func Int64NEQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.NEQ(v)) + }, + } +} + +// Int64GT applies the GT predicate on the "int64" field. +func Int64GT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.GT(v)) + }, + } +} + +// Int64GTE applies the GTE predicate on the "int64" field. +func Int64GTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.GTE(v)) + }, + } +} + +// Int64LT applies the LT predicate on the "int64" field. +func Int64LT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.LT(v)) + }, + } +} + +// Int64LTE applies the LTE predicate on the "int64" field. +func Int64LTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.LTE(v)) + }, + } +} + +// Int64In applies the In predicate on the "int64" field. +func Int64In(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.Within(v...)) + }, + } +} + +// Int64NotIn applies the NotIn predicate on the "int64" field. +func Int64NotIn(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldInt64, p.Without(v...)) + }, + } +} + +// OptionalIntEQ applies the EQ predicate on the "optional_int" field. +func OptionalIntEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.EQ(v)) + }, + } +} + +// OptionalIntNEQ applies the NEQ predicate on the "optional_int" field. +func OptionalIntNEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.NEQ(v)) + }, + } +} + +// OptionalIntGT applies the GT predicate on the "optional_int" field. +func OptionalIntGT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.GT(v)) + }, + } +} + +// OptionalIntGTE applies the GTE predicate on the "optional_int" field. +func OptionalIntGTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.GTE(v)) + }, + } +} + +// OptionalIntLT applies the LT predicate on the "optional_int" field. +func OptionalIntLT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.LT(v)) + }, + } +} + +// OptionalIntLTE applies the LTE predicate on the "optional_int" field. +func OptionalIntLTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldOptionalInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.LTE(v)) + }, + } +} + +// OptionalIntIn applies the In predicate on the "optional_int" field. +func OptionalIntIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.Within(v...)) + }, + } +} + +// OptionalIntNotIn applies the NotIn predicate on the "optional_int" field. +func OptionalIntNotIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt, p.Without(v...)) + }, + } +} + +// OptionalInt8EQ applies the EQ predicate on the "optional_int8" field. +func OptionalInt8EQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.EQ(v)) + }, + } +} + +// OptionalInt8NEQ applies the NEQ predicate on the "optional_int8" field. +func OptionalInt8NEQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.NEQ(v)) + }, + } +} + +// OptionalInt8GT applies the GT predicate on the "optional_int8" field. +func OptionalInt8GT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.GT(v)) + }, + } +} + +// OptionalInt8GTE applies the GTE predicate on the "optional_int8" field. +func OptionalInt8GTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.GTE(v)) + }, + } +} + +// OptionalInt8LT applies the LT predicate on the "optional_int8" field. +func OptionalInt8LT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.LT(v)) + }, + } +} + +// OptionalInt8LTE applies the LTE predicate on the "optional_int8" field. +func OptionalInt8LTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldOptionalInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.LTE(v)) + }, + } +} + +// OptionalInt8In applies the In predicate on the "optional_int8" field. +func OptionalInt8In(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.Within(v...)) + }, + } +} + +// OptionalInt8NotIn applies the NotIn predicate on the "optional_int8" field. +func OptionalInt8NotIn(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt8, p.Without(v...)) + }, + } +} + +// OptionalInt16EQ applies the EQ predicate on the "optional_int16" field. +func OptionalInt16EQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.EQ(v)) + }, + } +} + +// OptionalInt16NEQ applies the NEQ predicate on the "optional_int16" field. +func OptionalInt16NEQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.NEQ(v)) + }, + } +} + +// OptionalInt16GT applies the GT predicate on the "optional_int16" field. +func OptionalInt16GT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.GT(v)) + }, + } +} + +// OptionalInt16GTE applies the GTE predicate on the "optional_int16" field. +func OptionalInt16GTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.GTE(v)) + }, + } +} + +// OptionalInt16LT applies the LT predicate on the "optional_int16" field. +func OptionalInt16LT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.LT(v)) + }, + } +} + +// OptionalInt16LTE applies the LTE predicate on the "optional_int16" field. +func OptionalInt16LTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldOptionalInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.LTE(v)) + }, + } +} + +// OptionalInt16In applies the In predicate on the "optional_int16" field. +func OptionalInt16In(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.Within(v...)) + }, + } +} + +// OptionalInt16NotIn applies the NotIn predicate on the "optional_int16" field. +func OptionalInt16NotIn(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt16, p.Without(v...)) + }, + } +} + +// OptionalInt32EQ applies the EQ predicate on the "optional_int32" field. +func OptionalInt32EQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.EQ(v)) + }, + } +} + +// OptionalInt32NEQ applies the NEQ predicate on the "optional_int32" field. +func OptionalInt32NEQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.NEQ(v)) + }, + } +} + +// OptionalInt32GT applies the GT predicate on the "optional_int32" field. +func OptionalInt32GT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.GT(v)) + }, + } +} + +// OptionalInt32GTE applies the GTE predicate on the "optional_int32" field. +func OptionalInt32GTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.GTE(v)) + }, + } +} + +// OptionalInt32LT applies the LT predicate on the "optional_int32" field. +func OptionalInt32LT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.LT(v)) + }, + } +} + +// OptionalInt32LTE applies the LTE predicate on the "optional_int32" field. +func OptionalInt32LTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldOptionalInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.LTE(v)) + }, + } +} + +// OptionalInt32In applies the In predicate on the "optional_int32" field. +func OptionalInt32In(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.Within(v...)) + }, + } +} + +// OptionalInt32NotIn applies the NotIn predicate on the "optional_int32" field. +func OptionalInt32NotIn(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt32, p.Without(v...)) + }, + } +} + +// OptionalInt64EQ applies the EQ predicate on the "optional_int64" field. +func OptionalInt64EQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.EQ(v)) + }, + } +} + +// OptionalInt64NEQ applies the NEQ predicate on the "optional_int64" field. +func OptionalInt64NEQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.NEQ(v)) + }, + } +} + +// OptionalInt64GT applies the GT predicate on the "optional_int64" field. +func OptionalInt64GT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.GT(v)) + }, + } +} + +// OptionalInt64GTE applies the GTE predicate on the "optional_int64" field. +func OptionalInt64GTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.GTE(v)) + }, + } +} + +// OptionalInt64LT applies the LT predicate on the "optional_int64" field. +func OptionalInt64LT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.LT(v)) + }, + } +} + +// OptionalInt64LTE applies the LTE predicate on the "optional_int64" field. +func OptionalInt64LTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldOptionalInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.LTE(v)) + }, + } +} + +// OptionalInt64In applies the In predicate on the "optional_int64" field. +func OptionalInt64In(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.Within(v...)) + }, + } +} + +// OptionalInt64NotIn applies the NotIn predicate on the "optional_int64" field. +func OptionalInt64NotIn(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldOptionalInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldOptionalInt64, p.Without(v...)) + }, + } +} + +// NullableIntEQ applies the EQ predicate on the "nullable_int" field. +func NullableIntEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.EQ(v)) + }, + } +} + +// NullableIntNEQ applies the NEQ predicate on the "nullable_int" field. +func NullableIntNEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.NEQ(v)) + }, + } +} + +// NullableIntGT applies the GT predicate on the "nullable_int" field. +func NullableIntGT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.GT(v)) + }, + } +} + +// NullableIntGTE applies the GTE predicate on the "nullable_int" field. +func NullableIntGTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.GTE(v)) + }, + } +} + +// NullableIntLT applies the LT predicate on the "nullable_int" field. +func NullableIntLT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.LT(v)) + }, + } +} + +// NullableIntLTE applies the LTE predicate on the "nullable_int" field. +func NullableIntLTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldNullableInt), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.LTE(v)) + }, + } +} + +// NullableIntIn applies the In predicate on the "nullable_int" field. +func NullableIntIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.Within(v...)) + }, + } +} + +// NullableIntNotIn applies the NotIn predicate on the "nullable_int" field. +func NullableIntNotIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt, p.Without(v...)) + }, + } +} + +// NullableInt8EQ applies the EQ predicate on the "nullable_int8" field. +func NullableInt8EQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.EQ(v)) + }, + } +} + +// NullableInt8NEQ applies the NEQ predicate on the "nullable_int8" field. +func NullableInt8NEQ(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.NEQ(v)) + }, + } +} + +// NullableInt8GT applies the GT predicate on the "nullable_int8" field. +func NullableInt8GT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.GT(v)) + }, + } +} + +// NullableInt8GTE applies the GTE predicate on the "nullable_int8" field. +func NullableInt8GTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.GTE(v)) + }, + } +} + +// NullableInt8LT applies the LT predicate on the "nullable_int8" field. +func NullableInt8LT(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.LT(v)) + }, + } +} + +// NullableInt8LTE applies the LTE predicate on the "nullable_int8" field. +func NullableInt8LTE(v int8) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldNullableInt8), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.LTE(v)) + }, + } +} + +// NullableInt8In applies the In predicate on the "nullable_int8" field. +func NullableInt8In(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.Within(v...)) + }, + } +} + +// NullableInt8NotIn applies the NotIn predicate on the "nullable_int8" field. +func NullableInt8NotIn(vs ...int8) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt8), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt8, p.Without(v...)) + }, + } +} + +// NullableInt16EQ applies the EQ predicate on the "nullable_int16" field. +func NullableInt16EQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.EQ(v)) + }, + } +} + +// NullableInt16NEQ applies the NEQ predicate on the "nullable_int16" field. +func NullableInt16NEQ(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.NEQ(v)) + }, + } +} + +// NullableInt16GT applies the GT predicate on the "nullable_int16" field. +func NullableInt16GT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.GT(v)) + }, + } +} + +// NullableInt16GTE applies the GTE predicate on the "nullable_int16" field. +func NullableInt16GTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.GTE(v)) + }, + } +} + +// NullableInt16LT applies the LT predicate on the "nullable_int16" field. +func NullableInt16LT(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.LT(v)) + }, + } +} + +// NullableInt16LTE applies the LTE predicate on the "nullable_int16" field. +func NullableInt16LTE(v int16) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldNullableInt16), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.LTE(v)) + }, + } +} + +// NullableInt16In applies the In predicate on the "nullable_int16" field. +func NullableInt16In(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.Within(v...)) + }, + } +} + +// NullableInt16NotIn applies the NotIn predicate on the "nullable_int16" field. +func NullableInt16NotIn(vs ...int16) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt16), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt16, p.Without(v...)) + }, + } +} + +// NullableInt32EQ applies the EQ predicate on the "nullable_int32" field. +func NullableInt32EQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.EQ(v)) + }, + } +} + +// NullableInt32NEQ applies the NEQ predicate on the "nullable_int32" field. +func NullableInt32NEQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.NEQ(v)) + }, + } +} + +// NullableInt32GT applies the GT predicate on the "nullable_int32" field. +func NullableInt32GT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.GT(v)) + }, + } +} + +// NullableInt32GTE applies the GTE predicate on the "nullable_int32" field. +func NullableInt32GTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.GTE(v)) + }, + } +} + +// NullableInt32LT applies the LT predicate on the "nullable_int32" field. +func NullableInt32LT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.LT(v)) + }, + } +} + +// NullableInt32LTE applies the LTE predicate on the "nullable_int32" field. +func NullableInt32LTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldNullableInt32), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.LTE(v)) + }, + } +} + +// NullableInt32In applies the In predicate on the "nullable_int32" field. +func NullableInt32In(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.Within(v...)) + }, + } +} + +// NullableInt32NotIn applies the NotIn predicate on the "nullable_int32" field. +func NullableInt32NotIn(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt32), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt32, p.Without(v...)) + }, + } +} + +// NullableInt64EQ applies the EQ predicate on the "nullable_int64" field. +func NullableInt64EQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.EQ(v)) + }, + } +} + +// NullableInt64NEQ applies the NEQ predicate on the "nullable_int64" field. +func NullableInt64NEQ(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.NEQ(v)) + }, + } +} + +// NullableInt64GT applies the GT predicate on the "nullable_int64" field. +func NullableInt64GT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.GT(v)) + }, + } +} + +// NullableInt64GTE applies the GTE predicate on the "nullable_int64" field. +func NullableInt64GTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.GTE(v)) + }, + } +} + +// NullableInt64LT applies the LT predicate on the "nullable_int64" field. +func NullableInt64LT(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.LT(v)) + }, + } +} + +// NullableInt64LTE applies the LTE predicate on the "nullable_int64" field. +func NullableInt64LTE(v int64) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldNullableInt64), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.LTE(v)) + }, + } +} + +// NullableInt64In applies the In predicate on the "nullable_int64" field. +func NullableInt64In(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.Within(v...)) + }, + } +} + +// NullableInt64NotIn applies the NotIn predicate on the "nullable_int64" field. +func NullableInt64NotIn(vs ...int64) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldNullableInt64), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldNullableInt64, p.Without(v...)) + }, + } +} diff --git a/entc/integration/ent/fieldtype_create.go b/entc/integration/ent/fieldtype_create.go new file mode 100644 index 000000000..9aecc2a9c --- /dev/null +++ b/entc/integration/ent/fieldtype_create.go @@ -0,0 +1,395 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "strconv" + + "fbc/ent/entc/integration/ent/fieldtype" + + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// FieldTypeCreate is the builder for creating a FieldType entity. +type FieldTypeCreate struct { + config + int *int + int8 *int8 + int16 *int16 + int32 *int32 + int64 *int64 + optional_int *int + optional_int8 *int8 + optional_int16 *int16 + optional_int32 *int32 + optional_int64 *int64 + nullable_int *int + nullable_int8 *int8 + nullable_int16 *int16 + nullable_int32 *int32 + nullable_int64 *int64 +} + +// SetInt sets the int field. +func (ftc *FieldTypeCreate) SetInt(i int) *FieldTypeCreate { + ftc.int = &i + return ftc +} + +// SetInt8 sets the int8 field. +func (ftc *FieldTypeCreate) SetInt8(i int8) *FieldTypeCreate { + ftc.int8 = &i + return ftc +} + +// SetInt16 sets the int16 field. +func (ftc *FieldTypeCreate) SetInt16(i int16) *FieldTypeCreate { + ftc.int16 = &i + return ftc +} + +// SetInt32 sets the int32 field. +func (ftc *FieldTypeCreate) SetInt32(i int32) *FieldTypeCreate { + ftc.int32 = &i + return ftc +} + +// SetInt64 sets the int64 field. +func (ftc *FieldTypeCreate) SetInt64(i int64) *FieldTypeCreate { + ftc.int64 = &i + return ftc +} + +// SetOptionalInt sets the optional_int field. +func (ftc *FieldTypeCreate) SetOptionalInt(i int) *FieldTypeCreate { + ftc.optional_int = &i + return ftc +} + +// SetNillableOptionalInt sets the optional_int field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableOptionalInt(i *int) *FieldTypeCreate { + if i != nil { + ftc.SetOptionalInt(*i) + } + return ftc +} + +// SetOptionalInt8 sets the optional_int8 field. +func (ftc *FieldTypeCreate) SetOptionalInt8(i int8) *FieldTypeCreate { + ftc.optional_int8 = &i + return ftc +} + +// SetNillableOptionalInt8 sets the optional_int8 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableOptionalInt8(i *int8) *FieldTypeCreate { + if i != nil { + ftc.SetOptionalInt8(*i) + } + return ftc +} + +// SetOptionalInt16 sets the optional_int16 field. +func (ftc *FieldTypeCreate) SetOptionalInt16(i int16) *FieldTypeCreate { + ftc.optional_int16 = &i + return ftc +} + +// SetNillableOptionalInt16 sets the optional_int16 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableOptionalInt16(i *int16) *FieldTypeCreate { + if i != nil { + ftc.SetOptionalInt16(*i) + } + return ftc +} + +// SetOptionalInt32 sets the optional_int32 field. +func (ftc *FieldTypeCreate) SetOptionalInt32(i int32) *FieldTypeCreate { + ftc.optional_int32 = &i + return ftc +} + +// SetNillableOptionalInt32 sets the optional_int32 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableOptionalInt32(i *int32) *FieldTypeCreate { + if i != nil { + ftc.SetOptionalInt32(*i) + } + return ftc +} + +// SetOptionalInt64 sets the optional_int64 field. +func (ftc *FieldTypeCreate) SetOptionalInt64(i int64) *FieldTypeCreate { + ftc.optional_int64 = &i + return ftc +} + +// SetNillableOptionalInt64 sets the optional_int64 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableOptionalInt64(i *int64) *FieldTypeCreate { + if i != nil { + ftc.SetOptionalInt64(*i) + } + return ftc +} + +// SetNullableInt sets the nullable_int field. +func (ftc *FieldTypeCreate) SetNullableInt(i int) *FieldTypeCreate { + ftc.nullable_int = &i + return ftc +} + +// SetNillableNullableInt sets the nullable_int field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableNullableInt(i *int) *FieldTypeCreate { + if i != nil { + ftc.SetNullableInt(*i) + } + return ftc +} + +// SetNullableInt8 sets the nullable_int8 field. +func (ftc *FieldTypeCreate) SetNullableInt8(i int8) *FieldTypeCreate { + ftc.nullable_int8 = &i + return ftc +} + +// SetNillableNullableInt8 sets the nullable_int8 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableNullableInt8(i *int8) *FieldTypeCreate { + if i != nil { + ftc.SetNullableInt8(*i) + } + return ftc +} + +// SetNullableInt16 sets the nullable_int16 field. +func (ftc *FieldTypeCreate) SetNullableInt16(i int16) *FieldTypeCreate { + ftc.nullable_int16 = &i + return ftc +} + +// SetNillableNullableInt16 sets the nullable_int16 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableNullableInt16(i *int16) *FieldTypeCreate { + if i != nil { + ftc.SetNullableInt16(*i) + } + return ftc +} + +// SetNullableInt32 sets the nullable_int32 field. +func (ftc *FieldTypeCreate) SetNullableInt32(i int32) *FieldTypeCreate { + ftc.nullable_int32 = &i + return ftc +} + +// SetNillableNullableInt32 sets the nullable_int32 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableNullableInt32(i *int32) *FieldTypeCreate { + if i != nil { + ftc.SetNullableInt32(*i) + } + return ftc +} + +// SetNullableInt64 sets the nullable_int64 field. +func (ftc *FieldTypeCreate) SetNullableInt64(i int64) *FieldTypeCreate { + ftc.nullable_int64 = &i + return ftc +} + +// SetNillableNullableInt64 sets the nullable_int64 field if the given value is not nil. +func (ftc *FieldTypeCreate) SetNillableNullableInt64(i *int64) *FieldTypeCreate { + if i != nil { + ftc.SetNullableInt64(*i) + } + return ftc +} + +// Save creates the FieldType in the database. +func (ftc *FieldTypeCreate) Save(ctx context.Context) (*FieldType, error) { + if ftc.int == nil { + return nil, errors.New("ent: missing required field \"int\"") + } + if ftc.int8 == nil { + return nil, errors.New("ent: missing required field \"int8\"") + } + if ftc.int16 == nil { + return nil, errors.New("ent: missing required field \"int16\"") + } + if ftc.int32 == nil { + return nil, errors.New("ent: missing required field \"int32\"") + } + if ftc.int64 == nil { + return nil, errors.New("ent: missing required field \"int64\"") + } + switch ftc.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftc.sqlSave(ctx) + case dialect.Neptune: + return ftc.gremlinSave(ctx) + default: + return nil, errors.New("ent: unsupported dialect") + } +} + +// SaveX calls Save and panics if Save returns an error. +func (ftc *FieldTypeCreate) SaveX(ctx context.Context) *FieldType { + v, err := ftc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ftc *FieldTypeCreate) sqlSave(ctx context.Context) (*FieldType, error) { + var ( + res sql.Result + ft = &FieldType{config: ftc.config} + ) + tx, err := ftc.driver.Tx(ctx) + if err != nil { + return nil, err + } + builder := sql.Insert(fieldtype.Table).Default(ftc.driver.Dialect()) + if ftc.int != nil { + builder.Set(fieldtype.FieldInt, *ftc.int) + ft.Int = *ftc.int + } + if ftc.int8 != nil { + builder.Set(fieldtype.FieldInt8, *ftc.int8) + ft.Int8 = *ftc.int8 + } + if ftc.int16 != nil { + builder.Set(fieldtype.FieldInt16, *ftc.int16) + ft.Int16 = *ftc.int16 + } + if ftc.int32 != nil { + builder.Set(fieldtype.FieldInt32, *ftc.int32) + ft.Int32 = *ftc.int32 + } + if ftc.int64 != nil { + builder.Set(fieldtype.FieldInt64, *ftc.int64) + ft.Int64 = *ftc.int64 + } + if ftc.optional_int != nil { + builder.Set(fieldtype.FieldOptionalInt, *ftc.optional_int) + ft.OptionalInt = *ftc.optional_int + } + if ftc.optional_int8 != nil { + builder.Set(fieldtype.FieldOptionalInt8, *ftc.optional_int8) + ft.OptionalInt8 = *ftc.optional_int8 + } + if ftc.optional_int16 != nil { + builder.Set(fieldtype.FieldOptionalInt16, *ftc.optional_int16) + ft.OptionalInt16 = *ftc.optional_int16 + } + if ftc.optional_int32 != nil { + builder.Set(fieldtype.FieldOptionalInt32, *ftc.optional_int32) + ft.OptionalInt32 = *ftc.optional_int32 + } + if ftc.optional_int64 != nil { + builder.Set(fieldtype.FieldOptionalInt64, *ftc.optional_int64) + ft.OptionalInt64 = *ftc.optional_int64 + } + if ftc.nullable_int != nil { + builder.Set(fieldtype.FieldNullableInt, *ftc.nullable_int) + ft.NullableInt = ftc.nullable_int + } + if ftc.nullable_int8 != nil { + builder.Set(fieldtype.FieldNullableInt8, *ftc.nullable_int8) + ft.NullableInt8 = ftc.nullable_int8 + } + if ftc.nullable_int16 != nil { + builder.Set(fieldtype.FieldNullableInt16, *ftc.nullable_int16) + ft.NullableInt16 = ftc.nullable_int16 + } + if ftc.nullable_int32 != nil { + builder.Set(fieldtype.FieldNullableInt32, *ftc.nullable_int32) + ft.NullableInt32 = ftc.nullable_int32 + } + if ftc.nullable_int64 != nil { + builder.Set(fieldtype.FieldNullableInt64, *ftc.nullable_int64) + ft.NullableInt64 = ftc.nullable_int64 + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + id, err := res.LastInsertId() + if err != nil { + return nil, rollback(tx, err) + } + ft.ID = strconv.FormatInt(id, 10) + if err := tx.Commit(); err != nil { + return nil, err + } + return ft, nil +} + +func (ftc *FieldTypeCreate) gremlinSave(ctx context.Context) (*FieldType, error) { + res := &gremlin.Response{} + query, bindings := ftc.gremlin().Query() + if err := ftc.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + ft := &FieldType{config: ftc.config} + if err := ft.FromResponse(res); err != nil { + return nil, err + } + return ft, nil +} + +func (ftc *FieldTypeCreate) gremlin() *dsl.Traversal { + v := g.AddV(fieldtype.Label) + if ftc.int != nil { + v.Property(dsl.Single, fieldtype.FieldInt, *ftc.int) + } + if ftc.int8 != nil { + v.Property(dsl.Single, fieldtype.FieldInt8, *ftc.int8) + } + if ftc.int16 != nil { + v.Property(dsl.Single, fieldtype.FieldInt16, *ftc.int16) + } + if ftc.int32 != nil { + v.Property(dsl.Single, fieldtype.FieldInt32, *ftc.int32) + } + if ftc.int64 != nil { + v.Property(dsl.Single, fieldtype.FieldInt64, *ftc.int64) + } + if ftc.optional_int != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt, *ftc.optional_int) + } + if ftc.optional_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt8, *ftc.optional_int8) + } + if ftc.optional_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt16, *ftc.optional_int16) + } + if ftc.optional_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt32, *ftc.optional_int32) + } + if ftc.optional_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt64, *ftc.optional_int64) + } + if ftc.nullable_int != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt, *ftc.nullable_int) + } + if ftc.nullable_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt8, *ftc.nullable_int8) + } + if ftc.nullable_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt16, *ftc.nullable_int16) + } + if ftc.nullable_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt32, *ftc.nullable_int32) + } + if ftc.nullable_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt64, *ftc.nullable_int64) + } + return v.ValueMap(true) +} diff --git a/entc/integration/ent/fieldtype_delete.go b/entc/integration/ent/fieldtype_delete.go new file mode 100644 index 000000000..b46a70c36 --- /dev/null +++ b/entc/integration/ent/fieldtype_delete.go @@ -0,0 +1,88 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + + "fbc/ent/entc/integration/ent/fieldtype" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// FieldTypeDelete is the builder for deleting a FieldType entity. +type FieldTypeDelete struct { + config + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (ftd *FieldTypeDelete) Where(ps ...ent.Predicate) *FieldTypeDelete { + ftd.predicates = append(ftd.predicates, ps...) + return ftd +} + +// Exec executes the deletion query. +func (ftd *FieldTypeDelete) Exec(ctx context.Context) error { + switch ftd.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftd.sqlExec(ctx) + case dialect.Neptune: + return ftd.gremlinExec(ctx) + default: + return errors.New("ent: unsupported dialect") + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ftd *FieldTypeDelete) ExecX(ctx context.Context) { + if err := ftd.Exec(ctx); err != nil { + panic(err) + } +} + +func (ftd *FieldTypeDelete) sqlExec(ctx context.Context) error { + var res sql.Result + selector := sql.Select().From(sql.Table(fieldtype.Table)) + for _, p := range ftd.predicates { + p.SQL(selector) + } + query, args := sql.Delete(fieldtype.Table).FromSelect(selector).Query() + return ftd.driver.Exec(ctx, query, args, &res) +} + +func (ftd *FieldTypeDelete) gremlinExec(ctx context.Context) error { + res := &gremlin.Response{} + query, bindings := ftd.gremlin().Query() + return ftd.driver.Exec(ctx, query, bindings, res) +} + +func (ftd *FieldTypeDelete) gremlin() *dsl.Traversal { + t := g.V().HasLabel(fieldtype.Label) + for _, p := range ftd.predicates { + p.Gremlin(t) + } + return t.Drop() +} + +// FieldTypeDeleteOne is the builder for deleting a single FieldType entity. +type FieldTypeDeleteOne struct { + ftd *FieldTypeDelete +} + +// Exec executes the deletion query. +func (ftdo *FieldTypeDeleteOne) Exec(ctx context.Context) error { + return ftdo.ftd.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (ftdo *FieldTypeDeleteOne) ExecX(ctx context.Context) { + ftdo.ftd.ExecX(ctx) +} diff --git a/entc/integration/ent/fieldtype_query.go b/entc/integration/ent/fieldtype_query.go new file mode 100644 index 000000000..3dc5ddaa1 --- /dev/null +++ b/entc/integration/ent/fieldtype_query.go @@ -0,0 +1,616 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "math" + + "fbc/ent/entc/integration/ent/fieldtype" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/__" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// FieldTypeQuery is the builder for querying FieldType entities. +type FieldTypeQuery struct { + config + limit *int + offset *int + order []Order + unique []string + predicates []ent.Predicate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Where adds a new predicate for the builder. +func (ftq *FieldTypeQuery) Where(ps ...ent.Predicate) *FieldTypeQuery { + ftq.predicates = append(ftq.predicates, ps...) + return ftq +} + +// Limit adds a limit step to the query. +func (ftq *FieldTypeQuery) Limit(limit int) *FieldTypeQuery { + ftq.limit = &limit + return ftq +} + +// Offset adds an offset step to the query. +func (ftq *FieldTypeQuery) Offset(offset int) *FieldTypeQuery { + ftq.offset = &offset + return ftq +} + +// Order adds an order step to the query. +func (ftq *FieldTypeQuery) Order(o ...Order) *FieldTypeQuery { + ftq.order = append(ftq.order, o...) + return ftq +} + +// Get returns a FieldType entity by its id. +func (ftq *FieldTypeQuery) Get(ctx context.Context, id string) (*FieldType, error) { + return ftq.Where(fieldtype.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (ftq *FieldTypeQuery) GetX(ctx context.Context, id string) *FieldType { + ft, err := ftq.Get(ctx, id) + if err != nil { + panic(err) + } + return ft +} + +// First returns the first FieldType entity in the query. Returns *ErrNotFound when no fieldtype was found. +func (ftq *FieldTypeQuery) First(ctx context.Context) (*FieldType, error) { + fts, err := ftq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(fts) == 0 { + return nil, &ErrNotFound{fieldtype.Label} + } + return fts[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (ftq *FieldTypeQuery) FirstX(ctx context.Context) *FieldType { + ft, err := ftq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return ft +} + +// FirstID returns the first FieldType id in the query. Returns *ErrNotFound when no id was found. +func (ftq *FieldTypeQuery) FirstID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = ftq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &ErrNotFound{fieldtype.Label} + return + } + return ids[0], nil +} + +// FirstXID is like FirstID, but panics if an error occurs. +func (ftq *FieldTypeQuery) FirstXID(ctx context.Context) string { + id, err := ftq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns the only FieldType entity in the query, returns an error if not exactly one entity was returned. +func (ftq *FieldTypeQuery) Only(ctx context.Context) (*FieldType, error) { + fts, err := ftq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(fts) { + case 1: + return fts[0], nil + case 0: + return nil, &ErrNotFound{fieldtype.Label} + default: + return nil, &ErrNotSingular{fieldtype.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (ftq *FieldTypeQuery) OnlyX(ctx context.Context) *FieldType { + ft, err := ftq.Only(ctx) + if err != nil { + panic(err) + } + return ft +} + +// OnlyID returns the only FieldType id in the query, returns an error if not exactly one id was returned. +func (ftq *FieldTypeQuery) OnlyID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = ftq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &ErrNotFound{fieldtype.Label} + default: + err = &ErrNotSingular{fieldtype.Label} + } + return +} + +// OnlyXID is like OnlyID, but panics if an error occurs. +func (ftq *FieldTypeQuery) OnlyXID(ctx context.Context) string { + id, err := ftq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of FieldTypes. +func (ftq *FieldTypeQuery) All(ctx context.Context) ([]*FieldType, error) { + switch ftq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftq.sqlAll(ctx) + case dialect.Neptune: + return ftq.gremlinAll(ctx) + default: + return nil, errors.New("ent: unsupported dialect") + } +} + +// AllX is like All, but panics if an error occurs. +func (ftq *FieldTypeQuery) AllX(ctx context.Context) []*FieldType { + fts, err := ftq.All(ctx) + if err != nil { + panic(err) + } + return fts +} + +// IDs executes the query and returns a list of FieldType ids. +func (ftq *FieldTypeQuery) IDs(ctx context.Context) ([]string, error) { + switch ftq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftq.sqlIDs(ctx) + case dialect.Neptune: + return ftq.gremlinIDs(ctx) + default: + return nil, errors.New("ent: unsupported dialect") + } +} + +// IDsX is like IDs, but panics if an error occurs. +func (ftq *FieldTypeQuery) IDsX(ctx context.Context) []string { + ids, err := ftq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (ftq *FieldTypeQuery) Count(ctx context.Context) (int, error) { + switch ftq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftq.sqlCount(ctx) + case dialect.Neptune: + return ftq.gremlinCount(ctx) + default: + return 0, errors.New("ent: unsupported dialect") + } +} + +// CountX is like Count, but panics if an error occurs. +func (ftq *FieldTypeQuery) CountX(ctx context.Context) int { + count, err := ftq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (ftq *FieldTypeQuery) Exist(ctx context.Context) (bool, error) { + switch ftq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftq.sqlExist(ctx) + case dialect.Neptune: + return ftq.gremlinExist(ctx) + default: + return false, errors.New("ent: unsupported dialect") + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (ftq *FieldTypeQuery) ExistX(ctx context.Context) bool { + exist, err := ftq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// GroupBy 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 { +// Int int `json:"int,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.FieldType.Query(). +// GroupBy(fieldtype.FieldInt). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (ftq *FieldTypeQuery) GroupBy(field string, fields ...string) *FieldTypeGroupBy { + group := &FieldTypeGroupBy{config: ftq.config} + group.fields = append([]string{field}, fields...) + switch ftq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + group.sql = ftq.sqlQuery() + case dialect.Neptune: + group.gremlin = ftq.gremlinQuery() + } + return group +} + +func (ftq *FieldTypeQuery) sqlAll(ctx context.Context) ([]*FieldType, error) { + rows := &sql.Rows{} + selector := ftq.sqlQuery() + if unique := ftq.unique; len(unique) == 0 { + selector.Distinct() + } + query, args := selector.Query() + if err := ftq.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var fts FieldTypes + if err := fts.FromRows(rows); err != nil { + return nil, err + } + fts.config(ftq.config) + return fts, nil +} + +func (ftq *FieldTypeQuery) sqlCount(ctx context.Context) (int, error) { + rows := &sql.Rows{} + selector := ftq.sqlQuery() + unique := []string{fieldtype.FieldID} + if len(ftq.unique) > 0 { + unique = ftq.unique + } + selector.Count(sql.Distinct(selector.Columns(unique...)...)) + query, args := selector.Query() + if err := ftq.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + if !rows.Next() { + return 0, errors.New("ent: no rows found") + } + var n int + if err := rows.Scan(&n); err != nil { + return 0, fmt.Errorf("ent: failed reading count: %v", err) + } + return n, nil +} + +func (ftq *FieldTypeQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := ftq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %v", err) + } + return n > 0, nil +} + +func (ftq *FieldTypeQuery) sqlIDs(ctx context.Context) ([]string, error) { + vs, err := ftq.sqlAll(ctx) + if err != nil { + return nil, err + } + var ids []string + for _, v := range vs { + ids = append(ids, v.ID) + } + return ids, nil +} + +func (ftq *FieldTypeQuery) sqlQuery() *sql.Selector { + t1 := sql.Table(fieldtype.Table) + selector := sql.Select(t1.Columns(fieldtype.Columns...)...).From(t1) + if ftq.sql != nil { + selector = ftq.sql + selector.Select(selector.Columns(fieldtype.Columns...)...) + } + for _, p := range ftq.predicates { + p.SQL(selector) + } + for _, p := range ftq.order { + p.SQL(selector) + } + if offset := ftq.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.MaxInt64) + } + if limit := ftq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +func (ftq *FieldTypeQuery) gremlinIDs(ctx context.Context) ([]string, error) { + res := &gremlin.Response{} + query, bindings := ftq.gremlinQuery().Query() + if err := ftq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + vertices, err := res.ReadVertices() + if err != nil { + return nil, err + } + ids := make([]string, 0, len(vertices)) + for _, vertex := range vertices { + ids = append(ids, vertex.ID.(string)) + } + return ids, nil +} + +func (ftq *FieldTypeQuery) gremlinAll(ctx context.Context) ([]*FieldType, error) { + res := &gremlin.Response{} + query, bindings := ftq.gremlinQuery().ValueMap(true).Query() + if err := ftq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + var fts FieldTypes + if err := fts.FromResponse(res); err != nil { + return nil, err + } + fts.config(ftq.config) + return fts, nil +} + +func (ftq *FieldTypeQuery) gremlinCount(ctx context.Context) (int, error) { + res := &gremlin.Response{} + query, bindings := ftq.gremlinQuery().Count().Query() + if err := ftq.driver.Exec(ctx, query, bindings, res); err != nil { + return 0, err + } + return res.ReadInt() +} + +func (ftq *FieldTypeQuery) gremlinExist(ctx context.Context) (bool, error) { + res := &gremlin.Response{} + query, bindings := ftq.gremlinQuery().HasNext().Query() + if err := ftq.driver.Exec(ctx, query, bindings, res); err != nil { + return false, err + } + return res.ReadBool() +} + +func (ftq *FieldTypeQuery) gremlinQuery() *dsl.Traversal { + v := g.V().HasLabel(fieldtype.Label) + if ftq.gremlin != nil { + v = ftq.gremlin.Clone() + } + for _, p := range ftq.predicates { + p.Gremlin(v) + } + if len(ftq.order) > 0 { + v.Order() + for _, p := range ftq.order { + p.Gremlin(v) + } + } + switch limit, offset := ftq.limit, ftq.offset; { + case limit != nil && offset != nil: + v.Range(*offset, *offset+*limit) + case offset != nil: + v.Range(*offset, math.MaxInt64) + case limit != nil: + v.Limit(*limit) + } + if unique := ftq.unique; len(unique) == 0 { + v.Dedup() + } + return v +} + +// FieldTypeQuery is the builder for group-by FieldType entities. +type FieldTypeGroupBy struct { + config + fields []string + fns []Aggregate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (ftgb *FieldTypeGroupBy) Aggregate(fns ...Aggregate) *FieldTypeGroupBy { + ftgb.fns = append(ftgb.fns, fns...) + return ftgb +} + +// Scan applies the group-by query and scan the result into the given value. +func (ftgb *FieldTypeGroupBy) Scan(ctx context.Context, v interface{}) error { + switch ftgb.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftgb.sqlScan(ctx, v) + case dialect.Neptune: + return ftgb.gremlinScan(ctx, v) + default: + return errors.New("ftgb: unsupported dialect") + } +} + +// ScanX is like Scan, but panics if an error occurs. +func (ftgb *FieldTypeGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := ftgb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +func (ftgb *FieldTypeGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(ftgb.fields) > 1 { + return nil, errors.New("ent: FieldTypeGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := ftgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ftgb *FieldTypeGroupBy) StringsX(ctx context.Context) []string { + v, err := ftgb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +func (ftgb *FieldTypeGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(ftgb.fields) > 1 { + return nil, errors.New("ent: FieldTypeGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := ftgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ftgb *FieldTypeGroupBy) IntsX(ctx context.Context) []int { + v, err := ftgb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +func (ftgb *FieldTypeGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(ftgb.fields) > 1 { + return nil, errors.New("ent: FieldTypeGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := ftgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ftgb *FieldTypeGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := ftgb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +func (ftgb *FieldTypeGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(ftgb.fields) > 1 { + return nil, errors.New("ent: FieldTypeGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := ftgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ftgb *FieldTypeGroupBy) BoolsX(ctx context.Context) []bool { + v, err := ftgb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ftgb *FieldTypeGroupBy) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ftgb.sqlQuery().Query() + if err := ftgb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (ftgb *FieldTypeGroupBy) sqlQuery() *sql.Selector { + selector := ftgb.sql + columns := make([]string, 0, len(ftgb.fields)+len(ftgb.fns)) + columns = append(columns, ftgb.fields...) + for _, fn := range ftgb.fns { + columns = append(columns, fn.SQL(selector)) + } + return selector.Select(columns...).GroupBy(ftgb.fields...) +} + +func (ftgb *FieldTypeGroupBy) gremlinScan(ctx context.Context, v interface{}) error { + res := &gremlin.Response{} + query, bindings := ftgb.gremlinQuery().Query() + if err := ftgb.driver.Exec(ctx, query, bindings, res); err != nil { + return err + } + if len(ftgb.fields)+len(ftgb.fns) == 1 { + return res.ReadVal(v) + } + vm, err := res.ReadValueMap() + if err != nil { + return err + } + return vm.Decode(v) +} + +func (ftgb *FieldTypeGroupBy) gremlinQuery() *dsl.Traversal { + var ( + trs []interface{} + names []interface{} + ) + for _, fn := range ftgb.fns { + name, tr := fn.Gremlin("p", "") + trs = append(trs, tr) + names = append(names, name) + } + for _, f := range ftgb.fields { + names = append(names, f) + trs = append(trs, __.As("p").Unfold().Values(f).As(f)) + } + return ftgb.gremlin.Group(). + By(__.Values(ftgb.fields...).Fold()). + By(__.Fold().Match(trs...).Select(names...)). + Select(dsl.Values). + Next() +} diff --git a/entc/integration/ent/fieldtype_update.go b/entc/integration/ent/fieldtype_update.go new file mode 100644 index 000000000..87b235795 --- /dev/null +++ b/entc/integration/ent/fieldtype_update.go @@ -0,0 +1,848 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "fbc/ent/entc/integration/ent/fieldtype" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// FieldTypeUpdate is the builder for updating FieldType entities. +type FieldTypeUpdate struct { + config + int *int + int8 *int8 + int16 *int16 + int32 *int32 + int64 *int64 + optional_int *int + optional_int8 *int8 + optional_int16 *int16 + optional_int32 *int32 + optional_int64 *int64 + nullable_int *int + nullable_int8 *int8 + nullable_int16 *int16 + nullable_int32 *int32 + nullable_int64 *int64 + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (ftu *FieldTypeUpdate) Where(ps ...ent.Predicate) *FieldTypeUpdate { + ftu.predicates = append(ftu.predicates, ps...) + return ftu +} + +// SetInt sets the int field. +func (ftu *FieldTypeUpdate) SetInt(i int) *FieldTypeUpdate { + ftu.int = &i + return ftu +} + +// SetInt8 sets the int8 field. +func (ftu *FieldTypeUpdate) SetInt8(i int8) *FieldTypeUpdate { + ftu.int8 = &i + return ftu +} + +// SetInt16 sets the int16 field. +func (ftu *FieldTypeUpdate) SetInt16(i int16) *FieldTypeUpdate { + ftu.int16 = &i + return ftu +} + +// SetInt32 sets the int32 field. +func (ftu *FieldTypeUpdate) SetInt32(i int32) *FieldTypeUpdate { + ftu.int32 = &i + return ftu +} + +// SetInt64 sets the int64 field. +func (ftu *FieldTypeUpdate) SetInt64(i int64) *FieldTypeUpdate { + ftu.int64 = &i + return ftu +} + +// SetOptionalInt sets the optional_int field. +func (ftu *FieldTypeUpdate) SetOptionalInt(i int) *FieldTypeUpdate { + ftu.optional_int = &i + return ftu +} + +// SetNillableOptionalInt sets the optional_int field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableOptionalInt(i *int) *FieldTypeUpdate { + if i != nil { + ftu.SetOptionalInt(*i) + } + return ftu +} + +// SetOptionalInt8 sets the optional_int8 field. +func (ftu *FieldTypeUpdate) SetOptionalInt8(i int8) *FieldTypeUpdate { + ftu.optional_int8 = &i + return ftu +} + +// SetNillableOptionalInt8 sets the optional_int8 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableOptionalInt8(i *int8) *FieldTypeUpdate { + if i != nil { + ftu.SetOptionalInt8(*i) + } + return ftu +} + +// SetOptionalInt16 sets the optional_int16 field. +func (ftu *FieldTypeUpdate) SetOptionalInt16(i int16) *FieldTypeUpdate { + ftu.optional_int16 = &i + return ftu +} + +// SetNillableOptionalInt16 sets the optional_int16 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableOptionalInt16(i *int16) *FieldTypeUpdate { + if i != nil { + ftu.SetOptionalInt16(*i) + } + return ftu +} + +// SetOptionalInt32 sets the optional_int32 field. +func (ftu *FieldTypeUpdate) SetOptionalInt32(i int32) *FieldTypeUpdate { + ftu.optional_int32 = &i + return ftu +} + +// SetNillableOptionalInt32 sets the optional_int32 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableOptionalInt32(i *int32) *FieldTypeUpdate { + if i != nil { + ftu.SetOptionalInt32(*i) + } + return ftu +} + +// SetOptionalInt64 sets the optional_int64 field. +func (ftu *FieldTypeUpdate) SetOptionalInt64(i int64) *FieldTypeUpdate { + ftu.optional_int64 = &i + return ftu +} + +// SetNillableOptionalInt64 sets the optional_int64 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableOptionalInt64(i *int64) *FieldTypeUpdate { + if i != nil { + ftu.SetOptionalInt64(*i) + } + return ftu +} + +// SetNullableInt sets the nullable_int field. +func (ftu *FieldTypeUpdate) SetNullableInt(i int) *FieldTypeUpdate { + ftu.nullable_int = &i + return ftu +} + +// SetNillableNullableInt sets the nullable_int field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableNullableInt(i *int) *FieldTypeUpdate { + if i != nil { + ftu.SetNullableInt(*i) + } + return ftu +} + +// SetNullableInt8 sets the nullable_int8 field. +func (ftu *FieldTypeUpdate) SetNullableInt8(i int8) *FieldTypeUpdate { + ftu.nullable_int8 = &i + return ftu +} + +// SetNillableNullableInt8 sets the nullable_int8 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableNullableInt8(i *int8) *FieldTypeUpdate { + if i != nil { + ftu.SetNullableInt8(*i) + } + return ftu +} + +// SetNullableInt16 sets the nullable_int16 field. +func (ftu *FieldTypeUpdate) SetNullableInt16(i int16) *FieldTypeUpdate { + ftu.nullable_int16 = &i + return ftu +} + +// SetNillableNullableInt16 sets the nullable_int16 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableNullableInt16(i *int16) *FieldTypeUpdate { + if i != nil { + ftu.SetNullableInt16(*i) + } + return ftu +} + +// SetNullableInt32 sets the nullable_int32 field. +func (ftu *FieldTypeUpdate) SetNullableInt32(i int32) *FieldTypeUpdate { + ftu.nullable_int32 = &i + return ftu +} + +// SetNillableNullableInt32 sets the nullable_int32 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableNullableInt32(i *int32) *FieldTypeUpdate { + if i != nil { + ftu.SetNullableInt32(*i) + } + return ftu +} + +// SetNullableInt64 sets the nullable_int64 field. +func (ftu *FieldTypeUpdate) SetNullableInt64(i int64) *FieldTypeUpdate { + ftu.nullable_int64 = &i + return ftu +} + +// SetNillableNullableInt64 sets the nullable_int64 field if the given value is not nil. +func (ftu *FieldTypeUpdate) SetNillableNullableInt64(i *int64) *FieldTypeUpdate { + if i != nil { + ftu.SetNullableInt64(*i) + } + return ftu +} + +// Save executes the query and returns the number of rows/vertices matched by this operation. +func (ftu *FieldTypeUpdate) Save(ctx context.Context) (int, error) { + switch ftu.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftu.sqlSave(ctx) + case dialect.Neptune: + vertices, err := ftu.gremlinSave(ctx) + return len(vertices), err + default: + return 0, errors.New("ent: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (ftu *FieldTypeUpdate) SaveX(ctx context.Context) int { + affected, err := ftu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (ftu *FieldTypeUpdate) Exec(ctx context.Context) error { + _, err := ftu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ftu *FieldTypeUpdate) ExecX(ctx context.Context) { + if err := ftu.Exec(ctx); err != nil { + panic(err) + } +} + +func (ftu *FieldTypeUpdate) sqlSave(ctx context.Context) (n int, err error) { + selector := sql.Select(fieldtype.FieldID).From(sql.Table(fieldtype.Table)) + for _, p := range ftu.predicates { + p.SQL(selector) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err = ftu.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + if err := rows.Scan(&id); err != nil { + return 0, fmt.Errorf("ent: failed reading id: %v", err) + } + ids = append(ids, id) + } + if len(ids) == 0 { + return 0, nil + } + + tx, err := ftu.driver.Tx(ctx) + if err != nil { + return 0, err + } + var ( + update bool + res sql.Result + builder = sql.Update(fieldtype.Table).Where(sql.InInts(fieldtype.FieldID, ids...)) + ) + if ftu.int != nil { + update = true + builder.Set(fieldtype.FieldInt, *ftu.int) + } + if ftu.int8 != nil { + update = true + builder.Set(fieldtype.FieldInt8, *ftu.int8) + } + if ftu.int16 != nil { + update = true + builder.Set(fieldtype.FieldInt16, *ftu.int16) + } + if ftu.int32 != nil { + update = true + builder.Set(fieldtype.FieldInt32, *ftu.int32) + } + if ftu.int64 != nil { + update = true + builder.Set(fieldtype.FieldInt64, *ftu.int64) + } + if ftu.optional_int != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt, *ftu.optional_int) + } + if ftu.optional_int8 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt8, *ftu.optional_int8) + } + if ftu.optional_int16 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt16, *ftu.optional_int16) + } + if ftu.optional_int32 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt32, *ftu.optional_int32) + } + if ftu.optional_int64 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt64, *ftu.optional_int64) + } + if ftu.nullable_int != nil { + update = true + builder.Set(fieldtype.FieldNullableInt, *ftu.nullable_int) + } + if ftu.nullable_int8 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt8, *ftu.nullable_int8) + } + if ftu.nullable_int16 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt16, *ftu.nullable_int16) + } + if ftu.nullable_int32 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt32, *ftu.nullable_int32) + } + if ftu.nullable_int64 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt64, *ftu.nullable_int64) + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return 0, err + } + return len(ids), nil +} + +func (ftu *FieldTypeUpdate) gremlinSave(ctx context.Context) ([]*FieldType, error) { + res := &gremlin.Response{} + query, bindings := ftu.gremlin().Query() + if err := ftu.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + var fts FieldTypes + fts.config(ftu.config) + if err := fts.FromResponse(res); err != nil { + return nil, err + } + return fts, nil +} + +func (ftu *FieldTypeUpdate) gremlin() *dsl.Traversal { + v := g.V().HasLabel(fieldtype.Label) + for _, p := range ftu.predicates { + p.Gremlin(v) + } + var ( + trs []*dsl.Traversal + ) + if ftu.int != nil { + v.Property(dsl.Single, fieldtype.FieldInt, *ftu.int) + } + if ftu.int8 != nil { + v.Property(dsl.Single, fieldtype.FieldInt8, *ftu.int8) + } + if ftu.int16 != nil { + v.Property(dsl.Single, fieldtype.FieldInt16, *ftu.int16) + } + if ftu.int32 != nil { + v.Property(dsl.Single, fieldtype.FieldInt32, *ftu.int32) + } + if ftu.int64 != nil { + v.Property(dsl.Single, fieldtype.FieldInt64, *ftu.int64) + } + if ftu.optional_int != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt, *ftu.optional_int) + } + if ftu.optional_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt8, *ftu.optional_int8) + } + if ftu.optional_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt16, *ftu.optional_int16) + } + if ftu.optional_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt32, *ftu.optional_int32) + } + if ftu.optional_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt64, *ftu.optional_int64) + } + if ftu.nullable_int != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt, *ftu.nullable_int) + } + if ftu.nullable_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt8, *ftu.nullable_int8) + } + if ftu.nullable_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt16, *ftu.nullable_int16) + } + if ftu.nullable_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt32, *ftu.nullable_int32) + } + if ftu.nullable_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt64, *ftu.nullable_int64) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} + +// FieldTypeUpdateOne is the builder for updating a single FieldType entity. +type FieldTypeUpdateOne struct { + config + id string + int *int + int8 *int8 + int16 *int16 + int32 *int32 + int64 *int64 + optional_int *int + optional_int8 *int8 + optional_int16 *int16 + optional_int32 *int32 + optional_int64 *int64 + nullable_int *int + nullable_int8 *int8 + nullable_int16 *int16 + nullable_int32 *int32 + nullable_int64 *int64 +} + +// SetInt sets the int field. +func (ftuo *FieldTypeUpdateOne) SetInt(i int) *FieldTypeUpdateOne { + ftuo.int = &i + return ftuo +} + +// SetInt8 sets the int8 field. +func (ftuo *FieldTypeUpdateOne) SetInt8(i int8) *FieldTypeUpdateOne { + ftuo.int8 = &i + return ftuo +} + +// SetInt16 sets the int16 field. +func (ftuo *FieldTypeUpdateOne) SetInt16(i int16) *FieldTypeUpdateOne { + ftuo.int16 = &i + return ftuo +} + +// SetInt32 sets the int32 field. +func (ftuo *FieldTypeUpdateOne) SetInt32(i int32) *FieldTypeUpdateOne { + ftuo.int32 = &i + return ftuo +} + +// SetInt64 sets the int64 field. +func (ftuo *FieldTypeUpdateOne) SetInt64(i int64) *FieldTypeUpdateOne { + ftuo.int64 = &i + return ftuo +} + +// SetOptionalInt sets the optional_int field. +func (ftuo *FieldTypeUpdateOne) SetOptionalInt(i int) *FieldTypeUpdateOne { + ftuo.optional_int = &i + return ftuo +} + +// SetNillableOptionalInt sets the optional_int field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableOptionalInt(i *int) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetOptionalInt(*i) + } + return ftuo +} + +// SetOptionalInt8 sets the optional_int8 field. +func (ftuo *FieldTypeUpdateOne) SetOptionalInt8(i int8) *FieldTypeUpdateOne { + ftuo.optional_int8 = &i + return ftuo +} + +// SetNillableOptionalInt8 sets the optional_int8 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableOptionalInt8(i *int8) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetOptionalInt8(*i) + } + return ftuo +} + +// SetOptionalInt16 sets the optional_int16 field. +func (ftuo *FieldTypeUpdateOne) SetOptionalInt16(i int16) *FieldTypeUpdateOne { + ftuo.optional_int16 = &i + return ftuo +} + +// SetNillableOptionalInt16 sets the optional_int16 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableOptionalInt16(i *int16) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetOptionalInt16(*i) + } + return ftuo +} + +// SetOptionalInt32 sets the optional_int32 field. +func (ftuo *FieldTypeUpdateOne) SetOptionalInt32(i int32) *FieldTypeUpdateOne { + ftuo.optional_int32 = &i + return ftuo +} + +// SetNillableOptionalInt32 sets the optional_int32 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableOptionalInt32(i *int32) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetOptionalInt32(*i) + } + return ftuo +} + +// SetOptionalInt64 sets the optional_int64 field. +func (ftuo *FieldTypeUpdateOne) SetOptionalInt64(i int64) *FieldTypeUpdateOne { + ftuo.optional_int64 = &i + return ftuo +} + +// SetNillableOptionalInt64 sets the optional_int64 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableOptionalInt64(i *int64) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetOptionalInt64(*i) + } + return ftuo +} + +// SetNullableInt sets the nullable_int field. +func (ftuo *FieldTypeUpdateOne) SetNullableInt(i int) *FieldTypeUpdateOne { + ftuo.nullable_int = &i + return ftuo +} + +// SetNillableNullableInt sets the nullable_int field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableNullableInt(i *int) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetNullableInt(*i) + } + return ftuo +} + +// SetNullableInt8 sets the nullable_int8 field. +func (ftuo *FieldTypeUpdateOne) SetNullableInt8(i int8) *FieldTypeUpdateOne { + ftuo.nullable_int8 = &i + return ftuo +} + +// SetNillableNullableInt8 sets the nullable_int8 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableNullableInt8(i *int8) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetNullableInt8(*i) + } + return ftuo +} + +// SetNullableInt16 sets the nullable_int16 field. +func (ftuo *FieldTypeUpdateOne) SetNullableInt16(i int16) *FieldTypeUpdateOne { + ftuo.nullable_int16 = &i + return ftuo +} + +// SetNillableNullableInt16 sets the nullable_int16 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableNullableInt16(i *int16) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetNullableInt16(*i) + } + return ftuo +} + +// SetNullableInt32 sets the nullable_int32 field. +func (ftuo *FieldTypeUpdateOne) SetNullableInt32(i int32) *FieldTypeUpdateOne { + ftuo.nullable_int32 = &i + return ftuo +} + +// SetNillableNullableInt32 sets the nullable_int32 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableNullableInt32(i *int32) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetNullableInt32(*i) + } + return ftuo +} + +// SetNullableInt64 sets the nullable_int64 field. +func (ftuo *FieldTypeUpdateOne) SetNullableInt64(i int64) *FieldTypeUpdateOne { + ftuo.nullable_int64 = &i + return ftuo +} + +// SetNillableNullableInt64 sets the nullable_int64 field if the given value is not nil. +func (ftuo *FieldTypeUpdateOne) SetNillableNullableInt64(i *int64) *FieldTypeUpdateOne { + if i != nil { + ftuo.SetNullableInt64(*i) + } + return ftuo +} + +// Save executes the query and returns the updated entity. +func (ftuo *FieldTypeUpdateOne) Save(ctx context.Context) (*FieldType, error) { + switch ftuo.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ftuo.sqlSave(ctx) + case dialect.Neptune: + return ftuo.gremlinSave(ctx) + default: + return nil, errors.New("ent: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (ftuo *FieldTypeUpdateOne) SaveX(ctx context.Context) *FieldType { + ft, err := ftuo.Save(ctx) + if err != nil { + panic(err) + } + return ft +} + +// Exec executes the query on the entity. +func (ftuo *FieldTypeUpdateOne) Exec(ctx context.Context) error { + _, err := ftuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ftuo *FieldTypeUpdateOne) ExecX(ctx context.Context) { + if err := ftuo.Exec(ctx); err != nil { + panic(err) + } +} + +func (ftuo *FieldTypeUpdateOne) sqlSave(ctx context.Context) (ft *FieldType, err error) { + selector := sql.Select(fieldtype.Columns...).From(sql.Table(fieldtype.Table)) + fieldtype.ID(ftuo.id).SQL(selector) + rows := &sql.Rows{} + query, args := selector.Query() + if err = ftuo.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + ft = &FieldType{config: ftuo.config} + if err := ft.FromRows(rows); err != nil { + return nil, fmt.Errorf("ent: failed scanning row into FieldType: %v", err) + } + id = ft.id() + ids = append(ids, id) + } + switch n := len(ids); { + case n == 0: + return nil, fmt.Errorf("ent: FieldType not found with id: %v", ftuo.id) + case n > 1: + return nil, fmt.Errorf("ent: more than one FieldType with the same id: %v", ftuo.id) + } + + tx, err := ftuo.driver.Tx(ctx) + if err != nil { + return nil, err + } + var ( + update bool + res sql.Result + builder = sql.Update(fieldtype.Table).Where(sql.InInts(fieldtype.FieldID, ids...)) + ) + if ftuo.int != nil { + update = true + builder.Set(fieldtype.FieldInt, *ftuo.int) + ft.Int = *ftuo.int + } + if ftuo.int8 != nil { + update = true + builder.Set(fieldtype.FieldInt8, *ftuo.int8) + ft.Int8 = *ftuo.int8 + } + if ftuo.int16 != nil { + update = true + builder.Set(fieldtype.FieldInt16, *ftuo.int16) + ft.Int16 = *ftuo.int16 + } + if ftuo.int32 != nil { + update = true + builder.Set(fieldtype.FieldInt32, *ftuo.int32) + ft.Int32 = *ftuo.int32 + } + if ftuo.int64 != nil { + update = true + builder.Set(fieldtype.FieldInt64, *ftuo.int64) + ft.Int64 = *ftuo.int64 + } + if ftuo.optional_int != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt, *ftuo.optional_int) + ft.OptionalInt = *ftuo.optional_int + } + if ftuo.optional_int8 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt8, *ftuo.optional_int8) + ft.OptionalInt8 = *ftuo.optional_int8 + } + if ftuo.optional_int16 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt16, *ftuo.optional_int16) + ft.OptionalInt16 = *ftuo.optional_int16 + } + if ftuo.optional_int32 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt32, *ftuo.optional_int32) + ft.OptionalInt32 = *ftuo.optional_int32 + } + if ftuo.optional_int64 != nil { + update = true + builder.Set(fieldtype.FieldOptionalInt64, *ftuo.optional_int64) + ft.OptionalInt64 = *ftuo.optional_int64 + } + if ftuo.nullable_int != nil { + update = true + builder.Set(fieldtype.FieldNullableInt, *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 + } + if ftuo.nullable_int16 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt16, *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 + } + if ftuo.nullable_int64 != nil { + update = true + builder.Set(fieldtype.FieldNullableInt64, *ftuo.nullable_int64) + *ft.NullableInt64 = *ftuo.nullable_int64 + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return nil, err + } + return ft, nil +} + +func (ftuo *FieldTypeUpdateOne) gremlinSave(ctx context.Context) (*FieldType, error) { + res := &gremlin.Response{} + query, bindings := ftuo.gremlin(ftuo.id).Query() + if err := ftuo.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + ft := &FieldType{config: ftuo.config} + if err := ft.FromResponse(res); err != nil { + return nil, err + } + return ft, nil +} + +func (ftuo *FieldTypeUpdateOne) gremlin(id string) *dsl.Traversal { + v := g.V(id) + var ( + trs []*dsl.Traversal + ) + if ftuo.int != nil { + v.Property(dsl.Single, fieldtype.FieldInt, *ftuo.int) + } + if ftuo.int8 != nil { + v.Property(dsl.Single, fieldtype.FieldInt8, *ftuo.int8) + } + if ftuo.int16 != nil { + v.Property(dsl.Single, fieldtype.FieldInt16, *ftuo.int16) + } + if ftuo.int32 != nil { + v.Property(dsl.Single, fieldtype.FieldInt32, *ftuo.int32) + } + if ftuo.int64 != nil { + v.Property(dsl.Single, fieldtype.FieldInt64, *ftuo.int64) + } + if ftuo.optional_int != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt, *ftuo.optional_int) + } + if ftuo.optional_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt8, *ftuo.optional_int8) + } + if ftuo.optional_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt16, *ftuo.optional_int16) + } + if ftuo.optional_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt32, *ftuo.optional_int32) + } + if ftuo.optional_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldOptionalInt64, *ftuo.optional_int64) + } + if ftuo.nullable_int != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt, *ftuo.nullable_int) + } + if ftuo.nullable_int8 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt8, *ftuo.nullable_int8) + } + if ftuo.nullable_int16 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt16, *ftuo.nullable_int16) + } + if ftuo.nullable_int32 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt32, *ftuo.nullable_int32) + } + if ftuo.nullable_int64 != nil { + v.Property(dsl.Single, fieldtype.FieldNullableInt64, *ftuo.nullable_int64) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} diff --git a/entc/integration/ent/file.go b/entc/integration/ent/file.go index 1d294d45d..5712477a7 100644 --- a/entc/integration/ent/file.go +++ b/entc/integration/ent/file.go @@ -88,8 +88,7 @@ func (f *File) String() string { buf.WriteString("File(") buf.WriteString(fmt.Sprintf("id=%v,", f.ID)) buf.WriteString(fmt.Sprintf("size=%v", f.Size)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("name=%v", f.Name)) + buf.WriteString(fmt.Sprintf(", name=%v", f.Name)) buf.WriteString(")") return buf.String() } diff --git a/entc/integration/ent/group.go b/entc/integration/ent/group.go index 0c509b7cb..6405d77b6 100644 --- a/entc/integration/ent/group.go +++ b/entc/integration/ent/group.go @@ -81,7 +81,8 @@ func (gr *Group) FromRows(rows *sql.Rows) error { gr.Active = vgr.Active gr.Expire = vgr.Expire if vgr.Type.Valid { - gr.Type = &vgr.Type.String + gr.Type = new(string) + *gr.Type = vgr.Type.String } gr.MaxUsers = int(vgr.MaxUsers.Int64) gr.Name = vgr.Name @@ -132,16 +133,13 @@ func (gr *Group) String() string { buf.WriteString("Group(") buf.WriteString(fmt.Sprintf("id=%v,", gr.ID)) buf.WriteString(fmt.Sprintf("active=%v", gr.Active)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("expire=%v", gr.Expire)) - buf.WriteString(", ") + buf.WriteString(fmt.Sprintf(", expire=%v", gr.Expire)) if v := gr.Type; v != nil { + buf.WriteString(", ") buf.WriteString(fmt.Sprintf("type=%v", *v)) } - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("max_users=%v", gr.MaxUsers)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("name=%v", gr.Name)) + buf.WriteString(fmt.Sprintf(", max_users=%v", gr.MaxUsers)) + buf.WriteString(fmt.Sprintf(", name=%v", gr.Name)) buf.WriteString(")") return buf.String() } diff --git a/entc/integration/ent/group_create.go b/entc/integration/ent/group_create.go index 2e51e21fd..3c9f9dbc2 100644 --- a/entc/integration/ent/group_create.go +++ b/entc/integration/ent/group_create.go @@ -237,7 +237,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { } if gc._type != nil { builder.Set(group.FieldType, *gc._type) - *gr.Type = *gc._type + gr.Type = gc._type } if gc.max_users != nil { builder.Set(group.FieldMaxUsers, *gc.max_users) diff --git a/entc/integration/ent/groupinfo.go b/entc/integration/ent/groupinfo.go index 69c4a47af..31b68a267 100644 --- a/entc/integration/ent/groupinfo.go +++ b/entc/integration/ent/groupinfo.go @@ -93,8 +93,7 @@ func (gi *GroupInfo) String() string { buf.WriteString("GroupInfo(") buf.WriteString(fmt.Sprintf("id=%v,", gi.ID)) buf.WriteString(fmt.Sprintf("desc=%v", gi.Desc)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("max_users=%v", gi.MaxUsers)) + buf.WriteString(fmt.Sprintf(", max_users=%v", gi.MaxUsers)) buf.WriteString(")") return buf.String() } diff --git a/entc/integration/ent/migrate/migrate.go b/entc/integration/ent/migrate/migrate.go index ecac79503..ab3652d5f 100644 --- a/entc/integration/ent/migrate/migrate.go +++ b/entc/integration/ent/migrate/migrate.go @@ -41,6 +41,32 @@ var ( PrimaryKey: []*schema.Column{CommentsColumns[0]}, ForeignKeys: []*schema.ForeignKey{}, } + // FieldTypesColumns holds the columns for the "field_types" table. + FieldTypesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "int", Type: field.TypeInt}, + {Name: "int8", Type: field.TypeInt8}, + {Name: "int16", Type: field.TypeInt16}, + {Name: "int32", Type: field.TypeInt32}, + {Name: "int64", Type: field.TypeInt64}, + {Name: "optional_int", Type: field.TypeInt}, + {Name: "optional_int8", Type: field.TypeInt8}, + {Name: "optional_int16", Type: field.TypeInt16}, + {Name: "optional_int32", Type: field.TypeInt32}, + {Name: "optional_int64", Type: field.TypeInt64}, + {Name: "nullable_int", Type: field.TypeInt}, + {Name: "nullable_int8", Type: field.TypeInt8}, + {Name: "nullable_int16", Type: field.TypeInt16}, + {Name: "nullable_int32", Type: field.TypeInt32}, + {Name: "nullable_int64", Type: field.TypeInt64}, + } + // FieldTypesTable holds the schema information for the "field_types" table. + FieldTypesTable = &schema.Table{ + Name: "field_types", + Columns: FieldTypesColumns, + PrimaryKey: []*schema.Column{FieldTypesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{}, + } // FilesColumns holds the columns for the "files" table. FilesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -285,6 +311,7 @@ var ( Tables = []*schema.Table{ CardsTable, CommentsTable, + FieldTypesTable, FilesTable, GroupsTable, GroupInfosTable, diff --git a/entc/integration/ent/schema/fieldtype.go b/entc/integration/ent/schema/fieldtype.go new file mode 100644 index 000000000..885039229 --- /dev/null +++ b/entc/integration/ent/schema/fieldtype.go @@ -0,0 +1,33 @@ +package schema + +import ( + "fbc/ent" + "fbc/ent/field" +) + +// FieldType holds the schema definition for the FieldType entity. +// used for testing field types. +type FieldType struct { + ent.Schema +} + +// Fields of the File. +func (FieldType) Fields() []ent.Field { + return []ent.Field{ + field.Int("int"), + field.Int8("int8"), + field.Int16("int16"), + field.Int32("int32"), + field.Int64("int64"), + field.Int("optional_int").Optional(), + field.Int8("optional_int8").Optional(), + field.Int16("optional_int16").Optional(), + field.Int32("optional_int32").Optional(), + field.Int64("optional_int64").Optional(), + field.Int("nullable_int").Optional().Nullable(), + field.Int8("nullable_int8").Optional().Nullable(), + field.Int16("nullable_int16").Optional().Nullable(), + field.Int32("nullable_int32").Optional().Nullable(), + field.Int64("nullable_int64").Optional().Nullable(), + } +} diff --git a/entc/integration/ent/tx.go b/entc/integration/ent/tx.go index a137f3f49..88a7b92d7 100644 --- a/entc/integration/ent/tx.go +++ b/entc/integration/ent/tx.go @@ -17,6 +17,8 @@ type Tx struct { Card *CardClient // Comment is the client for interacting with the Comment builders. Comment *CommentClient + // FieldType is the client for interacting with the FieldType builders. + FieldType *FieldTypeClient // File is the client for interacting with the File builders. File *FileClient // Group is the client for interacting with the Group builders. @@ -48,6 +50,7 @@ func (tx *Tx) Client() *Client { Schema: migrate.NewSchema(tx.driver), Card: NewCardClient(tx.config), Comment: NewCommentClient(tx.config), + FieldType: NewFieldTypeClient(tx.config), File: NewFileClient(tx.config), Group: NewGroupClient(tx.config), GroupInfo: NewGroupInfoClient(tx.config), diff --git a/entc/integration/ent/user.go b/entc/integration/ent/user.go index 9425fbca3..5a72b89a0 100644 --- a/entc/integration/ent/user.go +++ b/entc/integration/ent/user.go @@ -164,14 +164,10 @@ func (u *User) String() string { buf.WriteString("User(") buf.WriteString(fmt.Sprintf("id=%v,", u.ID)) buf.WriteString(fmt.Sprintf("age=%v", u.Age)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("name=%v", u.Name)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("last=%v", u.Last)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("nickname=%v", u.Nickname)) - buf.WriteString(", ") - buf.WriteString(fmt.Sprintf("phone=%v", u.Phone)) + buf.WriteString(fmt.Sprintf(", name=%v", u.Name)) + buf.WriteString(fmt.Sprintf(", last=%v", u.Last)) + buf.WriteString(fmt.Sprintf(", nickname=%v", u.Nickname)) + buf.WriteString(fmt.Sprintf(", phone=%v", u.Phone)) buf.WriteString(")") return buf.String() } diff --git a/entc/integration/integration_test.go b/entc/integration/integration_test.go index 023902002..3d11b3327 100644 --- a/entc/integration/integration_test.go +++ b/entc/integration/integration_test.go @@ -95,6 +95,7 @@ func TestGremlin(t *testing.T) { // tests for all drivers to run. var tests = []func(*testing.T, *ent.Client){ Tx, + Types, Sanity, Paging, Charset, @@ -1754,4 +1755,5 @@ func drop(t *testing.T, client *ent.Client) { client.Group.Delete().ExecX(ctx) client.Comment.Delete().ExecX(ctx) client.GroupInfo.Delete().ExecX(ctx) + client.FieldType.Delete().ExecX(ctx) } diff --git a/entc/integration/migrate/entv1/client.go b/entc/integration/migrate/entv1/client.go new file mode 100644 index 000000000..86094445b --- /dev/null +++ b/entc/integration/migrate/entv1/client.go @@ -0,0 +1,99 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "fmt" + "log" + + "fbc/ent/entc/integration/migrate/entv1/migrate" + + "fbc/ent/entc/integration/migrate/entv1/user" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // User is the client for interacting with the User builders. + User *UserClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + c := config{log: log.Println} + c.options(opts...) + return &Client{ + config: c, + Schema: migrate.NewSchema(c.driver), + User: NewUserClient(c), + } +} + +// Tx returns a new transactional client. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, fmt.Errorf("entv1: cannot start a transaction within a transaction") + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("entv1: starting a transaction: %v", err) + } + cfg := config{driver: tx, log: c.log, verbose: c.verbose} + return &Tx{ + config: cfg, + User: NewUserClient(cfg), + }, nil +} + +// UserClient is a client for the User schema. +type UserClient struct { + config +} + +// NewUserClient returns a client for the User from the given config. +func NewUserClient(c config) *UserClient { + return &UserClient{config: c} +} + +// Create returns a create builder for User. +func (c *UserClient) Create() *UserCreate { + return &UserCreate{config: c.config} +} + +// Update returns an update builder for User. +func (c *UserClient) Update() *UserUpdate { + return &UserUpdate{config: c.config} +} + +// UpdateOne returns an update builder for the given entity. +func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { + return c.UpdateOneID(u.ID) +} + +// UpdateOneID returns an update builder for the given id. +func (c *UserClient) UpdateOneID(id string) *UserUpdateOne { + return &UserUpdateOne{config: c.config, id: id} +} + +// Delete returns a delete builder for User. +func (c *UserClient) Delete() *UserDelete { + return &UserDelete{config: c.config} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { + return c.DeleteOneID(u.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *UserClient) DeleteOneID(id string) *UserDeleteOne { + return &UserDeleteOne{c.Delete().Where(user.ID(id))} +} + +// Create returns a query builder for User. +func (c *UserClient) Query() *UserQuery { + return &UserQuery{config: c.config} +} diff --git a/entc/integration/migrate/entv1/config.go b/entc/integration/migrate/entv1/config.go new file mode 100644 index 000000000..1e99e63ec --- /dev/null +++ b/entc/integration/migrate/entv1/config.go @@ -0,0 +1,51 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "fbc/ent/dialect" +) + +// Option function to configure the client. +type Option func(*config) + +// Config is the configuration for the client and its builder. +type config struct { + // driver is the driver used for execute database requests. + driver dialect.Driver + // verbose enable a verbosity logging. + verbose bool + // log used for logging on verbose mode. + log func(...interface{}) +} + +// Options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.verbose { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Verbose sets the client logging to verbose. +func Verbose() Option { + return func(c *config) { + c.verbose = true + } +} + +// Log sets the client logging to verbose. +func Log(fn func(...interface{})) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} diff --git a/entc/integration/migrate/entv1/ent.go b/entc/integration/migrate/entv1/ent.go new file mode 100644 index 000000000..ec16d2846 --- /dev/null +++ b/entc/integration/migrate/entv1/ent.go @@ -0,0 +1,357 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "fmt" + "strconv" + "strings" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/encoding/graphson" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/__" +) + +// Predicate is an alias to ent.Predicate. +type Predicate = ent.Predicate + +// Or groups list of predicates with the or operator between them. +func Or(predicates ...ent.Predicate) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + for i, p := range predicates { + if i > 0 { + s.Or() + } + p.SQL(s) + } + }, + Gremlin: func(tr *dsl.Traversal) { + trs := make([]interface{}, 0, len(predicates)) + for _, p := range predicates { + t := __.New() + p.Gremlin(t) + trs = append(trs, t) + } + tr.Where(__.Or(trs...)) + }, + } +} + +// Not applies the not operator on the given predicate. +func Not(p ent.Predicate) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + p.SQL(s.Not()) + }, + Gremlin: func(tr *dsl.Traversal) { + t := __.New() + p.Gremlin(t) + tr.Where(__.Not(t)) + }, + } +} + +// Order applies an ordering on the traversal. +type Order ent.Predicate + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) Order { + return Order{ + SQL: func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Asc(f)) + } + }, + Gremlin: func(tr *dsl.Traversal) { + for _, f := range fields { + tr.By(f, dsl.Incr) + } + }, + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) Order { + return Order{ + SQL: func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Desc(f)) + } + }, + Gremlin: func(tr *dsl.Traversal) { + for _, f := range fields { + tr.By(f, dsl.Decr) + } + }, + } +} + +// 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 + // Gremlin gets two labels as parameters. The first used in the `As` step for the predicate, + // and the second is an optional name for the next predicates (or for later usage). + Gremlin func(string, string) (string, *dsl.Traversal) +} + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(entv1.As(entv1.Sum(field1), "sum_field1"), (entv1.As(entv1.Sum(field2), "sum_field2")). +// 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) + }, + Gremlin: func(start, _ string) (string, *dsl.Traversal) { + return fn.Gremlin(start, end) + }, + } +} + +// DefaultCountLabel is the default label name for the Count aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "count" 2 or more fields and avoid conflicting, use the `entv1.As(entv1.Count(field), "custom_name")` +// function with custom name in order to override it. +const DefaultCountLabel = "count" + +// Count applies the "count" aggregation function on each group. +func Count() Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Count("*") + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultCountLabel + } + return end, __.As(start).Count(dsl.Local).As(end) + }, + } +} + +// DefaultMaxLabel is the default label name for the Max aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "max" 2 or more fields and avoid conflicting, use the `entv1.As(entv1.Max(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMaxLabel = "max" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMaxLabel + } + return end, __.As(start).Unfold().Values(field).Max().As(end) + }, + } +} + +// DefaultMeanLabel is the default label name for the Mean aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "mean" 2 or more fields and avoid conflicting, use the `entv1.As(entv1.Mean(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMeanLabel = "mean" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMeanLabel + } + return end, __.As(start).Unfold().Values(field).Mean().As(end) + }, + } +} + +// DefaultMinLabel is the default label name for the Min aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "min" 2 or more fields and avoid conflicting, use the `entv1.As(entv1.Min(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMinLabel = "min" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMinLabel + } + return end, __.As(start).Unfold().Values(field).Min().As(end) + }, + } +} + +// DefaultSumLabel is the default label name for the Sum aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "sum" 2 or more fields and avoid conflicting, use the `entv1.As(entv1.Sum(field), "custom_name")` +// function with custom name in order to override it. +const DefaultSumLabel = "sum" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultSumLabel + } + return end, __.As(start).Unfold().Values(field).Sum().As(end) + }, + } +} + +// ErrNotFound returns when trying to fetch a specific entity and it was not found in the database. +type ErrNotFound struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotFound) Error() string { + return fmt.Sprintf("entv1: %s not found", e.label) +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + _, ok := err.(*ErrNotFound) + return ok +} + +// MaskNotFound masks nor found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// ErrNotSingular returns when trying to fetch a singular entity and more then one was found in the database. +type ErrNotSingular struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotSingular) Error() string { + return fmt.Sprintf("entv1: %s not singular", e.label) +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + _, ok := err.(*ErrNotSingular) + return ok +} + +// ErrConstraintFailed returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or field uniqueness. +type ErrConstraintFailed struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ErrConstraintFailed) Error() string { + return fmt.Sprintf("entv1: unique constraint failed: %s", e.msg) +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ErrConstraintFailed) Unwrap() error { + return e.wrap +} + +// Code implements the dsl.Node interface. +func (e ErrConstraintFailed) Code() (string, []interface{}) { + return strconv.Quote(e.prefix() + e.msg), nil +} + +func (e *ErrConstraintFailed) UnmarshalGraphson(b []byte) error { + var v [1]*string + if err := graphson.Unmarshal(b, &v); err != nil { + return err + } + if v[0] == nil { + return fmt.Errorf("entv1: missing string value") + } + if !strings.HasPrefix(*v[0], e.prefix()) { + return fmt.Errorf("entv1: invalid string for error: %s", *v[0]) + } + e.msg = strings.TrimPrefix(*v[0], e.prefix()) + return nil +} + +// prefix returns the prefix used for gremlin constants. +func (ErrConstraintFailed) prefix() string { return "Error: " } + +// NewErrUniqueField creates a constraint error for unique fields. +func NewErrUniqueField(label, field string, v interface{}) *ErrConstraintFailed { + return &ErrConstraintFailed{msg: fmt.Sprintf("field %s.%s with value: %#v", label, field, v)} +} + +// NewErrUniqueEdge creates a constraint error for unique edges. +func NewErrUniqueEdge(label, edge, id string) *ErrConstraintFailed { + return &ErrConstraintFailed{msg: fmt.Sprintf("edge %s.%s with id: %#v", label, edge, id)} +} + +// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure. +func IsConstraintFailure(err error) bool { + _, ok := err.(*ErrConstraintFailed) + return ok +} + +// isConstantError indicates if the given response holds a gremlin constant containing an error. +func isConstantError(r *gremlin.Response) (*ErrConstraintFailed, bool) { + e := &ErrConstraintFailed{} + if err := graphson.Unmarshal(r.Result.Data, e); err != nil { + return nil, false + } + return e, true +} + +func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) { + // Error number 1062 is ER_DUP_ENTRY in mysql, and "UNIQUE constraint failed" is SQLite prefix. + if msg := err.Error(); strings.HasPrefix(msg, "Error 1062") || strings.HasPrefix(msg, "UNIQUE constraint failed") { + return &ErrConstraintFailed{msg, err}, true + } + return nil, false +} + +// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred. +func rollback(tx dialect.Tx, err error) error { + if rerr := tx.Rollback(); rerr != nil { + err = fmt.Errorf("%s: %v", err.Error(), rerr) + } + if err, ok := isSQLConstraintError(err); ok { + return err + } + return err +} + +// keys returns the keys/ids from the edge map. +func keys(m map[string]struct{}) []string { + s := make([]string, 0, len(m)) + for id, _ := range m { + s = append(s, id) + } + return s +} diff --git a/entc/integration/migrate/entv1/example_test.go b/entc/integration/migrate/entv1/example_test.go new file mode 100644 index 000000000..84ccbe258 --- /dev/null +++ b/entc/integration/migrate/entv1/example_test.go @@ -0,0 +1,53 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "log" + "net/url" + "os" + + "fbc/ent/dialect" + "fbc/lib/go/gremlin" +) + +// endpoint for the database. In order to run the tests locally, run the following command: +// +// ENTV1_INTEGRATION_ENDPOINT="http://localhost:8182" go test -v +// +var endpoint *gremlin.Endpoint + +func init() { + if e, ok := os.LookupEnv("ENTV1_INTEGRATION_ENDPOINT"); ok { + if u, err := url.Parse(e); err == nil { + endpoint = &gremlin.Endpoint{u} + } + } +} + +func ExampleUser() { + if endpoint == nil { + return + } + ctx := context.Background() + conn, err := gremlin.NewClient(gremlin.Config{Endpoint: *endpoint}) + if err != nil { + log.Fatalf("failed creating database client: %v", err) + } + client := NewClient(Driver(dialect.NewGremlin(conn))) + + // creating vertices for the user's edges. + + // create user vertex with its edges. + u := client.User. + Create(). + SetAge(1). + SetName("string"). + SaveX(ctx) + log.Println("user created:", u) + + // query edges. + + // Output: +} diff --git a/entc/integration/migrate/entv1/migrate/migrate.go b/entc/integration/migrate/entv1/migrate/migrate.go new file mode 100644 index 000000000..3c796aaae --- /dev/null +++ b/entc/integration/migrate/entv1/migrate/migrate.go @@ -0,0 +1,32 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "fbc/ent/dialect/sql/schema" + "fbc/ent/field" +) + +var ( + nullable = true + // UsersColumns holds the columns for the "users" table. + UsersColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "age", Type: field.TypeInt32}, + {Name: "name", Type: field.TypeString, Size: 10}, + } + // UsersTable holds the schema information for the "users" table. + UsersTable = &schema.Table{ + Name: "users", + Columns: UsersColumns, + PrimaryKey: []*schema.Column{UsersColumns[0]}, + ForeignKeys: []*schema.ForeignKey{}, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + UsersTable, + } +) + +func init() { +} diff --git a/entc/integration/migrate/entv1/migrate/schema.go b/entc/integration/migrate/entv1/migrate/schema.go new file mode 100644 index 000000000..746e97204 --- /dev/null +++ b/entc/integration/migrate/entv1/migrate/schema.go @@ -0,0 +1,41 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + + "fbc/ent/dialect" + "fbc/ent/dialect/sql/schema" +) + +// SQLDialect wraps the dialect.Driver with additional migration methods. +type SQLDriver interface { + Create(context.Context, ...*schema.Table) error +} + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv SQLDriver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { + s := &Schema{} + switch drv.Dialect() { + case dialect.MySQL: + s.drv = &schema.MySQL{Driver: drv} + case dialect.SQLite: + s.drv = &schema.SQLite{Driver: drv} + } + return s +} + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context) error { + if s.drv == nil { + return fmt.Errorf("entv1/migrate: dialect does not support migration") + } + return s.drv.Create(ctx, Tables...) +} diff --git a/entc/integration/migrate/entv1/schema/user.go b/entc/integration/migrate/entv1/schema/user.go new file mode 100644 index 000000000..dd6d2c0e0 --- /dev/null +++ b/entc/integration/migrate/entv1/schema/user.go @@ -0,0 +1,19 @@ +package schema + +import ( + "fbc/ent" + "fbc/ent/field" +) + +// User holds the schema definition for the User entity. +type User struct { + ent.Schema +} + +// Fields of the User. +func (User) Fields() []ent.Field { + return []ent.Field{ + field.Int32("age"), + field.String("name").MaxLen(10), + } +} diff --git a/entc/integration/migrate/entv1/tx.go b/entc/integration/migrate/entv1/tx.go new file mode 100644 index 000000000..e736452fb --- /dev/null +++ b/entc/integration/migrate/entv1/tx.go @@ -0,0 +1,101 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "sync" + + "fbc/ent/dialect" + "fbc/ent/entc/integration/migrate/entv1/migrate" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // User is the client for interacting with the User builders. + User *UserClient +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + return tx.config.driver.(*txDriver).tx.Commit() +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + return tx.config.driver.(*txDriver).tx.Rollback() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + return &Client{ + config: tx.config, + Schema: migrate.NewSchema(tx.driver), + User: NewUserClient(tx.config), + } +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: User.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that this driver is safe for concurrent usage, however, it executes only one query +// at the time. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // protects the tx below from concurrent execution. + mu sync.Mutex + // tx is the underlying transaction. + tx dialect.Tx +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args interface{}, v interface{}) error { + tx.mu.Lock() + defer tx.mu.Unlock() + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args interface{}, v interface{}) error { + tx.mu.Lock() + defer tx.mu.Unlock() + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/entc/integration/migrate/entv1/user.go b/entc/integration/migrate/entv1/user.go new file mode 100644 index 000000000..d2ab243b2 --- /dev/null +++ b/entc/integration/migrate/entv1/user.go @@ -0,0 +1,145 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "bytes" + "fmt" + "strconv" + + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" +) + +// User is the model entity for the User schema. +type User struct { + config + // ID of the ent. + ID string `json:"id,omitempty"` + // Age holds the value of the "age" field. + Age int32 `json:"age,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` +} + +// FromResponse scans the gremlin response data into User. +func (u *User) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vu struct { + ID string `json:"id,omitempty"` + Age int32 `json:"age,omitempty"` + Name string `json:"name,omitempty"` + } + if err := vmap.Decode(&vu); err != nil { + return err + } + u.ID = vu.ID + u.Age = vu.Age + u.Name = vu.Name + return nil +} + +// FromRows scans the sql response data into User. +func (u *User) FromRows(rows *sql.Rows) error { + var vu struct { + ID int + Age int32 + Name string + } + // the order here should be the same as in the `user.Columns`. + if err := rows.Scan( + &vu.ID, + &vu.Age, + &vu.Name, + ); err != nil { + return err + } + u.ID = strconv.Itoa(vu.ID) + u.Age = vu.Age + u.Name = vu.Name + return nil +} + +// Update returns a builder for updating this User. +// Note that, you need to call User.Unwrap() before calling this method, if this User +// was returned from a transaction, and the transaction was committed or rolled back. +func (u *User) Update() *UserUpdateOne { + return (&UserClient{u.config}).UpdateOne(u) +} + +// Unwrap unwraps the entity that was returned from a transaction after it was closed, +// so that all next queries will be executed through the driver which created the transaction. +func (u *User) Unwrap() *User { + tx, ok := u.config.driver.(*txDriver) + if !ok { + panic("entv1: User is not a transactional entity") + } + u.config.driver = tx.drv + return u +} + +// String implements the fmt.Stringer. +func (u *User) String() string { + buf := bytes.NewBuffer(nil) + buf.WriteString("User(") + buf.WriteString(fmt.Sprintf("id=%v,", u.ID)) + buf.WriteString(fmt.Sprintf("age=%v", u.Age)) + buf.WriteString(fmt.Sprintf(", name=%v", u.Name)) + buf.WriteString(")") + return buf.String() +} + +// id returns the int representation of the ID field. +func (u *User) id() int { + id, _ := strconv.Atoi(u.ID) + return id +} + +// Users is a parsable slice of User. +type Users []*User + +// FromResponse scans the gremlin response data into Users. +func (u *Users) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vu []struct { + ID string `json:"id,omitempty"` + Age int32 `json:"age,omitempty"` + Name string `json:"name,omitempty"` + } + if err := vmap.Decode(&vu); err != nil { + return err + } + for _, v := range vu { + *u = append(*u, &User{ + ID: v.ID, + Age: v.Age, + Name: v.Name, + }) + } + return nil +} + +// FromRows scans the sql response data into Users. +func (u *Users) FromRows(rows *sql.Rows) error { + for rows.Next() { + vu := &User{} + if err := vu.FromRows(rows); err != nil { + return err + } + *u = append(*u, vu) + } + return nil +} + +func (u Users) config(cfg config) { + for i := range u { + u[i].config = cfg + } +} diff --git a/entc/integration/migrate/entv1/user/user.go b/entc/integration/migrate/entv1/user/user.go new file mode 100644 index 000000000..44e9f1187 --- /dev/null +++ b/entc/integration/migrate/entv1/user/user.go @@ -0,0 +1,33 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +import ( + "fbc/ent/entc/integration/migrate/entv1/schema" +) + +const ( + // Label holds the string label denoting the user type in the database. + Label = "user" + // FieldAge holds the string denoting the age vertex property in the database. + FieldAge = "age" + // FieldName holds the string denoting the name vertex property in the database. + FieldName = "name" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // Table holds the table name of the user in the database. + Table = "users" +) + +// Columns holds all SQL columns are user fields. +var Columns = []string{ + FieldID, + FieldAge, + FieldName, +} + +var ( + fields = schema.User{}.Fields() + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator = fields[1].Validators()[0].(func(string) error) +) diff --git a/entc/integration/migrate/entv1/user/where.go b/entc/integration/migrate/entv1/user/where.go new file mode 100644 index 000000000..820e80b7f --- /dev/null +++ b/entc/integration/migrate/entv1/user/where.go @@ -0,0 +1,448 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +import ( + "strconv" + + "fbc/ent" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/p" +) + +// ID filters vertices based on their identifier. +func ID(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(id) + }, + } +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.EQ(id)) + }, + } +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.NEQ(id)) + }, + } +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GT(id)) + }, + } +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GTE(id)) + }, + } +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LT(id)) + }, + } +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LTE(id)) + }, + } +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.In(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Within(v...)) + }, + } +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Without(v...)) + }, + } +} + +// Age applies equality check predicate on the "age" field. It's identical to AgeEQ. +func Age(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.EQ(v)) + }, + } +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EQ(v)) + }, + } +} + +// AgeEQ applies the EQ predicate on the "age" field. +func AgeEQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.EQ(v)) + }, + } +} + +// AgeNEQ applies the NEQ predicate on the "age" field. +func AgeNEQ(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.NEQ(v)) + }, + } +} + +// AgeGT applies the GT predicate on the "age" field. +func AgeGT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.GT(v)) + }, + } +} + +// AgeGTE applies the GTE predicate on the "age" field. +func AgeGTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.GTE(v)) + }, + } +} + +// AgeLT applies the LT predicate on the "age" field. +func AgeLT(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.LT(v)) + }, + } +} + +// AgeLTE applies the LTE predicate on the "age" field. +func AgeLTE(v int32) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.LTE(v)) + }, + } +} + +// AgeIn applies the In predicate on the "age" field. +func AgeIn(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldAge), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.Within(v...)) + }, + } +} + +// AgeNotIn applies the NotIn predicate on the "age" field. +func AgeNotIn(vs ...int32) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldAge), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.Without(v...)) + }, + } +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EQ(v)) + }, + } +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.NEQ(v)) + }, + } +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.GT(v)) + }, + } +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.GTE(v)) + }, + } +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.LT(v)) + }, + } +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.LTE(v)) + }, + } +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldName), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Within(v...)) + }, + } +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldName), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Without(v...)) + }, + } +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Containing(v)) + }, + } +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.StartingWith(v)) + }, + } +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EndingWith(v)) + }, + } +} diff --git a/entc/integration/migrate/entv1/user_create.go b/entc/integration/migrate/entv1/user_create.go new file mode 100644 index 000000000..4d18ba433 --- /dev/null +++ b/entc/integration/migrate/entv1/user_create.go @@ -0,0 +1,128 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "errors" + "fmt" + "strconv" + + "fbc/ent/entc/integration/migrate/entv1/user" + + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserCreate is the builder for creating a User entity. +type UserCreate struct { + config + age *int32 + name *string +} + +// SetAge sets the age field. +func (uc *UserCreate) SetAge(i int32) *UserCreate { + uc.age = &i + return uc +} + +// SetName sets the name field. +func (uc *UserCreate) SetName(s string) *UserCreate { + uc.name = &s + return uc +} + +// Save creates the User in the database. +func (uc *UserCreate) Save(ctx context.Context) (*User, error) { + if uc.age == nil { + return nil, errors.New("entv1: missing required field \"age\"") + } + if uc.name == nil { + return nil, errors.New("entv1: missing required field \"name\"") + } + if err := user.NameValidator(*uc.name); err != nil { + return nil, fmt.Errorf("entv1: validator failed for field \"name\": %v", err) + } + switch uc.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uc.sqlSave(ctx) + case dialect.Neptune: + return uc.gremlinSave(ctx) + default: + return nil, errors.New("entv1: unsupported dialect") + } +} + +// SaveX calls Save and panics if Save returns an error. +func (uc *UserCreate) SaveX(ctx context.Context) *User { + v, err := uc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { + var ( + res sql.Result + u = &User{config: uc.config} + ) + tx, err := uc.driver.Tx(ctx) + if err != nil { + 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 uc.name != nil { + builder.Set(user.FieldName, *uc.name) + u.Name = *uc.name + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + id, err := res.LastInsertId() + if err != nil { + return nil, rollback(tx, err) + } + u.ID = strconv.FormatInt(id, 10) + if err := tx.Commit(); err != nil { + return nil, err + } + return u, nil +} + +func (uc *UserCreate) gremlinSave(ctx context.Context) (*User, error) { + res := &gremlin.Response{} + query, bindings := uc.gremlin().Query() + if err := uc.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + u := &User{config: uc.config} + if err := u.FromResponse(res); err != nil { + return nil, err + } + return u, nil +} + +func (uc *UserCreate) gremlin() *dsl.Traversal { + v := g.AddV(user.Label) + if uc.age != nil { + v.Property(dsl.Single, user.FieldAge, *uc.age) + } + if uc.name != nil { + v.Property(dsl.Single, user.FieldName, *uc.name) + } + return v.ValueMap(true) +} diff --git a/entc/integration/migrate/entv1/user_delete.go b/entc/integration/migrate/entv1/user_delete.go new file mode 100644 index 000000000..ee6fa3aa8 --- /dev/null +++ b/entc/integration/migrate/entv1/user_delete.go @@ -0,0 +1,88 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "errors" + + "fbc/ent/entc/integration/migrate/entv1/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserDelete is the builder for deleting a User entity. +type UserDelete struct { + config + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (ud *UserDelete) Where(ps ...ent.Predicate) *UserDelete { + ud.predicates = append(ud.predicates, ps...) + return ud +} + +// Exec executes the deletion query. +func (ud *UserDelete) Exec(ctx context.Context) error { + switch ud.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ud.sqlExec(ctx) + case dialect.Neptune: + return ud.gremlinExec(ctx) + default: + return errors.New("entv1: unsupported dialect") + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ud *UserDelete) ExecX(ctx context.Context) { + if err := ud.Exec(ctx); err != nil { + panic(err) + } +} + +func (ud *UserDelete) sqlExec(ctx context.Context) error { + var res sql.Result + selector := sql.Select().From(sql.Table(user.Table)) + for _, p := range ud.predicates { + p.SQL(selector) + } + query, args := sql.Delete(user.Table).FromSelect(selector).Query() + return ud.driver.Exec(ctx, query, args, &res) +} + +func (ud *UserDelete) gremlinExec(ctx context.Context) error { + res := &gremlin.Response{} + query, bindings := ud.gremlin().Query() + return ud.driver.Exec(ctx, query, bindings, res) +} + +func (ud *UserDelete) gremlin() *dsl.Traversal { + t := g.V().HasLabel(user.Label) + for _, p := range ud.predicates { + p.Gremlin(t) + } + return t.Drop() +} + +// UserDeleteOne is the builder for deleting a single User entity. +type UserDeleteOne struct { + ud *UserDelete +} + +// Exec executes the deletion query. +func (udo *UserDeleteOne) Exec(ctx context.Context) error { + return udo.ud.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (udo *UserDeleteOne) ExecX(ctx context.Context) { + udo.ud.ExecX(ctx) +} diff --git a/entc/integration/migrate/entv1/user_query.go b/entc/integration/migrate/entv1/user_query.go new file mode 100644 index 000000000..8d2acbef7 --- /dev/null +++ b/entc/integration/migrate/entv1/user_query.go @@ -0,0 +1,616 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "errors" + "fmt" + "math" + + "fbc/ent/entc/integration/migrate/entv1/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/__" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserQuery is the builder for querying User entities. +type UserQuery struct { + config + limit *int + offset *int + order []Order + unique []string + predicates []ent.Predicate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Where adds a new predicate for the builder. +func (uq *UserQuery) Where(ps ...ent.Predicate) *UserQuery { + uq.predicates = append(uq.predicates, ps...) + return uq +} + +// Limit adds a limit step to the query. +func (uq *UserQuery) Limit(limit int) *UserQuery { + uq.limit = &limit + return uq +} + +// Offset adds an offset step to the query. +func (uq *UserQuery) Offset(offset int) *UserQuery { + uq.offset = &offset + return uq +} + +// Order adds an order step to the query. +func (uq *UserQuery) Order(o ...Order) *UserQuery { + uq.order = append(uq.order, o...) + return uq +} + +// Get returns a User entity by its id. +func (uq *UserQuery) Get(ctx context.Context, id string) (*User, error) { + return uq.Where(user.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (uq *UserQuery) GetX(ctx context.Context, id string) *User { + u, err := uq.Get(ctx, id) + if err != nil { + panic(err) + } + return u +} + +// First returns the first User entity in the query. Returns *ErrNotFound when no user was found. +func (uq *UserQuery) First(ctx context.Context) (*User, error) { + us, err := uq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(us) == 0 { + return nil, &ErrNotFound{user.Label} + } + return us[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (uq *UserQuery) FirstX(ctx context.Context) *User { + u, err := uq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return u +} + +// FirstID returns the first User id in the query. Returns *ErrNotFound when no id was found. +func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = uq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &ErrNotFound{user.Label} + return + } + return ids[0], nil +} + +// FirstXID is like FirstID, but panics if an error occurs. +func (uq *UserQuery) FirstXID(ctx context.Context) string { + id, err := uq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns the only User entity in the query, returns an error if not exactly one entity was returned. +func (uq *UserQuery) Only(ctx context.Context) (*User, error) { + us, err := uq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(us) { + case 1: + return us[0], nil + case 0: + return nil, &ErrNotFound{user.Label} + default: + return nil, &ErrNotSingular{user.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (uq *UserQuery) OnlyX(ctx context.Context) *User { + u, err := uq.Only(ctx) + if err != nil { + panic(err) + } + return u +} + +// OnlyID returns the only User id in the query, returns an error if not exactly one id was returned. +func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = uq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &ErrNotFound{user.Label} + default: + err = &ErrNotSingular{user.Label} + } + return +} + +// OnlyXID is like OnlyID, but panics if an error occurs. +func (uq *UserQuery) OnlyXID(ctx context.Context) string { + id, err := uq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Users. +func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlAll(ctx) + case dialect.Neptune: + return uq.gremlinAll(ctx) + default: + return nil, errors.New("entv1: unsupported dialect") + } +} + +// AllX is like All, but panics if an error occurs. +func (uq *UserQuery) AllX(ctx context.Context) []*User { + us, err := uq.All(ctx) + if err != nil { + panic(err) + } + return us +} + +// IDs executes the query and returns a list of User ids. +func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlIDs(ctx) + case dialect.Neptune: + return uq.gremlinIDs(ctx) + default: + return nil, errors.New("entv1: unsupported dialect") + } +} + +// IDsX is like IDs, but panics if an error occurs. +func (uq *UserQuery) IDsX(ctx context.Context) []string { + ids, err := uq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (uq *UserQuery) Count(ctx context.Context) (int, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlCount(ctx) + case dialect.Neptune: + return uq.gremlinCount(ctx) + default: + return 0, errors.New("entv1: unsupported dialect") + } +} + +// CountX is like Count, but panics if an error occurs. +func (uq *UserQuery) CountX(ctx context.Context) int { + count, err := uq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlExist(ctx) + case dialect.Neptune: + return uq.gremlinExist(ctx) + default: + return false, errors.New("entv1: unsupported dialect") + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (uq *UserQuery) ExistX(ctx context.Context) bool { + exist, err := uq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// GroupBy 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 { +// Age int32 `json:"age,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.User.Query(). +// GroupBy(user.FieldAge). +// Aggregate(entv1.Count()). +// Scan(ctx, &v) +// +func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { + group := &UserGroupBy{config: uq.config} + group.fields = append([]string{field}, fields...) + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + group.sql = uq.sqlQuery() + case dialect.Neptune: + group.gremlin = uq.gremlinQuery() + } + return group +} + +func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + if unique := uq.unique; len(unique) == 0 { + selector.Distinct() + } + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var us Users + if err := us.FromRows(rows); err != nil { + return nil, err + } + us.config(uq.config) + return us, nil +} + +func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + unique := []string{user.FieldID} + if len(uq.unique) > 0 { + unique = uq.unique + } + selector.Count(sql.Distinct(selector.Columns(unique...)...)) + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + if !rows.Next() { + return 0, errors.New("entv1: no rows found") + } + var n int + if err := rows.Scan(&n); err != nil { + return 0, fmt.Errorf("entv1: failed reading count: %v", err) + } + return n, nil +} + +func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := uq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("entv1: check existence: %v", err) + } + return n > 0, nil +} + +func (uq *UserQuery) sqlIDs(ctx context.Context) ([]string, error) { + vs, err := uq.sqlAll(ctx) + if err != nil { + return nil, err + } + var ids []string + for _, v := range vs { + ids = append(ids, v.ID) + } + return ids, nil +} + +func (uq *UserQuery) sqlQuery() *sql.Selector { + t1 := sql.Table(user.Table) + selector := sql.Select(t1.Columns(user.Columns...)...).From(t1) + if uq.sql != nil { + selector = uq.sql + selector.Select(selector.Columns(user.Columns...)...) + } + for _, p := range uq.predicates { + p.SQL(selector) + } + for _, p := range uq.order { + p.SQL(selector) + } + if offset := uq.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.MaxInt64) + } + if limit := uq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +func (uq *UserQuery) gremlinIDs(ctx context.Context) ([]string, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + vertices, err := res.ReadVertices() + if err != nil { + return nil, err + } + ids := make([]string, 0, len(vertices)) + for _, vertex := range vertices { + ids = append(ids, vertex.ID.(string)) + } + return ids, nil +} + +func (uq *UserQuery) gremlinAll(ctx context.Context) ([]*User, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().ValueMap(true).Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + var us Users + if err := us.FromResponse(res); err != nil { + return nil, err + } + us.config(uq.config) + return us, nil +} + +func (uq *UserQuery) gremlinCount(ctx context.Context) (int, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().Count().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return 0, err + } + return res.ReadInt() +} + +func (uq *UserQuery) gremlinExist(ctx context.Context) (bool, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().HasNext().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return false, err + } + return res.ReadBool() +} + +func (uq *UserQuery) gremlinQuery() *dsl.Traversal { + v := g.V().HasLabel(user.Label) + if uq.gremlin != nil { + v = uq.gremlin.Clone() + } + for _, p := range uq.predicates { + p.Gremlin(v) + } + if len(uq.order) > 0 { + v.Order() + for _, p := range uq.order { + p.Gremlin(v) + } + } + switch limit, offset := uq.limit, uq.offset; { + case limit != nil && offset != nil: + v.Range(*offset, *offset+*limit) + case offset != nil: + v.Range(*offset, math.MaxInt64) + case limit != nil: + v.Limit(*limit) + } + if unique := uq.unique; len(unique) == 0 { + v.Dedup() + } + return v +} + +// UserQuery is the builder for group-by User entities. +type UserGroupBy struct { + config + fields []string + fns []Aggregate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy { + ugb.fns = append(ugb.fns, fns...) + return ugb +} + +// Scan applies the group-by query and scan the result into the given value. +func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error { + switch ugb.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ugb.sqlScan(ctx, v) + case dialect.Neptune: + return ugb.gremlinScan(ctx, v) + default: + return errors.New("ugb: unsupported dialect") + } +} + +// ScanX is like Scan, but panics if an error occurs. +func (ugb *UserGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := ugb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv1: UserGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ugb *UserGroupBy) StringsX(ctx context.Context) []string { + v, err := ugb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv1: UserGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ugb *UserGroupBy) IntsX(ctx context.Context) []int { + v, err := ugb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv1: UserGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := ugb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv1: UserGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool { + v, err := ugb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ugb.sqlQuery().Query() + if err := ugb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (ugb *UserGroupBy) sqlQuery() *sql.Selector { + selector := ugb.sql + 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)) + } + return selector.Select(columns...).GroupBy(ugb.fields...) +} + +func (ugb *UserGroupBy) gremlinScan(ctx context.Context, v interface{}) error { + res := &gremlin.Response{} + query, bindings := ugb.gremlinQuery().Query() + if err := ugb.driver.Exec(ctx, query, bindings, res); err != nil { + return err + } + if len(ugb.fields)+len(ugb.fns) == 1 { + return res.ReadVal(v) + } + vm, err := res.ReadValueMap() + if err != nil { + return err + } + return vm.Decode(v) +} + +func (ugb *UserGroupBy) gremlinQuery() *dsl.Traversal { + var ( + trs []interface{} + names []interface{} + ) + for _, fn := range ugb.fns { + name, tr := fn.Gremlin("p", "") + trs = append(trs, tr) + names = append(names, name) + } + for _, f := range ugb.fields { + names = append(names, f) + trs = append(trs, __.As("p").Unfold().Values(f).As(f)) + } + return ugb.gremlin.Group(). + By(__.Values(ugb.fields...).Fold()). + By(__.Fold().Match(trs...).Select(names...)). + Select(dsl.Values). + Next() +} diff --git a/entc/integration/migrate/entv1/user_update.go b/entc/integration/migrate/entv1/user_update.go new file mode 100644 index 000000000..25398579b --- /dev/null +++ b/entc/integration/migrate/entv1/user_update.go @@ -0,0 +1,321 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv1 + +import ( + "context" + "errors" + "fmt" + + "fbc/ent/entc/integration/migrate/entv1/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserUpdate is the builder for updating User entities. +type UserUpdate struct { + config + age *int32 + name *string + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (uu *UserUpdate) Where(ps ...ent.Predicate) *UserUpdate { + uu.predicates = append(uu.predicates, ps...) + return uu +} + +// SetAge sets the age field. +func (uu *UserUpdate) SetAge(i int32) *UserUpdate { + uu.age = &i + return uu +} + +// SetName sets the name field. +func (uu *UserUpdate) SetName(s string) *UserUpdate { + uu.name = &s + return uu +} + +// Save executes the query and returns the number of rows/vertices matched by this operation. +func (uu *UserUpdate) Save(ctx context.Context) (int, error) { + if uu.name != nil { + if err := user.NameValidator(*uu.name); err != nil { + return 0, fmt.Errorf("entv1: validator failed for field \"name\": %v", err) + } + } + switch uu.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uu.sqlSave(ctx) + case dialect.Neptune: + vertices, err := uu.gremlinSave(ctx) + return len(vertices), err + default: + return 0, errors.New("entv1: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (uu *UserUpdate) SaveX(ctx context.Context) int { + affected, err := uu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (uu *UserUpdate) Exec(ctx context.Context) error { + _, err := uu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uu *UserUpdate) ExecX(ctx context.Context) { + if err := uu.Exec(ctx); err != nil { + panic(err) + } +} + +func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { + selector := sql.Select(user.FieldID).From(sql.Table(user.Table)) + for _, p := range uu.predicates { + p.SQL(selector) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err = uu.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + if err := rows.Scan(&id); err != nil { + return 0, fmt.Errorf("entv1: failed reading id: %v", err) + } + ids = append(ids, id) + } + if len(ids) == 0 { + return 0, nil + } + + tx, err := uu.driver.Tx(ctx) + if err != nil { + return 0, err + } + var ( + update bool + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if uu.age != nil { + update = true + builder.Set(user.FieldAge, *uu.age) + } + if uu.name != nil { + update = true + builder.Set(user.FieldName, *uu.name) + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return 0, err + } + return len(ids), nil +} + +func (uu *UserUpdate) gremlinSave(ctx context.Context) ([]*User, error) { + res := &gremlin.Response{} + query, bindings := uu.gremlin().Query() + if err := uu.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + var us Users + us.config(uu.config) + if err := us.FromResponse(res); err != nil { + return nil, err + } + return us, nil +} + +func (uu *UserUpdate) gremlin() *dsl.Traversal { + v := g.V().HasLabel(user.Label) + for _, p := range uu.predicates { + p.Gremlin(v) + } + var ( + trs []*dsl.Traversal + ) + if uu.age != nil { + v.Property(dsl.Single, user.FieldAge, *uu.age) + } + if uu.name != nil { + v.Property(dsl.Single, user.FieldName, *uu.name) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} + +// UserUpdateOne is the builder for updating a single User entity. +type UserUpdateOne struct { + config + id string + age *int32 + name *string +} + +// SetAge sets the age field. +func (uuo *UserUpdateOne) SetAge(i int32) *UserUpdateOne { + uuo.age = &i + return uuo +} + +// SetName sets the name field. +func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { + uuo.name = &s + return uuo +} + +// Save executes the query and returns the updated entity. +func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { + if uuo.name != nil { + if err := user.NameValidator(*uuo.name); err != nil { + return nil, fmt.Errorf("entv1: validator failed for field \"name\": %v", err) + } + } + switch uuo.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uuo.sqlSave(ctx) + case dialect.Neptune: + return uuo.gremlinSave(ctx) + default: + return nil, errors.New("entv1: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User { + u, err := uuo.Save(ctx) + if err != nil { + panic(err) + } + return u +} + +// Exec executes the query on the entity. +func (uuo *UserUpdateOne) Exec(ctx context.Context) error { + _, err := uuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uuo *UserUpdateOne) ExecX(ctx context.Context) { + if err := uuo.Exec(ctx); err != nil { + panic(err) + } +} + +func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { + selector := sql.Select(user.Columns...).From(sql.Table(user.Table)) + user.ID(uuo.id).SQL(selector) + rows := &sql.Rows{} + query, args := selector.Query() + if err = uuo.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + u = &User{config: uuo.config} + if err := u.FromRows(rows); err != nil { + return nil, fmt.Errorf("entv1: failed scanning row into User: %v", err) + } + id = u.id() + ids = append(ids, id) + } + switch n := len(ids); { + case n == 0: + return nil, fmt.Errorf("entv1: User not found with id: %v", uuo.id) + case n > 1: + return nil, fmt.Errorf("entv1: more than one User with the same id: %v", uuo.id) + } + + tx, err := uuo.driver.Tx(ctx) + if err != nil { + return nil, err + } + var ( + update bool + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if uuo.age != nil { + update = true + builder.Set(user.FieldAge, *uuo.age) + u.Age = *uuo.age + } + if uuo.name != nil { + update = true + builder.Set(user.FieldName, *uuo.name) + u.Name = *uuo.name + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return nil, err + } + return u, nil +} + +func (uuo *UserUpdateOne) gremlinSave(ctx context.Context) (*User, error) { + res := &gremlin.Response{} + query, bindings := uuo.gremlin(uuo.id).Query() + if err := uuo.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + u := &User{config: uuo.config} + if err := u.FromResponse(res); err != nil { + return nil, err + } + return u, nil +} + +func (uuo *UserUpdateOne) gremlin(id string) *dsl.Traversal { + v := g.V(id) + var ( + trs []*dsl.Traversal + ) + if uuo.age != nil { + v.Property(dsl.Single, user.FieldAge, *uuo.age) + } + if uuo.name != nil { + v.Property(dsl.Single, user.FieldName, *uuo.name) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} diff --git a/entc/integration/migrate/entv2/client.go b/entc/integration/migrate/entv2/client.go new file mode 100644 index 000000000..fdf12e5f6 --- /dev/null +++ b/entc/integration/migrate/entv2/client.go @@ -0,0 +1,99 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "fmt" + "log" + + "fbc/ent/entc/integration/migrate/entv2/migrate" + + "fbc/ent/entc/integration/migrate/entv2/user" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // User is the client for interacting with the User builders. + User *UserClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + c := config{log: log.Println} + c.options(opts...) + return &Client{ + config: c, + Schema: migrate.NewSchema(c.driver), + User: NewUserClient(c), + } +} + +// Tx returns a new transactional client. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, fmt.Errorf("entv2: cannot start a transaction within a transaction") + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("entv2: starting a transaction: %v", err) + } + cfg := config{driver: tx, log: c.log, verbose: c.verbose} + return &Tx{ + config: cfg, + User: NewUserClient(cfg), + }, nil +} + +// UserClient is a client for the User schema. +type UserClient struct { + config +} + +// NewUserClient returns a client for the User from the given config. +func NewUserClient(c config) *UserClient { + return &UserClient{config: c} +} + +// Create returns a create builder for User. +func (c *UserClient) Create() *UserCreate { + return &UserCreate{config: c.config} +} + +// Update returns an update builder for User. +func (c *UserClient) Update() *UserUpdate { + return &UserUpdate{config: c.config} +} + +// UpdateOne returns an update builder for the given entity. +func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { + return c.UpdateOneID(u.ID) +} + +// UpdateOneID returns an update builder for the given id. +func (c *UserClient) UpdateOneID(id string) *UserUpdateOne { + return &UserUpdateOne{config: c.config, id: id} +} + +// Delete returns a delete builder for User. +func (c *UserClient) Delete() *UserDelete { + return &UserDelete{config: c.config} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { + return c.DeleteOneID(u.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *UserClient) DeleteOneID(id string) *UserDeleteOne { + return &UserDeleteOne{c.Delete().Where(user.ID(id))} +} + +// Create returns a query builder for User. +func (c *UserClient) Query() *UserQuery { + return &UserQuery{config: c.config} +} diff --git a/entc/integration/migrate/entv2/config.go b/entc/integration/migrate/entv2/config.go new file mode 100644 index 000000000..127fa96db --- /dev/null +++ b/entc/integration/migrate/entv2/config.go @@ -0,0 +1,51 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "fbc/ent/dialect" +) + +// Option function to configure the client. +type Option func(*config) + +// Config is the configuration for the client and its builder. +type config struct { + // driver is the driver used for execute database requests. + driver dialect.Driver + // verbose enable a verbosity logging. + verbose bool + // log used for logging on verbose mode. + log func(...interface{}) +} + +// Options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.verbose { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Verbose sets the client logging to verbose. +func Verbose() Option { + return func(c *config) { + c.verbose = true + } +} + +// Log sets the client logging to verbose. +func Log(fn func(...interface{})) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} diff --git a/entc/integration/migrate/entv2/ent.go b/entc/integration/migrate/entv2/ent.go new file mode 100644 index 000000000..0e99d55f6 --- /dev/null +++ b/entc/integration/migrate/entv2/ent.go @@ -0,0 +1,357 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "fmt" + "strconv" + "strings" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/encoding/graphson" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/__" +) + +// Predicate is an alias to ent.Predicate. +type Predicate = ent.Predicate + +// Or groups list of predicates with the or operator between them. +func Or(predicates ...ent.Predicate) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + for i, p := range predicates { + if i > 0 { + s.Or() + } + p.SQL(s) + } + }, + Gremlin: func(tr *dsl.Traversal) { + trs := make([]interface{}, 0, len(predicates)) + for _, p := range predicates { + t := __.New() + p.Gremlin(t) + trs = append(trs, t) + } + tr.Where(__.Or(trs...)) + }, + } +} + +// Not applies the not operator on the given predicate. +func Not(p ent.Predicate) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + p.SQL(s.Not()) + }, + Gremlin: func(tr *dsl.Traversal) { + t := __.New() + p.Gremlin(t) + tr.Where(__.Not(t)) + }, + } +} + +// Order applies an ordering on the traversal. +type Order ent.Predicate + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) Order { + return Order{ + SQL: func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Asc(f)) + } + }, + Gremlin: func(tr *dsl.Traversal) { + for _, f := range fields { + tr.By(f, dsl.Incr) + } + }, + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) Order { + return Order{ + SQL: func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Desc(f)) + } + }, + Gremlin: func(tr *dsl.Traversal) { + for _, f := range fields { + tr.By(f, dsl.Decr) + } + }, + } +} + +// 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 + // Gremlin gets two labels as parameters. The first used in the `As` step for the predicate, + // and the second is an optional name for the next predicates (or for later usage). + Gremlin func(string, string) (string, *dsl.Traversal) +} + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(entv2.As(entv2.Sum(field1), "sum_field1"), (entv2.As(entv2.Sum(field2), "sum_field2")). +// 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) + }, + Gremlin: func(start, _ string) (string, *dsl.Traversal) { + return fn.Gremlin(start, end) + }, + } +} + +// DefaultCountLabel is the default label name for the Count aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "count" 2 or more fields and avoid conflicting, use the `entv2.As(entv2.Count(field), "custom_name")` +// function with custom name in order to override it. +const DefaultCountLabel = "count" + +// Count applies the "count" aggregation function on each group. +func Count() Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Count("*") + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultCountLabel + } + return end, __.As(start).Count(dsl.Local).As(end) + }, + } +} + +// DefaultMaxLabel is the default label name for the Max aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "max" 2 or more fields and avoid conflicting, use the `entv2.As(entv2.Max(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMaxLabel = "max" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMaxLabel + } + return end, __.As(start).Unfold().Values(field).Max().As(end) + }, + } +} + +// DefaultMeanLabel is the default label name for the Mean aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "mean" 2 or more fields and avoid conflicting, use the `entv2.As(entv2.Mean(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMeanLabel = "mean" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMeanLabel + } + return end, __.As(start).Unfold().Values(field).Mean().As(end) + }, + } +} + +// DefaultMinLabel is the default label name for the Min aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "min" 2 or more fields and avoid conflicting, use the `entv2.As(entv2.Min(field), "custom_name")` +// function with custom name in order to override it. +const DefaultMinLabel = "min" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultMinLabel + } + return end, __.As(start).Unfold().Values(field).Min().As(end) + }, + } +} + +// DefaultSumLabel is the default label name for the Sum aggregation function. +// It should be used as the struct-tag for decoding, or a map key for interaction with the returned response. +// In order to "sum" 2 or more fields and avoid conflicting, use the `entv2.As(entv2.Sum(field), "custom_name")` +// function with custom name in order to override it. +const DefaultSumLabel = "sum" + +// 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)) + }, + Gremlin: func(start, end string) (string, *dsl.Traversal) { + if end == "" { + end = DefaultSumLabel + } + return end, __.As(start).Unfold().Values(field).Sum().As(end) + }, + } +} + +// ErrNotFound returns when trying to fetch a specific entity and it was not found in the database. +type ErrNotFound struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotFound) Error() string { + return fmt.Sprintf("entv2: %s not found", e.label) +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + _, ok := err.(*ErrNotFound) + return ok +} + +// MaskNotFound masks nor found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// ErrNotSingular returns when trying to fetch a singular entity and more then one was found in the database. +type ErrNotSingular struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotSingular) Error() string { + return fmt.Sprintf("entv2: %s not singular", e.label) +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + _, ok := err.(*ErrNotSingular) + return ok +} + +// ErrConstraintFailed returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or field uniqueness. +type ErrConstraintFailed struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ErrConstraintFailed) Error() string { + return fmt.Sprintf("entv2: unique constraint failed: %s", e.msg) +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ErrConstraintFailed) Unwrap() error { + return e.wrap +} + +// Code implements the dsl.Node interface. +func (e ErrConstraintFailed) Code() (string, []interface{}) { + return strconv.Quote(e.prefix() + e.msg), nil +} + +func (e *ErrConstraintFailed) UnmarshalGraphson(b []byte) error { + var v [1]*string + if err := graphson.Unmarshal(b, &v); err != nil { + return err + } + if v[0] == nil { + return fmt.Errorf("entv2: missing string value") + } + if !strings.HasPrefix(*v[0], e.prefix()) { + return fmt.Errorf("entv2: invalid string for error: %s", *v[0]) + } + e.msg = strings.TrimPrefix(*v[0], e.prefix()) + return nil +} + +// prefix returns the prefix used for gremlin constants. +func (ErrConstraintFailed) prefix() string { return "Error: " } + +// NewErrUniqueField creates a constraint error for unique fields. +func NewErrUniqueField(label, field string, v interface{}) *ErrConstraintFailed { + return &ErrConstraintFailed{msg: fmt.Sprintf("field %s.%s with value: %#v", label, field, v)} +} + +// NewErrUniqueEdge creates a constraint error for unique edges. +func NewErrUniqueEdge(label, edge, id string) *ErrConstraintFailed { + return &ErrConstraintFailed{msg: fmt.Sprintf("edge %s.%s with id: %#v", label, edge, id)} +} + +// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure. +func IsConstraintFailure(err error) bool { + _, ok := err.(*ErrConstraintFailed) + return ok +} + +// isConstantError indicates if the given response holds a gremlin constant containing an error. +func isConstantError(r *gremlin.Response) (*ErrConstraintFailed, bool) { + e := &ErrConstraintFailed{} + if err := graphson.Unmarshal(r.Result.Data, e); err != nil { + return nil, false + } + return e, true +} + +func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) { + // Error number 1062 is ER_DUP_ENTRY in mysql, and "UNIQUE constraint failed" is SQLite prefix. + if msg := err.Error(); strings.HasPrefix(msg, "Error 1062") || strings.HasPrefix(msg, "UNIQUE constraint failed") { + return &ErrConstraintFailed{msg, err}, true + } + return nil, false +} + +// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred. +func rollback(tx dialect.Tx, err error) error { + if rerr := tx.Rollback(); rerr != nil { + err = fmt.Errorf("%s: %v", err.Error(), rerr) + } + if err, ok := isSQLConstraintError(err); ok { + return err + } + return err +} + +// keys returns the keys/ids from the edge map. +func keys(m map[string]struct{}) []string { + s := make([]string, 0, len(m)) + for id, _ := range m { + s = append(s, id) + } + return s +} diff --git a/entc/integration/migrate/entv2/example_test.go b/entc/integration/migrate/entv2/example_test.go new file mode 100644 index 000000000..bee26863f --- /dev/null +++ b/entc/integration/migrate/entv2/example_test.go @@ -0,0 +1,54 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "log" + "net/url" + "os" + + "fbc/ent/dialect" + "fbc/lib/go/gremlin" +) + +// endpoint for the database. In order to run the tests locally, run the following command: +// +// ENTV2_INTEGRATION_ENDPOINT="http://localhost:8182" go test -v +// +var endpoint *gremlin.Endpoint + +func init() { + if e, ok := os.LookupEnv("ENTV2_INTEGRATION_ENDPOINT"); ok { + if u, err := url.Parse(e); err == nil { + endpoint = &gremlin.Endpoint{u} + } + } +} + +func ExampleUser() { + if endpoint == nil { + return + } + ctx := context.Background() + conn, err := gremlin.NewClient(gremlin.Config{Endpoint: *endpoint}) + if err != nil { + log.Fatalf("failed creating database client: %v", err) + } + client := NewClient(Driver(dialect.NewGremlin(conn))) + + // creating vertices for the user's edges. + + // create user vertex with its edges. + u := client.User. + Create(). + SetAge(1). + SetName("string"). + SetPhone("string"). + SaveX(ctx) + log.Println("user created:", u) + + // query edges. + + // Output: +} diff --git a/entc/integration/migrate/entv2/migrate/migrate.go b/entc/integration/migrate/entv2/migrate/migrate.go new file mode 100644 index 000000000..e1a8abeaf --- /dev/null +++ b/entc/integration/migrate/entv2/migrate/migrate.go @@ -0,0 +1,33 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "fbc/ent/dialect/sql/schema" + "fbc/ent/field" +) + +var ( + nullable = true + // UsersColumns holds the columns for the "users" table. + UsersColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "age", Type: field.TypeInt}, + {Name: "name", Type: field.TypeString, Size: 2147483647}, + {Name: "phone", Type: field.TypeString}, + } + // UsersTable holds the schema information for the "users" table. + UsersTable = &schema.Table{ + Name: "users", + Columns: UsersColumns, + PrimaryKey: []*schema.Column{UsersColumns[0]}, + ForeignKeys: []*schema.ForeignKey{}, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + UsersTable, + } +) + +func init() { +} diff --git a/entc/integration/migrate/entv2/migrate/schema.go b/entc/integration/migrate/entv2/migrate/schema.go new file mode 100644 index 000000000..382d38a90 --- /dev/null +++ b/entc/integration/migrate/entv2/migrate/schema.go @@ -0,0 +1,41 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + + "fbc/ent/dialect" + "fbc/ent/dialect/sql/schema" +) + +// SQLDialect wraps the dialect.Driver with additional migration methods. +type SQLDriver interface { + Create(context.Context, ...*schema.Table) error +} + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv SQLDriver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { + s := &Schema{} + switch drv.Dialect() { + case dialect.MySQL: + s.drv = &schema.MySQL{Driver: drv} + case dialect.SQLite: + s.drv = &schema.SQLite{Driver: drv} + } + return s +} + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context) error { + if s.drv == nil { + return fmt.Errorf("entv2/migrate: dialect does not support migration") + } + return s.drv.Create(ctx, Tables...) +} diff --git a/entc/integration/migrate/entv2/schema/user.go b/entc/integration/migrate/entv2/schema/user.go new file mode 100644 index 000000000..8c56f78bb --- /dev/null +++ b/entc/integration/migrate/entv2/schema/user.go @@ -0,0 +1,23 @@ +package schema + +import ( + "fbc/ent" + "fbc/ent/field" +) + +// User holds the schema definition for the User entity. +type User struct { + ent.Schema +} + +// Fields of the User. +func (User) Fields() []ent.Field { + return []ent.Field{ + // changing the type of the field. + field.Int("age"), + // extending name field to longtext. + field.Text("name"), + // adding new column. + field.String("phone"), + } +} diff --git a/entc/integration/migrate/entv2/tx.go b/entc/integration/migrate/entv2/tx.go new file mode 100644 index 000000000..11c8f99a2 --- /dev/null +++ b/entc/integration/migrate/entv2/tx.go @@ -0,0 +1,101 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "sync" + + "fbc/ent/dialect" + "fbc/ent/entc/integration/migrate/entv2/migrate" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // User is the client for interacting with the User builders. + User *UserClient +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + return tx.config.driver.(*txDriver).tx.Commit() +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + return tx.config.driver.(*txDriver).tx.Rollback() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + return &Client{ + config: tx.config, + Schema: migrate.NewSchema(tx.driver), + User: NewUserClient(tx.config), + } +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: User.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that this driver is safe for concurrent usage, however, it executes only one query +// at the time. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // protects the tx below from concurrent execution. + mu sync.Mutex + // tx is the underlying transaction. + tx dialect.Tx +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args interface{}, v interface{}) error { + tx.mu.Lock() + defer tx.mu.Unlock() + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args interface{}, v interface{}) error { + tx.mu.Lock() + defer tx.mu.Unlock() + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/entc/integration/migrate/entv2/user.go b/entc/integration/migrate/entv2/user.go new file mode 100644 index 000000000..1e0cfdee8 --- /dev/null +++ b/entc/integration/migrate/entv2/user.go @@ -0,0 +1,155 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "bytes" + "fmt" + "strconv" + + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" +) + +// User is the model entity for the User schema. +type User struct { + config + // ID of the ent. + ID string `json:"id,omitempty"` + // Age holds the value of the "age" field. + Age int `json:"age,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Phone holds the value of the "phone" field. + Phone string `json:"phone,omitempty"` +} + +// FromResponse scans the gremlin response data into User. +func (u *User) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vu struct { + ID string `json:"id,omitempty"` + Age int `json:"age,omitempty"` + Name string `json:"name,omitempty"` + Phone string `json:"phone,omitempty"` + } + if err := vmap.Decode(&vu); err != nil { + return err + } + u.ID = vu.ID + u.Age = vu.Age + u.Name = vu.Name + u.Phone = vu.Phone + return nil +} + +// FromRows scans the sql response data into User. +func (u *User) FromRows(rows *sql.Rows) error { + var vu struct { + ID int + Age int + Name string + Phone string + } + // the order here should be the same as in the `user.Columns`. + if err := rows.Scan( + &vu.ID, + &vu.Age, + &vu.Name, + &vu.Phone, + ); err != nil { + return err + } + u.ID = strconv.Itoa(vu.ID) + u.Age = vu.Age + u.Name = vu.Name + u.Phone = vu.Phone + return nil +} + +// Update returns a builder for updating this User. +// Note that, you need to call User.Unwrap() before calling this method, if this User +// was returned from a transaction, and the transaction was committed or rolled back. +func (u *User) Update() *UserUpdateOne { + return (&UserClient{u.config}).UpdateOne(u) +} + +// Unwrap unwraps the entity that was returned from a transaction after it was closed, +// so that all next queries will be executed through the driver which created the transaction. +func (u *User) Unwrap() *User { + tx, ok := u.config.driver.(*txDriver) + if !ok { + panic("entv2: User is not a transactional entity") + } + u.config.driver = tx.drv + return u +} + +// String implements the fmt.Stringer. +func (u *User) String() string { + buf := bytes.NewBuffer(nil) + buf.WriteString("User(") + buf.WriteString(fmt.Sprintf("id=%v,", u.ID)) + buf.WriteString(fmt.Sprintf("age=%v", u.Age)) + buf.WriteString(fmt.Sprintf(", name=%v", u.Name)) + buf.WriteString(fmt.Sprintf(", phone=%v", u.Phone)) + buf.WriteString(")") + return buf.String() +} + +// id returns the int representation of the ID field. +func (u *User) id() int { + id, _ := strconv.Atoi(u.ID) + return id +} + +// Users is a parsable slice of User. +type Users []*User + +// FromResponse scans the gremlin response data into Users. +func (u *Users) FromResponse(res *gremlin.Response) error { + vmap, err := res.ReadValueMap() + if err != nil { + return err + } + var vu []struct { + ID string `json:"id,omitempty"` + Age int `json:"age,omitempty"` + Name string `json:"name,omitempty"` + Phone string `json:"phone,omitempty"` + } + if err := vmap.Decode(&vu); err != nil { + return err + } + for _, v := range vu { + *u = append(*u, &User{ + ID: v.ID, + Age: v.Age, + Name: v.Name, + Phone: v.Phone, + }) + } + return nil +} + +// FromRows scans the sql response data into Users. +func (u *Users) FromRows(rows *sql.Rows) error { + for rows.Next() { + vu := &User{} + if err := vu.FromRows(rows); err != nil { + return err + } + *u = append(*u, vu) + } + return nil +} + +func (u Users) config(cfg config) { + for i := range u { + u[i].config = cfg + } +} diff --git a/entc/integration/migrate/entv2/user/user.go b/entc/integration/migrate/entv2/user/user.go new file mode 100644 index 000000000..bef6ab94f --- /dev/null +++ b/entc/integration/migrate/entv2/user/user.go @@ -0,0 +1,26 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +const ( + // Label holds the string label denoting the user type in the database. + Label = "user" + // FieldAge holds the string denoting the age vertex property in the database. + FieldAge = "age" + // FieldName holds the string denoting the name vertex property in the database. + FieldName = "name" + // FieldPhone holds the string denoting the phone vertex property in the database. + FieldPhone = "phone" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // Table holds the table name of the user in the database. + Table = "users" +) + +// Columns holds all SQL columns are user fields. +var Columns = []string{ + FieldID, + FieldAge, + FieldName, + FieldPhone, +} diff --git a/entc/integration/migrate/entv2/user/where.go b/entc/integration/migrate/entv2/user/where.go new file mode 100644 index 000000000..7a418504d --- /dev/null +++ b/entc/integration/migrate/entv2/user/where.go @@ -0,0 +1,612 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +import ( + "strconv" + + "fbc/ent" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/p" +) + +// ID filters vertices based on their identifier. +func ID(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(id) + }, + } +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.EQ(id)) + }, + } +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.NEQ(id)) + }, + } +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GT(id)) + }, + } +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.GTE(id)) + }, + } +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LT(id)) + }, + } +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + v, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.HasID(p.LTE(id)) + }, + } +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.In(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Within(v...)) + }, + } +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...string) ent.Predicate { + return ent.Predicate{ + SQL: 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], _ = strconv.Atoi(ids[i]) + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + t.HasID(p.Without(v...)) + }, + } +} + +// Age applies equality check predicate on the "age" field. It's identical to AgeEQ. +func Age(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.EQ(v)) + }, + } +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EQ(v)) + }, + } +} + +// Phone applies equality check predicate on the "phone" field. It's identical to PhoneEQ. +func Phone(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.EQ(v)) + }, + } +} + +// AgeEQ applies the EQ predicate on the "age" field. +func AgeEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.EQ(v)) + }, + } +} + +// AgeNEQ applies the NEQ predicate on the "age" field. +func AgeNEQ(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.NEQ(v)) + }, + } +} + +// AgeGT applies the GT predicate on the "age" field. +func AgeGT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.GT(v)) + }, + } +} + +// AgeGTE applies the GTE predicate on the "age" field. +func AgeGTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.GTE(v)) + }, + } +} + +// AgeLT applies the LT predicate on the "age" field. +func AgeLT(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.LT(v)) + }, + } +} + +// AgeLTE applies the LTE predicate on the "age" field. +func AgeLTE(v int) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldAge), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.LTE(v)) + }, + } +} + +// AgeIn applies the In predicate on the "age" field. +func AgeIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldAge), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.Within(v...)) + }, + } +} + +// AgeNotIn applies the NotIn predicate on the "age" field. +func AgeNotIn(vs ...int) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldAge), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldAge, p.Without(v...)) + }, + } +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EQ(v)) + }, + } +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.NEQ(v)) + }, + } +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.GT(v)) + }, + } +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.GTE(v)) + }, + } +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.LT(v)) + }, + } +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.LTE(v)) + }, + } +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldName), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Within(v...)) + }, + } +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldName), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Without(v...)) + }, + } +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.Containing(v)) + }, + } +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.StartingWith(v)) + }, + } +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldName), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldName, p.EndingWith(v)) + }, + } +} + +// PhoneEQ applies the EQ predicate on the "phone" field. +func PhoneEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.EQ(v)) + }, + } +} + +// PhoneNEQ applies the NEQ predicate on the "phone" field. +func PhoneNEQ(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.NEQ(v)) + }, + } +} + +// PhoneGT applies the GT predicate on the "phone" field. +func PhoneGT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.GT(v)) + }, + } +} + +// PhoneGTE applies the GTE predicate on the "phone" field. +func PhoneGTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.GTE(v)) + }, + } +} + +// PhoneLT applies the LT predicate on the "phone" field. +func PhoneLT(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.LT(v)) + }, + } +} + +// PhoneLTE applies the LTE predicate on the "phone" field. +func PhoneLTE(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.LTE(v)) + }, + } +} + +// PhoneIn applies the In predicate on the "phone" field. +func PhoneIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldPhone), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.Within(v...)) + }, + } +} + +// PhoneNotIn applies the NotIn predicate on the "phone" field. +func PhoneNotIn(vs ...string) ent.Predicate { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return ent.Predicate{ + SQL: 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(FieldPhone), v...)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.Without(v...)) + }, + } +} + +// PhoneContains applies the Contains predicate on the "phone" field. +func PhoneContains(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.Containing(v)) + }, + } +} + +// PhoneHasPrefix applies the HasPrefix predicate on the "phone" field. +func PhoneHasPrefix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.StartingWith(v)) + }, + } +} + +// PhoneHasSuffix applies the HasSuffix predicate on the "phone" field. +func PhoneHasSuffix(v string) ent.Predicate { + return ent.Predicate{ + SQL: func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldPhone), v)) + }, + Gremlin: func(t *dsl.Traversal) { + t.Has(Label, FieldPhone, p.EndingWith(v)) + }, + } +} diff --git a/entc/integration/migrate/entv2/user_create.go b/entc/integration/migrate/entv2/user_create.go new file mode 100644 index 000000000..ba6c427de --- /dev/null +++ b/entc/integration/migrate/entv2/user_create.go @@ -0,0 +1,141 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "errors" + "strconv" + + "fbc/ent/entc/integration/migrate/entv2/user" + + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserCreate is the builder for creating a User entity. +type UserCreate struct { + config + age *int + name *string + phone *string +} + +// SetAge sets the age field. +func (uc *UserCreate) SetAge(i int) *UserCreate { + uc.age = &i + return uc +} + +// SetName sets the name field. +func (uc *UserCreate) SetName(s string) *UserCreate { + uc.name = &s + return uc +} + +// SetPhone sets the phone field. +func (uc *UserCreate) SetPhone(s string) *UserCreate { + uc.phone = &s + return uc +} + +// Save creates the User in the database. +func (uc *UserCreate) Save(ctx context.Context) (*User, error) { + if uc.age == nil { + return nil, errors.New("entv2: missing required field \"age\"") + } + if uc.name == nil { + return nil, errors.New("entv2: missing required field \"name\"") + } + if uc.phone == nil { + return nil, errors.New("entv2: missing required field \"phone\"") + } + switch uc.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uc.sqlSave(ctx) + case dialect.Neptune: + return uc.gremlinSave(ctx) + default: + return nil, errors.New("entv2: unsupported dialect") + } +} + +// SaveX calls Save and panics if Save returns an error. +func (uc *UserCreate) SaveX(ctx context.Context) *User { + v, err := uc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { + var ( + res sql.Result + u = &User{config: uc.config} + ) + tx, err := uc.driver.Tx(ctx) + if err != nil { + 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 uc.name != nil { + builder.Set(user.FieldName, *uc.name) + u.Name = *uc.name + } + if uc.phone != nil { + builder.Set(user.FieldPhone, *uc.phone) + u.Phone = *uc.phone + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + id, err := res.LastInsertId() + if err != nil { + return nil, rollback(tx, err) + } + u.ID = strconv.FormatInt(id, 10) + if err := tx.Commit(); err != nil { + return nil, err + } + return u, nil +} + +func (uc *UserCreate) gremlinSave(ctx context.Context) (*User, error) { + res := &gremlin.Response{} + query, bindings := uc.gremlin().Query() + if err := uc.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + u := &User{config: uc.config} + if err := u.FromResponse(res); err != nil { + return nil, err + } + return u, nil +} + +func (uc *UserCreate) gremlin() *dsl.Traversal { + v := g.AddV(user.Label) + if uc.age != nil { + v.Property(dsl.Single, user.FieldAge, *uc.age) + } + if uc.name != nil { + v.Property(dsl.Single, user.FieldName, *uc.name) + } + if uc.phone != nil { + v.Property(dsl.Single, user.FieldPhone, *uc.phone) + } + return v.ValueMap(true) +} diff --git a/entc/integration/migrate/entv2/user_delete.go b/entc/integration/migrate/entv2/user_delete.go new file mode 100644 index 000000000..e670324a4 --- /dev/null +++ b/entc/integration/migrate/entv2/user_delete.go @@ -0,0 +1,88 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "errors" + + "fbc/ent/entc/integration/migrate/entv2/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserDelete is the builder for deleting a User entity. +type UserDelete struct { + config + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (ud *UserDelete) Where(ps ...ent.Predicate) *UserDelete { + ud.predicates = append(ud.predicates, ps...) + return ud +} + +// Exec executes the deletion query. +func (ud *UserDelete) Exec(ctx context.Context) error { + switch ud.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ud.sqlExec(ctx) + case dialect.Neptune: + return ud.gremlinExec(ctx) + default: + return errors.New("entv2: unsupported dialect") + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ud *UserDelete) ExecX(ctx context.Context) { + if err := ud.Exec(ctx); err != nil { + panic(err) + } +} + +func (ud *UserDelete) sqlExec(ctx context.Context) error { + var res sql.Result + selector := sql.Select().From(sql.Table(user.Table)) + for _, p := range ud.predicates { + p.SQL(selector) + } + query, args := sql.Delete(user.Table).FromSelect(selector).Query() + return ud.driver.Exec(ctx, query, args, &res) +} + +func (ud *UserDelete) gremlinExec(ctx context.Context) error { + res := &gremlin.Response{} + query, bindings := ud.gremlin().Query() + return ud.driver.Exec(ctx, query, bindings, res) +} + +func (ud *UserDelete) gremlin() *dsl.Traversal { + t := g.V().HasLabel(user.Label) + for _, p := range ud.predicates { + p.Gremlin(t) + } + return t.Drop() +} + +// UserDeleteOne is the builder for deleting a single User entity. +type UserDeleteOne struct { + ud *UserDelete +} + +// Exec executes the deletion query. +func (udo *UserDeleteOne) Exec(ctx context.Context) error { + return udo.ud.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (udo *UserDeleteOne) ExecX(ctx context.Context) { + udo.ud.ExecX(ctx) +} diff --git a/entc/integration/migrate/entv2/user_query.go b/entc/integration/migrate/entv2/user_query.go new file mode 100644 index 000000000..8953cf8ec --- /dev/null +++ b/entc/integration/migrate/entv2/user_query.go @@ -0,0 +1,616 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "errors" + "fmt" + "math" + + "fbc/ent/entc/integration/migrate/entv2/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/__" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserQuery is the builder for querying User entities. +type UserQuery struct { + config + limit *int + offset *int + order []Order + unique []string + predicates []ent.Predicate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Where adds a new predicate for the builder. +func (uq *UserQuery) Where(ps ...ent.Predicate) *UserQuery { + uq.predicates = append(uq.predicates, ps...) + return uq +} + +// Limit adds a limit step to the query. +func (uq *UserQuery) Limit(limit int) *UserQuery { + uq.limit = &limit + return uq +} + +// Offset adds an offset step to the query. +func (uq *UserQuery) Offset(offset int) *UserQuery { + uq.offset = &offset + return uq +} + +// Order adds an order step to the query. +func (uq *UserQuery) Order(o ...Order) *UserQuery { + uq.order = append(uq.order, o...) + return uq +} + +// Get returns a User entity by its id. +func (uq *UserQuery) Get(ctx context.Context, id string) (*User, error) { + return uq.Where(user.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (uq *UserQuery) GetX(ctx context.Context, id string) *User { + u, err := uq.Get(ctx, id) + if err != nil { + panic(err) + } + return u +} + +// First returns the first User entity in the query. Returns *ErrNotFound when no user was found. +func (uq *UserQuery) First(ctx context.Context) (*User, error) { + us, err := uq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(us) == 0 { + return nil, &ErrNotFound{user.Label} + } + return us[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (uq *UserQuery) FirstX(ctx context.Context) *User { + u, err := uq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return u +} + +// FirstID returns the first User id in the query. Returns *ErrNotFound when no id was found. +func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = uq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &ErrNotFound{user.Label} + return + } + return ids[0], nil +} + +// FirstXID is like FirstID, but panics if an error occurs. +func (uq *UserQuery) FirstXID(ctx context.Context) string { + id, err := uq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns the only User entity in the query, returns an error if not exactly one entity was returned. +func (uq *UserQuery) Only(ctx context.Context) (*User, error) { + us, err := uq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(us) { + case 1: + return us[0], nil + case 0: + return nil, &ErrNotFound{user.Label} + default: + return nil, &ErrNotSingular{user.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (uq *UserQuery) OnlyX(ctx context.Context) *User { + u, err := uq.Only(ctx) + if err != nil { + panic(err) + } + return u +} + +// OnlyID returns the only User id in the query, returns an error if not exactly one id was returned. +func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { + var ids []string + if ids, err = uq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &ErrNotFound{user.Label} + default: + err = &ErrNotSingular{user.Label} + } + return +} + +// OnlyXID is like OnlyID, but panics if an error occurs. +func (uq *UserQuery) OnlyXID(ctx context.Context) string { + id, err := uq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Users. +func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlAll(ctx) + case dialect.Neptune: + return uq.gremlinAll(ctx) + default: + return nil, errors.New("entv2: unsupported dialect") + } +} + +// AllX is like All, but panics if an error occurs. +func (uq *UserQuery) AllX(ctx context.Context) []*User { + us, err := uq.All(ctx) + if err != nil { + panic(err) + } + return us +} + +// IDs executes the query and returns a list of User ids. +func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlIDs(ctx) + case dialect.Neptune: + return uq.gremlinIDs(ctx) + default: + return nil, errors.New("entv2: unsupported dialect") + } +} + +// IDsX is like IDs, but panics if an error occurs. +func (uq *UserQuery) IDsX(ctx context.Context) []string { + ids, err := uq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (uq *UserQuery) Count(ctx context.Context) (int, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlCount(ctx) + case dialect.Neptune: + return uq.gremlinCount(ctx) + default: + return 0, errors.New("entv2: unsupported dialect") + } +} + +// CountX is like Count, but panics if an error occurs. +func (uq *UserQuery) CountX(ctx context.Context) int { + count, err := uq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uq.sqlExist(ctx) + case dialect.Neptune: + return uq.gremlinExist(ctx) + default: + return false, errors.New("entv2: unsupported dialect") + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (uq *UserQuery) ExistX(ctx context.Context) bool { + exist, err := uq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// GroupBy 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 { +// Age int `json:"age,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.User.Query(). +// GroupBy(user.FieldAge). +// Aggregate(entv2.Count()). +// Scan(ctx, &v) +// +func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { + group := &UserGroupBy{config: uq.config} + group.fields = append([]string{field}, fields...) + switch uq.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + group.sql = uq.sqlQuery() + case dialect.Neptune: + group.gremlin = uq.gremlinQuery() + } + return group +} + +func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + if unique := uq.unique; len(unique) == 0 { + selector.Distinct() + } + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var us Users + if err := us.FromRows(rows); err != nil { + return nil, err + } + us.config(uq.config) + return us, nil +} + +func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + unique := []string{user.FieldID} + if len(uq.unique) > 0 { + unique = uq.unique + } + selector.Count(sql.Distinct(selector.Columns(unique...)...)) + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + if !rows.Next() { + return 0, errors.New("entv2: no rows found") + } + var n int + if err := rows.Scan(&n); err != nil { + return 0, fmt.Errorf("entv2: failed reading count: %v", err) + } + return n, nil +} + +func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := uq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("entv2: check existence: %v", err) + } + return n > 0, nil +} + +func (uq *UserQuery) sqlIDs(ctx context.Context) ([]string, error) { + vs, err := uq.sqlAll(ctx) + if err != nil { + return nil, err + } + var ids []string + for _, v := range vs { + ids = append(ids, v.ID) + } + return ids, nil +} + +func (uq *UserQuery) sqlQuery() *sql.Selector { + t1 := sql.Table(user.Table) + selector := sql.Select(t1.Columns(user.Columns...)...).From(t1) + if uq.sql != nil { + selector = uq.sql + selector.Select(selector.Columns(user.Columns...)...) + } + for _, p := range uq.predicates { + p.SQL(selector) + } + for _, p := range uq.order { + p.SQL(selector) + } + if offset := uq.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.MaxInt64) + } + if limit := uq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +func (uq *UserQuery) gremlinIDs(ctx context.Context) ([]string, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + vertices, err := res.ReadVertices() + if err != nil { + return nil, err + } + ids := make([]string, 0, len(vertices)) + for _, vertex := range vertices { + ids = append(ids, vertex.ID.(string)) + } + return ids, nil +} + +func (uq *UserQuery) gremlinAll(ctx context.Context) ([]*User, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().ValueMap(true).Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + var us Users + if err := us.FromResponse(res); err != nil { + return nil, err + } + us.config(uq.config) + return us, nil +} + +func (uq *UserQuery) gremlinCount(ctx context.Context) (int, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().Count().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return 0, err + } + return res.ReadInt() +} + +func (uq *UserQuery) gremlinExist(ctx context.Context) (bool, error) { + res := &gremlin.Response{} + query, bindings := uq.gremlinQuery().HasNext().Query() + if err := uq.driver.Exec(ctx, query, bindings, res); err != nil { + return false, err + } + return res.ReadBool() +} + +func (uq *UserQuery) gremlinQuery() *dsl.Traversal { + v := g.V().HasLabel(user.Label) + if uq.gremlin != nil { + v = uq.gremlin.Clone() + } + for _, p := range uq.predicates { + p.Gremlin(v) + } + if len(uq.order) > 0 { + v.Order() + for _, p := range uq.order { + p.Gremlin(v) + } + } + switch limit, offset := uq.limit, uq.offset; { + case limit != nil && offset != nil: + v.Range(*offset, *offset+*limit) + case offset != nil: + v.Range(*offset, math.MaxInt64) + case limit != nil: + v.Limit(*limit) + } + if unique := uq.unique; len(unique) == 0 { + v.Dedup() + } + return v +} + +// UserQuery is the builder for group-by User entities. +type UserGroupBy struct { + config + fields []string + fns []Aggregate + // intermediate queries. + sql *sql.Selector + gremlin *dsl.Traversal +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy { + ugb.fns = append(ugb.fns, fns...) + return ugb +} + +// Scan applies the group-by query and scan the result into the given value. +func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error { + switch ugb.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return ugb.sqlScan(ctx, v) + case dialect.Neptune: + return ugb.gremlinScan(ctx, v) + default: + return errors.New("ugb: unsupported dialect") + } +} + +// ScanX is like Scan, but panics if an error occurs. +func (ugb *UserGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := ugb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv2: UserGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ugb *UserGroupBy) StringsX(ctx context.Context) []string { + v, err := ugb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv2: UserGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ugb *UserGroupBy) IntsX(ctx context.Context) []int { + v, err := ugb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv2: UserGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := ugb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("entv2: UserGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool { + v, err := ugb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ugb.sqlQuery().Query() + if err := ugb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (ugb *UserGroupBy) sqlQuery() *sql.Selector { + selector := ugb.sql + 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)) + } + return selector.Select(columns...).GroupBy(ugb.fields...) +} + +func (ugb *UserGroupBy) gremlinScan(ctx context.Context, v interface{}) error { + res := &gremlin.Response{} + query, bindings := ugb.gremlinQuery().Query() + if err := ugb.driver.Exec(ctx, query, bindings, res); err != nil { + return err + } + if len(ugb.fields)+len(ugb.fns) == 1 { + return res.ReadVal(v) + } + vm, err := res.ReadValueMap() + if err != nil { + return err + } + return vm.Decode(v) +} + +func (ugb *UserGroupBy) gremlinQuery() *dsl.Traversal { + var ( + trs []interface{} + names []interface{} + ) + for _, fn := range ugb.fns { + name, tr := fn.Gremlin("p", "") + trs = append(trs, tr) + names = append(names, name) + } + for _, f := range ugb.fields { + names = append(names, f) + trs = append(trs, __.As("p").Unfold().Values(f).As(f)) + } + return ugb.gremlin.Group(). + By(__.Values(ugb.fields...).Fold()). + By(__.Fold().Match(trs...).Select(names...)). + Select(dsl.Values). + Next() +} diff --git a/entc/integration/migrate/entv2/user_update.go b/entc/integration/migrate/entv2/user_update.go new file mode 100644 index 000000000..217169c45 --- /dev/null +++ b/entc/integration/migrate/entv2/user_update.go @@ -0,0 +1,340 @@ +// Code generated (@generated) by entc, DO NOT EDIT. + +package entv2 + +import ( + "context" + "errors" + "fmt" + + "fbc/ent/entc/integration/migrate/entv2/user" + + "fbc/ent" + "fbc/ent/dialect" + "fbc/ent/dialect/sql" + + "fbc/lib/go/gremlin" + "fbc/lib/go/gremlin/graph/dsl" + "fbc/lib/go/gremlin/graph/dsl/g" +) + +// UserUpdate is the builder for updating User entities. +type UserUpdate struct { + config + age *int + name *string + phone *string + predicates []ent.Predicate +} + +// Where adds a new predicate for the builder. +func (uu *UserUpdate) Where(ps ...ent.Predicate) *UserUpdate { + uu.predicates = append(uu.predicates, ps...) + return uu +} + +// SetAge sets the age field. +func (uu *UserUpdate) SetAge(i int) *UserUpdate { + uu.age = &i + return uu +} + +// SetName sets the name field. +func (uu *UserUpdate) SetName(s string) *UserUpdate { + uu.name = &s + return uu +} + +// SetPhone sets the phone field. +func (uu *UserUpdate) SetPhone(s string) *UserUpdate { + uu.phone = &s + return uu +} + +// Save executes the query and returns the number of rows/vertices matched by this operation. +func (uu *UserUpdate) Save(ctx context.Context) (int, error) { + switch uu.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uu.sqlSave(ctx) + case dialect.Neptune: + vertices, err := uu.gremlinSave(ctx) + return len(vertices), err + default: + return 0, errors.New("entv2: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (uu *UserUpdate) SaveX(ctx context.Context) int { + affected, err := uu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (uu *UserUpdate) Exec(ctx context.Context) error { + _, err := uu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uu *UserUpdate) ExecX(ctx context.Context) { + if err := uu.Exec(ctx); err != nil { + panic(err) + } +} + +func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { + selector := sql.Select(user.FieldID).From(sql.Table(user.Table)) + for _, p := range uu.predicates { + p.SQL(selector) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err = uu.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + if err := rows.Scan(&id); err != nil { + return 0, fmt.Errorf("entv2: failed reading id: %v", err) + } + ids = append(ids, id) + } + if len(ids) == 0 { + return 0, nil + } + + tx, err := uu.driver.Tx(ctx) + if err != nil { + return 0, err + } + var ( + update bool + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if uu.age != nil { + update = true + builder.Set(user.FieldAge, *uu.age) + } + if uu.name != nil { + update = true + builder.Set(user.FieldName, *uu.name) + } + if uu.phone != nil { + update = true + builder.Set(user.FieldPhone, *uu.phone) + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return 0, err + } + return len(ids), nil +} + +func (uu *UserUpdate) gremlinSave(ctx context.Context) ([]*User, error) { + res := &gremlin.Response{} + query, bindings := uu.gremlin().Query() + if err := uu.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + var us Users + us.config(uu.config) + if err := us.FromResponse(res); err != nil { + return nil, err + } + return us, nil +} + +func (uu *UserUpdate) gremlin() *dsl.Traversal { + v := g.V().HasLabel(user.Label) + for _, p := range uu.predicates { + p.Gremlin(v) + } + var ( + trs []*dsl.Traversal + ) + if uu.age != nil { + v.Property(dsl.Single, user.FieldAge, *uu.age) + } + if uu.name != nil { + v.Property(dsl.Single, user.FieldName, *uu.name) + } + if uu.phone != nil { + v.Property(dsl.Single, user.FieldPhone, *uu.phone) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} + +// UserUpdateOne is the builder for updating a single User entity. +type UserUpdateOne struct { + config + id string + age *int + name *string + phone *string +} + +// SetAge sets the age field. +func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne { + uuo.age = &i + return uuo +} + +// SetName sets the name field. +func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { + uuo.name = &s + return uuo +} + +// SetPhone sets the phone field. +func (uuo *UserUpdateOne) SetPhone(s string) *UserUpdateOne { + uuo.phone = &s + return uuo +} + +// Save executes the query and returns the updated entity. +func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { + switch uuo.driver.Dialect() { + case dialect.MySQL, dialect.SQLite: + return uuo.sqlSave(ctx) + case dialect.Neptune: + return uuo.gremlinSave(ctx) + default: + return nil, errors.New("entv2: unsupported dialect") + } +} + +// SaveX is like Save, but panics if an error occurs. +func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User { + u, err := uuo.Save(ctx) + if err != nil { + panic(err) + } + return u +} + +// Exec executes the query on the entity. +func (uuo *UserUpdateOne) Exec(ctx context.Context) error { + _, err := uuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uuo *UserUpdateOne) ExecX(ctx context.Context) { + if err := uuo.Exec(ctx); err != nil { + panic(err) + } +} + +func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { + selector := sql.Select(user.Columns...).From(sql.Table(user.Table)) + user.ID(uuo.id).SQL(selector) + rows := &sql.Rows{} + query, args := selector.Query() + if err = uuo.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + u = &User{config: uuo.config} + if err := u.FromRows(rows); err != nil { + return nil, fmt.Errorf("entv2: failed scanning row into User: %v", err) + } + id = u.id() + ids = append(ids, id) + } + switch n := len(ids); { + case n == 0: + return nil, fmt.Errorf("entv2: User not found with id: %v", uuo.id) + case n > 1: + return nil, fmt.Errorf("entv2: more than one User with the same id: %v", uuo.id) + } + + tx, err := uuo.driver.Tx(ctx) + if err != nil { + return nil, err + } + var ( + update bool + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if uuo.age != nil { + update = true + builder.Set(user.FieldAge, *uuo.age) + u.Age = *uuo.age + } + if uuo.name != nil { + update = true + builder.Set(user.FieldName, *uuo.name) + u.Name = *uuo.name + } + if uuo.phone != nil { + update = true + builder.Set(user.FieldPhone, *uuo.phone) + u.Phone = *uuo.phone + } + if update { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return nil, err + } + return u, nil +} + +func (uuo *UserUpdateOne) gremlinSave(ctx context.Context) (*User, error) { + res := &gremlin.Response{} + query, bindings := uuo.gremlin(uuo.id).Query() + if err := uuo.driver.Exec(ctx, query, bindings, res); err != nil { + return nil, err + } + if err, ok := isConstantError(res); ok { + return nil, err + } + u := &User{config: uuo.config} + if err := u.FromResponse(res); err != nil { + return nil, err + } + return u, nil +} + +func (uuo *UserUpdateOne) gremlin(id string) *dsl.Traversal { + v := g.V(id) + var ( + trs []*dsl.Traversal + ) + if uuo.age != nil { + v.Property(dsl.Single, user.FieldAge, *uuo.age) + } + if uuo.name != nil { + v.Property(dsl.Single, user.FieldName, *uuo.name) + } + if uuo.phone != nil { + v.Property(dsl.Single, user.FieldPhone, *uuo.phone) + } + v.ValueMap(true) + trs = append(trs, v) + return dsl.Join(trs...) +} diff --git a/entc/integration/migrate/migrate_test.go b/entc/integration/migrate/migrate_test.go new file mode 100644 index 000000000..f017862e9 --- /dev/null +++ b/entc/integration/migrate/migrate_test.go @@ -0,0 +1,57 @@ +package migrate + +import ( + "context" + "testing" + + "fbc/ent/dialect/sql" + "fbc/ent/entc/integration/migrate/entv1" + "fbc/ent/entc/integration/migrate/entv2" + + _ "github.com/go-sql-driver/mysql" + _ "github.com/mattn/go-sqlite3" + "github.com/stretchr/testify/require" +) + +func TestMySQL(t *testing.T) { + root, err := sql.Open("mysql", "root:pass@tcp(localhost:3306)/") + require.NoError(t, err) + defer root.Close() + ctx := context.Background() + err = root.Exec(ctx, "CREATE DATABASE migrate", []interface{}{}, new(sql.Result)) + require.NoError(t, err, "creating database") + defer root.Exec(ctx, "DROP DATABASE migrate", []interface{}{}, new(sql.Result)) + + drv, err := sql.Open("mysql", "root:pass@tcp(localhost:3306)/migrate?parseTime=True") + require.NoError(t, err, "connecting to migrate database") + + // run migration and execute queries on v1. + clientv1 := entv1.NewClient(entv1.Driver(drv)) + require.NoError(t, clientv1.Schema.Create(ctx)) + SanityV1(t, clientv1) + + // run migration and execute queries on v2. + clientv2 := entv2.NewClient(entv2.Driver(drv)) + require.NoError(t, clientv2.Schema.Create(ctx)) + SanityV2(t, clientv2) +} + +func SanityV1(t *testing.T, client *entv1.Client) { + ctx := context.Background() + u := client.User.Create().SetAge(1).SetName("foo").SaveX(ctx) + require.Equal(t, int32(1), u.Age) + require.Equal(t, "foo", u.Name) + + _, err := client.User.Create().SetAge(1).SetName("foobarbazqux").Save(ctx) + require.Error(t, err, "name is limited to 10 chars") +} + +func SanityV2(t *testing.T, client *entv2.Client) { + ctx := context.Background() + u := client.User.Create().SetAge(1).SetName("bar").SetPhone("100").SaveX(ctx) + require.Equal(t, 1, u.Age) + require.Equal(t, "bar", u.Name) + + _, err := client.User.Create().SetAge(1).SetName("foobarbazqux").SetPhone("100").Save(ctx) + require.NoError(t, err, "name is not limited to 10 chars") +} diff --git a/entc/integration/type_test.go b/entc/integration/type_test.go new file mode 100644 index 000000000..18820963f --- /dev/null +++ b/entc/integration/type_test.go @@ -0,0 +1,80 @@ +package integration + +import ( + "context" + "math" + "testing" + + "fbc/ent/entc/integration/ent" + + "github.com/stretchr/testify/require" +) + +func Types(t *testing.T, client *ent.Client) { + ctx := context.Background() + require := require.New(t) + + ft := client.FieldType.Create(). + SetInt(1). + SetInt8(8). + SetInt16(16). + SetInt32(32). + SetInt64(64). + SaveX(ctx) + + require.Equal(1, ft.Int) + require.Equal(int8(8), ft.Int8) + require.Equal(int16(16), ft.Int16) + require.Equal(int32(32), ft.Int32) + require.Equal(int64(64), ft.Int64) + + ft = client.FieldType.Create(). + SetInt(1). + SetInt8(math.MaxInt8). + SetInt16(math.MaxInt16). + SetInt32(math.MaxInt16). + SetInt64(math.MaxInt16). + SetOptionalInt8(math.MaxInt8). + SetOptionalInt16(math.MaxInt16). + SetOptionalInt32(math.MaxInt32). + SetOptionalInt64(math.MaxInt64). + SetNullableInt8(math.MaxInt8). + SetNullableInt16(math.MaxInt16). + SetNullableInt32(math.MaxInt32). + SetNullableInt64(math.MaxInt64). + SaveX(ctx) + + require.Equal(int8(math.MaxInt8), ft.OptionalInt8) + require.Equal(int16(math.MaxInt16), ft.OptionalInt16) + require.Equal(int32(math.MaxInt32), ft.OptionalInt32) + require.Equal(int64(math.MaxInt64), ft.OptionalInt64) + require.Equal(int8(math.MaxInt8), *ft.NullableInt8) + require.Equal(int16(math.MaxInt16), *ft.NullableInt16) + require.Equal(int32(math.MaxInt32), *ft.NullableInt32) + require.Equal(int64(math.MaxInt64), *ft.NullableInt64) + + ft = client.FieldType.UpdateOne(ft). + SetInt(1). + SetInt8(math.MaxInt8). + SetInt16(math.MaxInt16). + SetInt32(math.MaxInt16). + SetInt64(math.MaxInt16). + SetOptionalInt8(math.MaxInt8). + SetOptionalInt16(math.MaxInt16). + SetOptionalInt32(math.MaxInt32). + SetOptionalInt64(math.MaxInt64). + SetNullableInt8(math.MaxInt8). + SetNullableInt16(math.MaxInt16). + SetNullableInt32(math.MaxInt32). + SetNullableInt64(math.MaxInt64). + SaveX(ctx) + + require.Equal(int8(math.MaxInt8), ft.OptionalInt8) + require.Equal(int16(math.MaxInt16), ft.OptionalInt16) + require.Equal(int32(math.MaxInt32), ft.OptionalInt32) + require.Equal(int64(math.MaxInt64), ft.OptionalInt64) + require.Equal(int8(math.MaxInt8), *ft.NullableInt8) + require.Equal(int16(math.MaxInt16), *ft.NullableInt16) + require.Equal(int32(math.MaxInt32), *ft.NullableInt32) + require.Equal(int64(math.MaxInt64), *ft.NullableInt64) +} diff --git a/field/field.go b/field/field.go index 0ad2ab241..518a9eace 100644 --- a/field/field.go +++ b/field/field.go @@ -2,6 +2,7 @@ package field import ( "errors" + "math" "regexp" "strconv" "strings" @@ -16,15 +17,15 @@ const ( TypeBool TypeTime TypeString - TypeInt TypeInt8 TypeInt16 TypeInt32 + TypeInt TypeInt64 - TypeUint TypeUint8 TypeUint16 TypeUint32 + TypeUint TypeUint64 TypeFloat32 TypeFloat64 @@ -75,6 +76,7 @@ var typeNames = [...]string{ type Field struct { typ Type tag string + size int name string comment string charset string @@ -89,12 +91,30 @@ type Field struct { // Int returns a new Field with type int. func Int(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt, name: name}} } +// Int8 returns a new Field with type int8. +func Int8(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt8, name: name}} } + +// Int16 returns a new Field with type int16. +func Int16(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt16, name: name}} } + +// Int32 returns a new Field with type int32. +func Int32(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt32, name: name}} } + +// Int64 returns a new Field with type int64. +func Int64(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt64, name: name}} } + // Float returns a new Field with type float. func Float(name string) *floatBuilder { return &floatBuilder{Field{typ: TypeFloat64, name: name}} } // String returns a new Field with type string. func String(name string) *stringBuilder { return &stringBuilder{Field{typ: TypeString, name: name}} } +// Text returns a new string field without limitation on the size. +// In MySQL, it is the "longtext" type, but in SQLite and Gremlin it has not effect. +func Text(name string) *stringBuilder { + return &stringBuilder{Field{typ: TypeString, name: name, size: math.MaxInt32}} +} + // Bool returns a new Field with type bool. func Bool(name string) *boolBuilder { return &boolBuilder{Field{typ: TypeBool, name: name}} } @@ -337,6 +357,7 @@ func (b *stringBuilder) MinLen(i int) *stringBuilder { // MaxLen adds a length validator for this field. // Operation fails if the length of the string is greater than the given value. func (b *stringBuilder) MaxLen(i int) *stringBuilder { + b.size = i b.validators = append(b.validators, func(v string) error { if len(v) > i { return errors.New("value is less than the required length") @@ -391,6 +412,10 @@ func (b *stringBuilder) SetCharset(s string) *stringBuilder { return b } +// Size returns the maximum size of a string. +// In SQL dialects this is parameter for varchar. +func (b stringBuilder) Size() int { return b.size } + // Charset returns the character set of the field. func (b stringBuilder) Charset() string { return b.charset } @@ -466,3 +491,8 @@ func (b *boolBuilder) StructTag(s string) *boolBuilder { type Charseter interface { Charset() string } + +// Sizer is the interface that wraps the Size method. +type Sizer interface { + Size() int +} diff --git a/field/field_test.go b/field/field_test.go index 89fd290d3..26a7d6102 100644 --- a/field/field_test.go +++ b/field/field_test.go @@ -25,6 +25,11 @@ func TestInt(t *testing.T) { assert.False(t, f.HasDefault()) assert.True(t, f.IsNullable()) assert.Len(t, f.Validators(), 1) + + assert.Equal(t, field.TypeInt8, field.Int8("age").Type()) + assert.Equal(t, field.TypeInt16, field.Int16("age").Type()) + assert.Equal(t, field.TypeInt32, field.Int32("age").Type()) + assert.Equal(t, field.TypeInt64, field.Int64("age").Type()) } func TestFloat(t *testing.T) {