An entity framework for Go

Related tags

orm entity-framework ent
Overview

ent - An Entity Framework For Go

Simple, yet powerful entity framework for Go, that makes it easy to build and maintain applications with large data-models.

  • Schema As Code - model any database schema as Go objects.
  • Easily Traverse Any Graph - run queries, aggregations and traverse any graph structure easily.
  • Statically Typed And Explicit API - 100% statically typed and explicit API using code generation.
  • Multi Storage Driver - supports MySQL, PostgreSQL, SQLite and Gremlin.
  • Extendable - simple to extend and customize using Go templates.

Quick Installation

go get entgo.io/ent/cmd/ent

For proper installation using Go modules, visit entgo.io website.

Docs and Support

The documentation for developing and using ent is available at: https://entgo.io

For discussion and support, open an issue or join our channel in the gophers Slack.

Join the ent Community

In order to contribute to ent, see the CONTRIBUTING file for how to go get started.
If your company or your product is using ent, please let us know by adding yourself to the ent users page.

About the Project

The ent project was inspired by Ent, an entity framework we use internally. It is developed and maintained by a8m and alexsn from the Facebook Connectivity team. It is used by multiple teams and projects in production, and the roadmap for its v1 release is described here. Read more about the motivation of the project here.

License

ent is licensed under Apache 2.0 as found in the LICENSE file.

Issues
  • WIP: SQLite3 support for migrations

    WIP: SQLite3 support for migrations

    This is a basic start, a lot of cut and paste but it does pass some very basic tests now. I still have more work to do but I was hoping we could discuss some of it as it arrives, so here's the PR.

    CLA Signed 
    opened by erikh 32
  • entc/gen: add support for edge-fields (foreign-keys)

    entc/gen: add support for edge-fields (foreign-keys)

    Update

    Please see https://entgo.io/docs/schema-edges/#edge-field for full docs.


    Add an API for loading and getting the FKs of ent models, and gate it with feature-flag.

    This change adds a new method on each <T>Query (with FKs on its table) named WithFK() for loading the FKs together with all other fields. However, if users want to select specific fields, they can use Select(...) for selecting any field (including FK). For example:

    pets, err = client.Pet.Query().
    	WithFKs().
    	All(ctx)
    
    pets, err = client.Pet.Query().
    	Select(pet.FieldName, pet.ForeignKeys...).
    	All(ctx)
    

    Also, for each field-edge (an edge with FK), we generate a new method (e.g. OwnerID() (int, error)), that returns the value of the foreign-key, or an error if it wasn't loaded on query or wasn't found (was NULL in the database). For example:

    owner, err := luna.OwnerID()
    

    Next steps (in future PRs) are to add the Select option also to mutations (e.g. Pet.Update()) and predicates for simplifying queries:

    pets, err := client.Pet.Query().
    	Where(pet.OwnerID(id)).
    	All(ctx)
    

    Please share you feedback. Thanks cc @aight8 @errorhandler @Siceberg @rubensayshi

    CLA Signed 
    opened by a8m 20
  • ent/circleci: store go tests metadata (#1527)

    ent/circleci: store go tests metadata (#1527)

    Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1527

    See https://circleci.com/blog/level-up-go-test-with-gotestsum/ for more info

    Differential Revision: D17761305

    CLA Signed Merged 
    opened by alexsn 20
  • migrations with sqlite3

    migrations with sqlite3

    I have roughly the schema below, and on the second pass of Schema.Create, it gives this stack trace. I notice on the documentation near the trace it says sqlite3 can't be used in "append-only" mode because it's "just for testing". Is that the current state of things? If so I can just change my database targets.

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x957333]
    
    goroutine 1 [running]:
    github.com/facebookincubator/ent/dialect/sql/schema.(*Migrate).changeSet(0xc00011f740, 0x0, 0x10b6c40, 0xc8f660, 0xc00015a860, 0xbb0ea2)
            /usergo/pkg/mod/github.com/facebookincubator/[email protected]/dialect/sql/schema/migrate.go:241 +0x63
    github.com/facebookincubator/ent/dialect/sql/schema.(*Migrate).create(0xc00011f740, 0xc8f460, 0xc0000a0000, 0xc8f660, 0xc00015a860, 0x10b0920, 0x3, 0x3, 0xbd9320, 0xc00011f740)
            /usergo/pkg/mod/github.com/facebookincubator/[email protected]/dialect/sql/schema/migrate.go:121 +0x1b6
    github.com/facebookincubator/ent/dialect/sql/schema.(*Migrate).Create(0xc00011f740, 0xc8f460, 0xc0000a0000, 0x10b0920, 0x3, 0x3, 0x0, 0x0)
            /usergo/pkg/mod/github.com/facebookincubator/[email protected]/dialect/sql/schema/migrate.go:104 +0x11f
    github.com/tinyci/services/service/usersvc/ent/migrate.(*Schema).Create(0xc0000ab6c0, 0xc8f460, 0xc0000a0000, 0x0, 0x0, 0x0, 0x0, 0xc0000d0d80)
            /usergo/src/github.com/tinyci/services/service/usersvc/ent/migrate/migrate.go:48 +0x12a
    

    Schema:

    // 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.String("username").Immutable().Unique(),
        field.String("password"),
        field.Time("created_at").Immutable().Default(time.Now),
        field.Time("updated_at").Default(time.Now),
      }
    }
    
    // Edges of the User.
    func (User) Edges() []ent.Edge {
      return []ent.Edge{
        edge.To("capabilities", Capability.Type),
        edge.To("tokens", AuthToken.Type),
      }
    }
    
    // Capability holds the schema definition for the Capabilities entity.
    type Capability struct {
      ent.Schema
    }
    
    // Fields of the Capabilities.
    func (Capability) Fields() []ent.Field {
      return []ent.Field{
        field.String("capability").Immutable().Unique(),
      }
    }
    
    // Edges of the Capabilities.
    func (Capability) Edges() []ent.Edge {
      return []ent.Edge{
        edge.To("users", User.Type).Unique(),
      }
    }
    
    
    // AuthToken holds the schema definition for the AuthToken entity.
    type AuthToken struct {
      ent.Schema
    }
    
    // Fields of the AuthToken.
    func (AuthToken) Fields() []ent.Field {
      return []ent.Field{
        field.String("service").Immutable(),
        field.String("token").Sensitive(),
        field.Time("created_at").Immutable().Default(time.Now),
        field.Time("expires_at").Immutable().Nillable().Optional(),
      }
    }
    
    // Edges of the AuthToken.
    func (AuthToken) Edges() []ent.Edge {
      return []ent.Edge{
        edge.To("user", User.Type).Required().Unique(),
      }
    }
    
    opened by erikh 19
  • override id column

    override id column

    Is there a way to redeclare the id column as a custom string type?

    If I put the following in my schema:

    field.String("id").Unique()

    The generated code ends up broken because it creates two declarations of "id", but furthermore it ignores the fact that it's a string, and declares it as an integer instead.

    This might be related to the UUID discussions, but it would be great if we can define our own custom primary keys as strings that we provide at runtime.

    opened by marwan-at-work 19
  • proposal: custom column name for edges

    proposal: custom column name for edges

    Currently there's a way to customize the Table name. Can we do the same for column names (including edges)?

    Thanks

    opened by marwan-at-work 18
  • entgql: Noder doesn't support UUID Types

    entgql: Noder doesn't support UUID Types

    Super excited to see ent support gqlgen (although I understand it's still early on :))

    I was giving it a spin this evening and noticed when trying to create a model using uuid.UUID as the ID type, I got a bunch of type errors in some of the generated code.

    ent/node.go:51:3: cannot use c.ID (type uuid.UUID) as type int in field value
    ent/node.go:86:3: cannot use u.ID (type uuid.UUID) as type int in field value
    ent/node.go:190:21: cannot use id (type int) as type uuid.UUID in argument to testmodel1.ID
    ent/node.go:199:17: cannot use id (type int) as type uuid.UUID in argument to testmodel2.ID
    ent/pagination.go:450:18: cannot use c.ID (type uuid.UUID) as type int in field value
    ent/pagination.go:669:18: cannot use u.ID (type uuid.UUID) as type int in field value
    

    So I changed the generator based from the documentation to use a custom Field TypeInfo to TypeUUID

    // +build ignore
    
    package main
    
    import (
    	"log"
    
    	"github.com/facebook/ent/entc"
    	"github.com/facebook/ent/entc/gen"
    	"github.com/facebook/ent/schema/field"
    	"github.com/facebookincubator/ent-contrib/entgql"
    )
    
    func main() {
    	err := entc.Generate("./schema", &gen.Config{
    		Templates: entgql.AllTemplates,
    		IDType: &field.TypeInfo{
    			Type: field.TypeUUID,
    		},
    	})
    	if err != nil {
    		log.Fatalf("running ent codegen: %v", err)
    	}
    }
    

    Which got me a little bit further!

    ent/node.go:180:26: cannot use id (type [16]byte) as type string in argument to strconv.Atoi
    

    Looks like the culprit is located here. As the type of id argument in Noder is [16]byte, this wont work but I'm wondering if there's an easy way to set this as uuid.UUID and use a Stringer interface to call Atoi?

    Thanks!

    opened by tankbusta 18
  • Default json-Tag on Edges field

    Default json-Tag on Edges field

    • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

    Summary 💡

    Following #910 and the PR #1204 there are now default json tags on the edges struct. However a default json:"edges,omitempty" is still missing from the generated entity. I believe to have consistent behaviour this needs to be added.

    I removed the generated comments from the example to make it more clear.

    // Display is the model entity for the Display schema.
    type Display struct {
    	config `groups:"-" json:"-"`
    
    	ID string `json:"id,omitempty"` // <- tag is added by default
    
    	Edges          DisplayEdges  // <- I am missing a default tag for this field.
    	group_displays *int
    	group_media    *int
    }
    
    // DisplayEdges holds the relations/edges for other nodes in the graph.
    type DisplayEdges struct {
    
    	Group *Group `json:"group,omitempty"` // tag is added by default (since PR 1204)
    
    	loadedTypes [1]bool
    }
    

    Motivation 🔦

    Reduce boilerplate.

    opened by masseelch 15
  • proposal: Generated Data Loaders

    proposal: Generated Data Loaders

    It would be nice if ent would generate some sort of dataloaders / context-specific caching and batching layer like https://github.com/vektah/dataloaden. That would simplify using ent in GraphQL APIs a lot by removing the need to build an extra abstraction layer over "simple" database operations.

    opened by BitPhinix 13
  • Feature request: database schema in entity configs

    Feature request: database schema in entity configs

    Quite often, it becomes necessary to place different tables in different database schemas, not only in public. It would be nice to get support for this case from ent.

    It might look something like:

    func (User) Config() ent.Config {
        return ent.Config{
            Table:  "my_table",
            Schema: "my_schema",
        }
    }
    
    Proposal 
    opened by alexeyco 13
  • Allow a O2m Edge with Same type to have the same `To` and `From`

    Allow a O2m Edge with Same type to have the same `To` and `From`

    I am trying to implement a self referrential audit fk where the created_by columns refers to users.id

    type User struct {
    	ent.Schema
    }
    
    func (User) Fields() []ent.Field {
    	return []ent.Field{
    		field.String("username").Unique(),
    		field.Int("created_by_id").Optional(),
    		field.Int("updated_by_id").Optional(),
    	}
    }
    
    func (User) Edges() []ent.Edge {
    	return []ent.Edge{
    		edge.To("created_by", User.Type).From("created_by_owner").Unique().Field("created_by_id"),
    		edge.To("updated_by", User.Type).From("updated_by_owner").Unique().Field("updated_by_id"),
    	}
    }
    

    This works but has the unintended sideeffect of adding the *owner fields

    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Summary 💡

    func (User) Edges() []ent.Edge {
    	return []ent.Edge{
    		edge.To("created_by", User2.Type).From("created_by").Unique().Field("created_by_id"),
    		edge.To("updated_by", User2.Type).From("updated_by").Unique().Field("updated_by_id"),
    	}
    }
    

    Allow the user to set the to and from values to the same field.

    This should only be allowed in the o2o and o2m case.

    This currently fails because the fields are duplicated

    opened by cliedeman 0
  • Interactive CLI

    Interactive CLI

    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Summary 💡

    Extend the current entc tool to behave more like the symfony maker bundle. The make:entity is the command I am mostly interessed in. Having a cli-utility to help generating the schemas including all the edges will ease transition especially for new / less experienced users.

    Motivation 🔦

    See above.

    opened by masseelch 0
  • Default field annotation doesn't change existent column

    Default field annotation doesn't change existent column

    When I change ent field to have Default after the table was already created, the migration doesn't change the column with command like: ALTER TABLE users ALTER COLUMN name SET DEFAULT 'unknown';

    • [x] The issue is present in the latest release.
    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Current Behavior 😯

    1. Create Table User and run migration on database
    // Fields of the User.
    func (User) Fields() []ent.Field {
        return []ent.Field{
            field.String("name").
        }
    }
    
    1. Add default and run migration again
    // Fields of the User.
    func (User) Fields() []ent.Field {
        return []ent.Field{
            field.String("name").
                Default("unknown"),
        }
    }
    
    1. check database schema that name is "name" VARCHAR NOT NULL

    Expected Behavior 🤔

    • ALTER TABLE users ALTER COLUMN name SET DEFAULT 'unknown'; should be run on database following step 2
    • In database name should be "name" VARCHAR NOT NULL Default 'unknown'

    Your Environment 🌎

    | Tech | Version | | ----------- | ------- | | Go | 1.16 | | Ent | 0.8 | | Database | Postgres | | Driver | github.com/jackc/pgx/v4 |

    opened by naormatania 0
  • named xxxAPI table some end with ap_is and some end with apis

    named xxxAPI table some end with ap_is and some end with apis

    • [x] The issue is present in the latest release.
    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Current Behavior 😯

    i defined two table one is end with API then run migrate. it created two tables admin_sys_ap_is and admin_sys_permission_apis.

    // AdminSysAPI holds the schema definition for the AdminSysAPI entity.
    type AdminSysAPI struct {
    	ent.Schema
    }
    
    // Fields of the AdminSysAPI.
    func (AdminSysAPI) Fields() []ent.Field {
    	return []ent.Field{
    		field.UUID("id", uuid.UUID{}).
    			Default(uuid.New).Unique(),
    		field.String("url").Default(""),
    		field.Enum("method").Values(
    			http.MethodGet,
    			http.MethodHead,
    			http.MethodPut,
    			http.MethodPost,
    			http.MethodDelete).Default(http.MethodGet),
    		field.Text("comment").Default("").Optional().Nillable(), 
    	}
    }
    
    // Edges of the AdminSysAPI.
    func (AdminSysAPI) Edges() []ent.Edge {
    	return []ent.Edge{
    		edge.From("permissions", AdminSysPermission.Type).Ref("apis"),
    	}
    }
    
    
    
    // AdminSysPermission holds the schema definition for the AdminSysPermission entity.
    type AdminSysPermission struct {
    	ent.Schema
    }
    
    // Fields of the AdminSysPermission.
    func (AdminSysPermission) Fields() []ent.Field {
    	return []ent.Field{
    		field.UUID("id", uuid.UUID{}).
    			Default(uuid.New).Unique(),
    		field.String("title").Default(""),
    		field.String("name").Default("").Match(regexp.MustCompile(`^\w+$`)),
    		field.String("api_rule").Default(""),
    		field.Text("comment").Default("").Optional().Nillable(), 
    	}
    }
    
    // Edges of the AdminSysPermission.
    func (AdminSysPermission) Edges() []ent.Edge {
    	return []ent.Edge{
    		edge.To("apis", AdminSysAPI.Type),
    	}
    }
    

    Expected Behavior 🤔

    the correct name of admin_sys_ap_is should be ``admin_sys_apis`.

    Steps to Reproduce 🕹

    Steps:

    1. defined table
    2. run migrate
    3. check the database after migration.

    Your Environment 🌎

    | Tech | Version | | ----------- | ------- | | Go | 1.16.6 | | Ent | 0.8.0 | | Database | Mysql | | Driver | https://github.com/go-sql-driver/mysql |

    opened by godcong 2
  • Improved hook rejection error

    Improved hook rejection error

    Fix for #1750

    opened by cliedeman 2
  • Improve Rejection Error

    Improve Rejection Error

    client := ...
    client.Use(hook.Reject(ent.OpCreate | ent.OpUpdate | ent.OpUpdateOne | ent.OpDelete | ent.OpDeleteOne))
    client.Card.Create().SetNumber("1234").SaveX(ctx)
    // err: Op(31) operation is not allowed
    
    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Summary 💡

    The hook rejection error is hard to decipher. I expected the error to be

    Create operation is not allowed
    

    Motivation 🔦

    Trying to get better feedback for readonly driver

    opened by cliedeman 1
  • Add nillbale update to non-null fields Update

    Add nillbale update to non-null fields Update

    Hey 👋

    First, I would like to thank you for this awesome ORM.

    I suggest updating the Update API to allow Nullable update for non-null fields. Like the following:

    client.User.UpdateOneID(id).
      SetNillableName(name)
      SetName(name)
    
    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Summary 💡

    During Update, for example in GraphQL we usually update only some fields and others are Null pointer. This leads to a lot of code like this to update non-null fields:

    update := client.User.UpdateOneID(id).
    		SetNillableName(name)
    
    if input.Username != nil {
      update = update.SetUsername(*input.Username)
    }
    

    While we could just have a the following;

    client.User.UpdateOneID(id).
     SetNillableName(name).
     SetNillableUsername(username)
    

    Motivation 🔦

    This would improve the overall Update API and let users save time.

    Thank you :)

    opened by shellbear 3
  • Return selector's alias as a table name

    Return selector's alias as a table name

    In case selector's from clause has *Selector instead of *SelectTable, TableName() function (used for column checking) will panic.

    Instead, return selector's alias which is useful if the query returns a table with the same schema as some entity. Essentially, this allows materialized views to reuse the same entity code as long as columns are matching.

    opened by timoha 0
  • Creating an entity called

    Creating an entity called "sync" will cause a compilation error of the generated code

    • [x] The issue is present in the latest release.
    • [x] I have searched the issues of this repository and believe that this is not a duplicate.

    Current Behavior 😯

    When creating a sync entity like this:

    package schema
    
    import (
    	"entgo.io/ent"
    	"entgo.io/ent/schema/edge"
    	"entgo.io/ent/schema/field"
    )
    
    // Sync schema
    type Sync struct {
    	ent.Schema
    }
    
    // Fields of the Sync.
    func (s Sync) Fields() []ent.Field {
    	return []ent.Field{
    
    	}
    }
    
    // Edges of the Sync.
    func (Sync) Edges() []ent.Edge {
    	return []ent.Edge{
    
    	}
    }
    

    The generated code will not compile, instead gives the following error:

    # github.com/advanderveer/extron/model
    model/mutation.go:16:2: sync redeclared as imported package name
    	previous declaration at model/mutation.go:8:2
    ...
    

    Most probably because it collides with the stdlib "sync" package.

    Expected Behavior 🤔

    Expected it to compile, or be warned that some entity names are reserved.

    Steps to Reproduce 🕹

    Steps:

    1. Setup an entity
    2. Generate ent code
    3. Compile the binary

    Your Environment 🌎

    go.mod:

    module github.com/advanderveer/extron
    
    go 1.16
    
    require (
    	entgo.io/contrib v0.0.0-20210503071007-94b55dee6550
    	entgo.io/ent v0.8.0
    	github.com/jackc/pgx/v4 v4.12.0 // indirect
    	github.com/mattn/go-sqlite3 v1.14.6
    )
    
    opened by advanderveer 0
  • Hope to add the `paginate` method to quickly query paging data

    Hope to add the `paginate` method to quickly query paging data

    Hope to add the paginate method to quickly query paging data

    type Paginator struct {
      TotalItem int  `json:"total_item"`
      TotalPage int  `json:"total_page"`
      Page      int  `json:"page"`
      Items     []*T `json:"items"`
    }
    
    type Param struct{
      Size int
      Page int
    }
    
    func Paginate(context.Context,...*Param)(*Paginator,err)
    func PaginateX(context.Context,...*Param)*Paginator
    
    client.User.Query().Paginate(ctx,paginate.Size(10),paginate.Page(1))
    
    OR
    client.User.Query().PaginateX(ctx,paginate.Size(10),paginate.Page(1))
    
    opened by liuaiyuan 0
Releases(v0.8.0)
  • v0.8.0(Apr 14, 2021)

    This release contains several bug fixes, performance and runtime improvements, and multiple new features in ent/schema and ent-codegen.

    The next release (~1 month from now) is going to be focused on adding support for ent schema-versioning, and the initial support for the new SQL schema migration. Proposal issues/discussions are going to be posted next week.

    Users are welcome to join our Slack channel and subscribe to the Ent newsletter to get ~monthly updates on the new features, proposal discussions, and content we release.

    How to update

    go get -u entgo.io/[email protected]
    

    Summary

    entc/gen

    • Allow extending and injecting dependencies to the generated clients/builders. See example in Ent website.
    • Add Select option to <T>UpdateOne builders. See example in Ent website:
      pedro, err := client.Pet.
         UpdateOneID(id).
         SetAge(9).
         Select(pet.FieldName, pet.FieldAge).
         Save(ctx)
      
    • (perf) Filter duplicate identifiers when loading O2M/M2O and M2M edges.
    • Allow disabling the DISTINCT clause in queries (#1371).
    • Change custom ordering/grouping functions format - This change can affect users that use custom ent.Order functions, and will require them to modify the function signature from func (*sql.Selector, func() bool) to func (*sql.Selector).
    • Code generation API - Add global annotation option - See documentation.

    ent/schema

    • Major change: The codegen now uses the actual GoType defined in the schema in the generated builders/structs (see #1428). TL;DR - Using *T now means that you'll get *T as a field type (and not T). If you want to get T instead, define it in the GoType option instead, even if the sql.Scanner interface is implemented by the pointer (*T).
    • Add database cascading deletion support to edge annotations. See FK annotation.
    • Add support for custom DEFAULT clauses using entsql.Annotation:
      field.String("uuid").
         Annotation(entsql.Annotation{
             Default: "uuid_generate_v4()",
         })
      
    • Add annotation for configuring FK symbols (#1423).

    dialect/sql

    • Add basic predicates for comparing 2 columns.
    • Add on-conflict handling to sql builder (initial support for upsert).

    dialect/sql/schema

    • JSON column migration for MariaDB10.3.13 - Thanks @AnnatarHe for reporting this issue.
    • Initial support for Postgres arrays in migration.

    contrib

    • Support additional types in entproto.
    • Support ordering by ID fields in entgql.

    Thanks, @dilipkk-foyernet, @enjoylife, @rubensayshi, @bshihr, @rotemtam, @alexsn, @cliedeman, @chrisguox, @uta-mori, @Bladrak for contributing to the Ent project and participating in this release.

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Mar 11, 2021)

    This release contains 1 major feature, small improvements and bug fixes to ent codegen and its runtime, and an experimental integration with protobuf.

    Global

    • Add support for edge-fields/foreign-keys in the schema (#1213) - Thanks @alexsn, @rubensayshi, @marwan-at-work, @adayNU, @aight8 and @errorhandler for the feedback and helping designing this feature properly. Please read more about it here - Thanks @rotemtam for the blog-post 🙏 .
    • Small change to all codebase. Wrap errors (replace %v with %w) when it's useful - Thanks @mgabeler-lee-6rs

    Code Generation

    • The generated ent.IsConstraintError function catches now FK constraint violations (#1316) - Thanks @rotemtam
    • The edge.Annotation provides a way to override the struct-tag for the Edges field in generated models. #1315 changes the implementation to extend the struct-tag and override the default JSON tag only if it was provided by the annotation.

    Schema

    • Add support for DefaultFunc in user-defined PKs (#1290)
    • Add support for MySQL spatial types in migration and add example for it - a8m/entspatial

    Contrib

    • OSS entproto. An experimental package for generating .proto files from ent/schema.

    CLI

    • ent init now creates a `generate.go file that matches Go 1.16 (#1300) - Thanks @uta-mori

    Thanks @kercylan98, @HarikiRito, @SogoCZE, @wenj91 for reporting issues and being involved in the project.

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Feb 2, 2021)

    New import path 🎊

    Package path was changed from github.com/facebook/ent to entgo.io/ent. Please use the following command (on Mac) to replace imports:

    For github.com/facebookincubator/ent-contrib:

    find . -type f -name '*.go' -exec sed -i '' 's/github.com\/facebookincubator\/ent-contrib/entgo.io\/contrib/g' {} +
    

    For github.com/facebook/ent:

    find . -type f -name '*.go' -exec sed -i '' 's/github.com\/facebook/entgo.io/g' {} +
    

    schema/fields

    • Add DefaultFunc option for fields (#1153)

    entc/gen

    • Add support for alternate schema/database names (Thanks @marwan-at-work). Read more here

    • Add field.Comment support in generated assets (Thanks @kerbelp)

    • Breaking change: add the edge-name as the default json tag for edge fields (#1204):

      - Users []*User
      + Users []*User `json:"users,omitempty"`
      

    dialect/sql/schema

    dialect/sql/sqlgraph

    • Apply predicate on update-node

    Besides these, there are multiple bug fixes and small perf improvements in this release.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.4(Jan 6, 2021)

    Users that upgrade to this version and already use schema-hooks or the privacy policy in ent/schema, should follow the steps mentioned in https://github.com/facebook/ent/issues/1115#issuecomment-753944990.

    schema/field

    • Support for indexing ID fields (Thanks @napei)
    • Allow non incremental PKs (Thanks @saantiaguilera)
    • Add DefaultFunc option to string and bytes builders
    • Remove the deprecated ValueMap option for enum builder

    codegen

    • Allow field selection in query builder and eager-loading (#1077)

    dialect/sql/schema

    • Add migration support for JSON columns in old versions of MariaDB (=< 10.2)
    • Support for binary columns in MySQL (Thanks @nolotz)

    dialect/sql/sqlgraph

    • Small perf improvements
    • Allow arbitrary last insert id type (Thanks @cliedeman)

    dialect/sql

    • Add schema options for sql builders (Thanks @marwan-at-work)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.3(Dec 13, 2020)

  • v0.5.2(Dec 11, 2020)

    We release this version although it's quite small, in order to provide a stable version for supporting JSON fields migration in MariaDB.

    entql

    • Add support for driver.Valuer in typed predicates

    dialect/sql/schema

    • Support JSON fields migration for MariaDB

    Misc

    • Small changes and improvements for the runtime code
    Source code(tar.gz)
    Source code(zip)
  • v0.5.1(Nov 29, 2020)

    cmd/ent

    • Replace entc to ent - #989

    dialect/entsql

    • Add support for table options in ent/schema (#925)
    • Add Size annotation (#947)

    dialect/sql/sqlgraph

    • Improve perf for UpadteMany operations.

    dialect/sql/schema

    • Add support for PostgreSQL net types
    • Allow migrations from integer columns to string
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Nov 4, 2020)

    This version contains multiple bug fixes and perf improvements, but also includes a major feature which is the privacy support and additional small features for ent/schema and code-generation.

    schema

    dialect/sql/schema

    • Add the WithForeighKeys option to migrate
    • Properly handle indexes of tables with uncountable name (#828)
    • Apply size-check only if it is defined in schema (#855)

    dialect/sql/sqljson

    • Initial work for json_contains predicate

    dialect/sql

    • Add Left/Right join for the SQL builder

    entc/gen:

    • Add gen.Template for ent extensions
    • Rename generated FirstXID to FirstIDX
    • Add hook.FixedError helper

    entc/internal

    • Add feature-flag support for code-generation (allow opt-in to specific features)
    • Support schema versioning (#852)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.3(Sep 21, 2020)

    entc/gen (codegen)

    • Add an option for clearing non-unique edges.
    • Add validators on group-by and order-by arguments.
    • Add templates for supporting custom predicates in codegen (#758).
    • Improve API for custom templates (add an option for passing template.FuncMap for template execution).

    dialect/sql

    • Add an experiment package for supporting JSON predicates at runtime named sqljson. In the future, JSON predicates will be added to the generated predicates.

    schema migration

    • Change the WithFixture default value to be false. It's likely to be removed in the upcoming versions. Users that migrate from v0.0.1, directly to v0.4.3, should pass WithFixture(true) on migration.

    misc

    • Add the GraphQL integration to ent-contrib, and create a page for it in https://entgo.io/docs/graphql.
    Source code(tar.gz)
    Source code(zip)
  • v0.4.2(Aug 30, 2020)

    Small release with a few bug fixes and the following schema changes:

    ent/schema

    • Added support for setting default values for fields with a custom GoType.
    • The Enum.NamedValues method was added to replace Enum.ValueMap.
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Aug 18, 2020)

  • v0.3.0(Aug 5, 2020)

    This version includes multiple bug fixes, changes in ent/schema, the generated-code and the database migration.

    Schema changes

    • Add schema annotations support for fields and edges. This API allows to attach metadata to fields and edges and inject them to external templates. More info can be found in the docs.
    • Add GoType support for enum fields. This change makes it possible to share the same enum type between multiple schemas.
    • Add the Unique option to UUID fields.

    Codegen changes

    • Add an API for creating bulk of entities. More info can be found in the docs.
    • Add the fail function to template functions.
    • Import codegen out (makes goimports faster).

    Migration changes

    • Fix default value option to enum fields.
    • Change ent_types table id type to uint64 (from int).
    Source code(tar.gz)
    Source code(zip)
  • v0.2.7(Jul 16, 2020)

  • v0.2.6(Jul 12, 2020)

    Ent changes:

    • Add OldField to the ent.Mutation interface

    Schema changes:

    • Add the Unique option to UUID fields

    SQL runtime changes:

    • Minor bug fixes: #561, #587, etc
    • Initial work for batch inserts

    Codegen changes:

    • Official release for transaction hooks
    • Add singular finishers for querying primitives, e.g: .String(), .Int(), etc
    • Add condition helpers foe generated hooks
    • Add option to extend existing templates: #583
    Source code(tar.gz)
    Source code(zip)
  • v0.2.4(Jun 17, 2020)

  • v0.2.3(Jun 9, 2020)

    Schema changes

    2 options were added to the schema fields:

    • SchemaType - an option to override the default database-type used by ent. docs
    • GoType - an option to provide a custom Go type for fields. docs

    Codegen

    A few bug fixes and another option for getting the Mutation object of a builder. More info can be found in the PR.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Apr 20, 2020)

    Add Indexes/Edges/Hooks to ent.Mixin, and also rename schema/schemautil to schema/mixin.

    This means that if you upgrade to v0.2.0 and you used mixins before, you should do the following:

    • If you use one of the mixins in schemautil (like schemautil.TimeMixin), you should replace the import path to be ent/schema/mixin instead (and drop the Mixin suffix).
    • If you use your own mixin, you should embed mixin.Schema in your struct instead of implementing the rest of the methods.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Mar 22, 2020)

  • v0.1.2(Feb 14, 2020)

    integration: update mysql8 version and remove test container integration: add pg and mysql test for customids (#342) doc: fix a doc error (#339) entc/gen: currently handle user-defined string ids (#338) dialect/sql/mysql: fix verifyrange check for mysql (#337) entc/gen: better formatted codegen for predicates (#336) dialect/sql/schema: setrange on custom column name of pks (#333) entc/gen: fix eager-loading for m2m edges (#335) ci: upgrade to mysql latest in integration (#331) dialect/sql/schema: support mysql latest numeric type format (#328) entc/gen: allow defining custom tag for id field (#330) dialect/sql/schema: verify and fix mysql auto-increment on reset (#329)

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Feb 3, 2020)

    #286 addressed the issue that described in #285.

    Although, this PR was heavily tested internally before it was merged, we suggest that if you upgrade an older version of ent, run migration with offline mode before, to make sure it goes smoothly.

    Source code(tar.gz)
    Source code(zip)
Owner
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
Facebook
An entity framework for Go

ent - An Entity Framework For Go Simple, yet powerful entity framework for Go, that makes it easy to build and maintain applications with large data-m

Facebook 7.7k Jul 25, 2021
Generate a Go ORM tailored to your database schema.

SQLBoiler is a tool to generate a Go ORM tailored to your database schema. It is a "database-first" ORM as opposed to "code-first" (like gorm/gorp). T

Volatile Technologies Inc. 4.1k Jul 24, 2021