ent

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

ent - An Entity Framework For Go

Simple, yet powerful ORM for modeling and querying data.

  • Schema As Code - model any graph 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.

Quick Installation

go get github.com/facebookincubator/ent/cmd/entc

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

Docs

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

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.

Project Status

ent was developed and maintained by a8m and alexsn from the Facebook Connectivity team. It's currently considered experimental (although we're using it in production), and the roadmap for 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.

Documentation

Overview

Package ent is the interface between end-user schemas and entc (ent codegen).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// A Table is an optional table name defined for the schema.
	Table string
}

A Config structure is used to configure an entity schema. The usage of this structure is as follows:

func (T) Config() ent.Config {
	return ent.Config{
		Table: "Name",
	}
}

type Edge

type Edge interface {
	Descriptor() *edge.Descriptor
}

A Edge interface returns an edge descriptor for vertex edges. The usage for the interface is as follows:

func (T) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("S", S.Type),
	}
}

type Field

type Field interface {
	Descriptor() *field.Descriptor
}

A Field interface returns a field descriptor for vertex fields/properties. The usage for the interface is as follows:

func (T) Fields() []ent.Field {
	return []ent.Field{
		field.Int("int"),
	}
}

type Index

type Index interface {
	Descriptor() *index.Descriptor
}

A Index interface returns an index descriptor for vertex indexes. The usage for the interface is as follows:

func (T) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("f1", "f2").
			Unique(),
	}
}

type Interface

type Interface interface {
	// Type is a dummy method, that is used in edge declaration.
	//
	// The Type method should be used as follows:
	//
	//	type S struct { ent.Schema }
	//
	//	type T struct { ent.Schema }
	//
	//	func (T) Edges() []ent.Edge {
	//		return []ent.Edge{
	//			edge.To("S", S.Type),
	//		}
	//	}
	//
	Type()
	// Fields returns the fields of the schema.
	Fields() []Field
	// Edges returns the edges of the schema.
	Edges() []Edge
	// Indexes returns the indexes of the schema.
	Indexes() []Index
	// Config returns an optional config for the schema.
	Config() Config
	// Mixin returns an optional list of Mixin to extends
	// the schema.
	Mixin() []Mixin
}

The Interface type describes the requirements for an exported type defined in the schema package. It functions as the interface between the user's schema types and codegen loader. Users should use the Schema type for embedding as follows:

type T struct {
	ent.Schema
}

type Mixin

type Mixin interface {
	// Fields returns a slice of fields to be added
	// to the schema fields.
	Fields() []Field
}

The Mixin type describes a set of methods that can extend other methods in the schema without calling them directly.

type TimeMixin struct {}

func (TimeMixin) Fields() []ent.Field {
	return []ent.Field{
		field.Time("created_at").
			Immutable().
			Default(time.Now),
		field.Time("updated_at").
			Default(time.Now).
			UpdateDefault(time.Now),
	}
}

type T struct {
	ent.Schema
}

func(T) Mixin() []ent.Mixin {
	return []ent.Mixin{
		TimeMixin{},
	}
}

type Schema

type Schema struct {
	Interface
}

Schema is the default implementation for the schema Interface. It can be embedded in end-user schemas as follows:

type T struct {
	ent.Schema
}

func (Schema) Config

func (Schema) Config() Config

Config of the schema.

func (Schema) Edges

func (Schema) Edges() []Edge

Edges of the schema.

func (Schema) Fields

func (Schema) Fields() []Field

Fields of the schema.

func (Schema) Indexes

func (Schema) Indexes() []Index

Indexes of the schema.

func (Schema) Mixin

func (Schema) Mixin() []Mixin

Mixin of the schema.

Directories

Path Synopsis
cmd
gremlin/graph/dsl
Package dsl provide an API for writing gremlin dsl queries almost as-is in Go without using strings in the code.
Package dsl provide an API for writing gremlin dsl queries almost as-is in Go without using strings in the code.
sql
sql/schema
Package schema contains all schema migration logic for SQL dialects.
Package schema contains all schema migration logic for SQL dialects.
sql/sqlgraph
sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen.
sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen.
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable.
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable.
gen
Package gen is the interface for generating loaded schemas into a Go package.
Package gen is the interface for generating loaded schemas into a Go package.
gen/internal
Package internal Code generated by go-bindata.
Package internal Code generated by go-bindata.
load
Package load is the interface for loading schema package into a Go program.
Package load is the interface for loading schema package into a Go program.
load/internal
Package internal Code generated by go-bindata.
Package internal Code generated by go-bindata.
examples
schema
field/gen
gen is a codegen cmd for generating numeric build types from template.
gen is a codegen cmd for generating numeric build types from template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL