entc/gen: add edge-field api for schema and codegen (#1213)

This commit is contained in:
Ariel Mashraki
2021-03-07 22:51:17 +02:00
committed by GitHub
parent eeb5bc7141
commit c0fd7c1305
203 changed files with 13038 additions and 2736 deletions

View File

@@ -13,10 +13,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeStreets holds the string denoting the streets edge name in mutations.
EdgeStreets = "streets"
// Table holds the table name of the city in the database.
Table = "cities"
// StreetsTable is the table the holds the streets relation/edge.

View File

@@ -13,10 +13,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeCity holds the string denoting the city edge name in mutations.
EdgeCity = "city"
// Table holds the table name of the street in the database.
Table = "streets"
// CityTable is the table the holds the city relation/edge.
@@ -34,7 +32,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Street type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "streets"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"city_streets",
}

View File

@@ -155,6 +155,7 @@ func (sc *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.city_streets = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -11,7 +11,6 @@ const (
Label = "user"
// 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"
)

View File

@@ -13,10 +13,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeUsers holds the string denoting the users edge name in mutations.
EdgeUsers = "users"
// Table holds the table name of the group in the database.
Table = "groups"
// UsersTable is the table the holds the users relation/edge. The primary key declared below.

View File

@@ -15,10 +15,8 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeGroups holds the string denoting the groups edge name in mutations.
EdgeGroups = "groups"
// Table holds the table name of the user in the database.
Table = "users"
// GroupsTable is the table the holds the groups relation/edge. The primary key declared below.

View File

@@ -15,10 +15,8 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeFriends holds the string denoting the friends edge name in mutations.
EdgeFriends = "friends"
// Table holds the table name of the user in the database.
Table = "users"
// FriendsTable is the table the holds the friends relation/edge. The primary key declared below.

View File

@@ -15,12 +15,10 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeFollowers holds the string denoting the followers edge name in mutations.
EdgeFollowers = "followers"
// EdgeFollowing holds the string denoting the following edge name in mutations.
EdgeFollowing = "following"
// Table holds the table name of the user in the database.
Table = "users"
// FollowersTable is the table the holds the followers relation/edge. The primary key declared below.

View File

@@ -13,10 +13,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// Table holds the table name of the pet in the database.
Table = "pets"
// OwnerTable is the table the holds the owner relation/edge.
@@ -34,7 +32,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Pet type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "pets"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_pets",
}

View File

@@ -155,6 +155,7 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_pets = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -15,10 +15,8 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgePets holds the string denoting the pets edge name in mutations.
EdgePets = "pets"
// Table holds the table name of the user in the database.
Table = "users"
// PetsTable is the table the holds the pets relation/edge.

View File

@@ -13,12 +13,10 @@ const (
FieldID = "id"
// FieldValue holds the string denoting the value field in the database.
FieldValue = "value"
// EdgeParent holds the string denoting the parent edge name in mutations.
EdgeParent = "parent"
// EdgeChildren holds the string denoting the children edge name in mutations.
EdgeChildren = "children"
// Table holds the table name of the node in the database.
Table = "nodes"
// ParentTable is the table the holds the parent relation/edge.
@@ -37,7 +35,8 @@ var Columns = []string{
FieldValue,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Node type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "nodes"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"node_children",
}

View File

@@ -169,6 +169,7 @@ func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.node_children = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := nc.mutation.ChildrenIDs(); len(nodes) > 0 {

View File

@@ -15,10 +15,8 @@ const (
FieldExpired = "expired"
// FieldNumber holds the string denoting the number field in the database.
FieldNumber = "number"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// Table holds the table name of the card in the database.
Table = "cards"
// OwnerTable is the table the holds the owner relation/edge.
@@ -37,7 +35,8 @@ var Columns = []string{
FieldNumber,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Card type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "cards"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_card",
}

View File

@@ -168,6 +168,7 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_card = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -15,10 +15,8 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeCard holds the string denoting the card edge name in mutations.
EdgeCard = "card"
// Table holds the table name of the user in the database.
Table = "users"
// CardTable is the table the holds the card relation/edge.

View File

@@ -15,10 +15,8 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeSpouse holds the string denoting the spouse edge name in mutations.
EdgeSpouse = "spouse"
// Table holds the table name of the user in the database.
Table = "users"
// SpouseTable is the table the holds the spouse relation/edge.
@@ -34,7 +32,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the User type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_spouse",
}

View File

@@ -171,6 +171,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_spouse = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -13,12 +13,10 @@ const (
FieldID = "id"
// FieldValue holds the string denoting the value field in the database.
FieldValue = "value"
// EdgePrev holds the string denoting the prev edge name in mutations.
EdgePrev = "prev"
// EdgeNext holds the string denoting the next edge name in mutations.
EdgeNext = "next"
// Table holds the table name of the node in the database.
Table = "nodes"
// PrevTable is the table the holds the prev relation/edge.
@@ -37,7 +35,8 @@ var Columns = []string{
FieldValue,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Node type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "nodes"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"node_next",
}

View File

@@ -173,6 +173,7 @@ func (nc *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.node_next = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := nc.mutation.NextIDs(); len(nodes) > 0 {

View File

@@ -17,7 +17,6 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// Table holds the table name of the user in the database.
Table = "users"
)

View File

@@ -17,12 +17,10 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeTenant holds the string denoting the tenant edge name in mutations.
EdgeTenant = "tenant"
// EdgeUsers holds the string denoting the users edge name in mutations.
EdgeUsers = "users"
// Table holds the table name of the group in the database.
Table = "groups"
// TenantTable is the table the holds the tenant relation/edge.
@@ -45,7 +43,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Group type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "groups"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"group_tenant",
}

View File

@@ -183,6 +183,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.group_tenant = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := gc.mutation.UsersIDs(); len(nodes) > 0 {

View File

@@ -17,7 +17,6 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// Table holds the table name of the tenant in the database.
Table = "tenants"
)

View File

@@ -19,12 +19,10 @@ const (
FieldName = "name"
// FieldFoods holds the string denoting the foods field in the database.
FieldFoods = "foods"
// EdgeTenant holds the string denoting the tenant edge name in mutations.
EdgeTenant = "tenant"
// EdgeGroups holds the string denoting the groups edge name in mutations.
EdgeGroups = "groups"
// Table holds the table name of the user in the database.
Table = "users"
// TenantTable is the table the holds the tenant relation/edge.
@@ -48,7 +46,8 @@ var Columns = []string{
FieldFoods,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the User type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_tenant",
}

View File

@@ -197,6 +197,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_tenant = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := uc.mutation.GroupsIDs(); len(nodes) > 0 {

View File

@@ -15,10 +15,8 @@ const (
FieldModel = "model"
// FieldRegisteredAt holds the string denoting the registered_at field in the database.
FieldRegisteredAt = "registered_at"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// Table holds the table name of the car in the database.
Table = "cars"
// OwnerTable is the table the holds the owner relation/edge.
@@ -37,7 +35,8 @@ var Columns = []string{
FieldRegisteredAt,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Car type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "cars"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_cars",
}

View File

@@ -173,6 +173,7 @@ func (cc *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_cars = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -13,10 +13,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeUsers holds the string denoting the users edge name in mutations.
EdgeUsers = "users"
// Table holds the table name of the group in the database.
Table = "groups"
// UsersTable is the table the holds the users relation/edge. The primary key declared below.

View File

@@ -15,12 +15,10 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeCars holds the string denoting the cars edge name in mutations.
EdgeCars = "cars"
// EdgeGroups holds the string denoting the groups edge name in mutations.
EdgeGroups = "groups"
// Table holds the table name of the user in the database.
Table = "users"
// CarsTable is the table the holds the cars relation/edge.

View File

@@ -13,12 +13,10 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeUsers holds the string denoting the users edge name in mutations.
EdgeUsers = "users"
// EdgeAdmin holds the string denoting the admin edge name in mutations.
EdgeAdmin = "admin"
// Table holds the table name of the group in the database.
Table = "groups"
// UsersTable is the table the holds the users relation/edge. The primary key declared below.
@@ -41,7 +39,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Group type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "groups"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"group_admin",
}

View File

@@ -189,6 +189,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.group_admin = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -13,12 +13,10 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgeFriends holds the string denoting the friends edge name in mutations.
EdgeFriends = "friends"
// EdgeOwner holds the string denoting the owner edge name in mutations.
EdgeOwner = "owner"
// Table holds the table name of the pet in the database.
Table = "pets"
// FriendsTable is the table the holds the friends relation/edge. The primary key declared below.
@@ -38,7 +36,8 @@ var Columns = []string{
FieldName,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the Pet type.
// ForeignKeys holds the SQL foreign-keys that are owned by the "pets"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
"user_pets",
}

View File

@@ -189,6 +189,7 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) {
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.user_pets = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec

View File

@@ -15,7 +15,6 @@ const (
FieldAge = "age"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// EdgePets holds the string denoting the pets edge name in mutations.
EdgePets = "pets"
// EdgeFriends holds the string denoting the friends edge name in mutations.
@@ -24,7 +23,6 @@ const (
EdgeGroups = "groups"
// EdgeManage holds the string denoting the manage edge name in mutations.
EdgeManage = "manage"
// Table holds the table name of the user in the database.
Table = "users"
// PetsTable is the table the holds the pets relation/edge.