ka.graphql missing and mutations
This commit is contained in:
parent
bf20abdbaf
commit
18654f241a
785
ent.graphql
Normal file
785
ent.graphql
Normal file
@ -0,0 +1,785 @@
|
|||||||
|
directive @goField(forceResolver: Boolean, name: String, omittable: Boolean) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
|
||||||
|
directive @goModel(model: String, models: [String!], forceGenerate: Boolean) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION
|
||||||
|
type Category implements Node {
|
||||||
|
id: ID!
|
||||||
|
createdAt: Time!
|
||||||
|
updatedAt: Time
|
||||||
|
title: String!
|
||||||
|
description: String
|
||||||
|
posts(
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come after the specified cursor.
|
||||||
|
"""
|
||||||
|
after: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the first _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
first: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come before the specified cursor.
|
||||||
|
"""
|
||||||
|
before: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the last _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
last: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ordering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
orderBy: PostOrder
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
where: PostWhereInput
|
||||||
|
): PostConnection!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
A connection to a list of items.
|
||||||
|
"""
|
||||||
|
type CategoryConnection {
|
||||||
|
"""
|
||||||
|
A list of edges.
|
||||||
|
"""
|
||||||
|
edges: [CategoryEdge]
|
||||||
|
"""
|
||||||
|
Information to aid in pagination.
|
||||||
|
"""
|
||||||
|
pageInfo: PageInfo!
|
||||||
|
"""
|
||||||
|
Identifies the total count of items in the connection.
|
||||||
|
"""
|
||||||
|
totalCount: Int!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
An edge in a connection.
|
||||||
|
"""
|
||||||
|
type CategoryEdge {
|
||||||
|
"""
|
||||||
|
The item at the end of the edge.
|
||||||
|
"""
|
||||||
|
node: Category
|
||||||
|
"""
|
||||||
|
A cursor for use in pagination.
|
||||||
|
"""
|
||||||
|
cursor: Cursor!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Ordering options for Category connections
|
||||||
|
"""
|
||||||
|
input CategoryOrder {
|
||||||
|
"""
|
||||||
|
The ordering direction.
|
||||||
|
"""
|
||||||
|
direction: OrderDirection! = ASC
|
||||||
|
"""
|
||||||
|
The field by which to order Categories.
|
||||||
|
"""
|
||||||
|
field: CategoryOrderField!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Properties by which Category connections can be ordered.
|
||||||
|
"""
|
||||||
|
enum CategoryOrderField {
|
||||||
|
CREATED_AT
|
||||||
|
UPDATED_AT
|
||||||
|
POSTS_COUNT
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
CategoryWhereInput is used for filtering Category objects.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input CategoryWhereInput {
|
||||||
|
not: CategoryWhereInput
|
||||||
|
and: [CategoryWhereInput!]
|
||||||
|
or: [CategoryWhereInput!]
|
||||||
|
"""
|
||||||
|
id field predicates
|
||||||
|
"""
|
||||||
|
id: ID
|
||||||
|
idNEQ: ID
|
||||||
|
idIn: [ID!]
|
||||||
|
idNotIn: [ID!]
|
||||||
|
idGT: ID
|
||||||
|
idGTE: ID
|
||||||
|
idLT: ID
|
||||||
|
idLTE: ID
|
||||||
|
"""
|
||||||
|
created_at field predicates
|
||||||
|
"""
|
||||||
|
createdAt: Time
|
||||||
|
createdAtNEQ: Time
|
||||||
|
createdAtIn: [Time!]
|
||||||
|
createdAtNotIn: [Time!]
|
||||||
|
createdAtGT: Time
|
||||||
|
createdAtGTE: Time
|
||||||
|
createdAtLT: Time
|
||||||
|
createdAtLTE: Time
|
||||||
|
"""
|
||||||
|
updated_at field predicates
|
||||||
|
"""
|
||||||
|
updatedAt: Time
|
||||||
|
updatedAtNEQ: Time
|
||||||
|
updatedAtIn: [Time!]
|
||||||
|
updatedAtNotIn: [Time!]
|
||||||
|
updatedAtGT: Time
|
||||||
|
updatedAtGTE: Time
|
||||||
|
updatedAtLT: Time
|
||||||
|
updatedAtLTE: Time
|
||||||
|
updatedAtIsNil: Boolean
|
||||||
|
updatedAtNotNil: Boolean
|
||||||
|
"""
|
||||||
|
title field predicates
|
||||||
|
"""
|
||||||
|
title: String
|
||||||
|
titleNEQ: String
|
||||||
|
titleIn: [String!]
|
||||||
|
titleNotIn: [String!]
|
||||||
|
titleGT: String
|
||||||
|
titleGTE: String
|
||||||
|
titleLT: String
|
||||||
|
titleLTE: String
|
||||||
|
titleContains: String
|
||||||
|
titleHasPrefix: String
|
||||||
|
titleHasSuffix: String
|
||||||
|
titleEqualFold: String
|
||||||
|
titleContainsFold: String
|
||||||
|
"""
|
||||||
|
description field predicates
|
||||||
|
"""
|
||||||
|
description: String
|
||||||
|
descriptionNEQ: String
|
||||||
|
descriptionIn: [String!]
|
||||||
|
descriptionNotIn: [String!]
|
||||||
|
descriptionGT: String
|
||||||
|
descriptionGTE: String
|
||||||
|
descriptionLT: String
|
||||||
|
descriptionLTE: String
|
||||||
|
descriptionContains: String
|
||||||
|
descriptionHasPrefix: String
|
||||||
|
descriptionHasSuffix: String
|
||||||
|
descriptionIsNil: Boolean
|
||||||
|
descriptionNotNil: Boolean
|
||||||
|
descriptionEqualFold: String
|
||||||
|
descriptionContainsFold: String
|
||||||
|
"""
|
||||||
|
posts edge predicates
|
||||||
|
"""
|
||||||
|
hasPosts: Boolean
|
||||||
|
hasPostsWith: [PostWhereInput!]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
CreateCategoryInput is used for create Category object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input CreateCategoryInput {
|
||||||
|
createdAt: Time
|
||||||
|
updatedAt: Time
|
||||||
|
title: String!
|
||||||
|
description: String
|
||||||
|
postIDs: [ID!]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
CreatePostInput is used for create Post object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input CreatePostInput {
|
||||||
|
createdAt: Time
|
||||||
|
updatedAt: Time
|
||||||
|
expires: Boolean
|
||||||
|
expireTime: Time
|
||||||
|
title: String!
|
||||||
|
body: String!
|
||||||
|
categoryID: ID
|
||||||
|
profileID: ID
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
CreateProfileInput is used for create Profile object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input CreateProfileInput {
|
||||||
|
createdAt: Time
|
||||||
|
updatedAt: Time
|
||||||
|
name: String
|
||||||
|
address: String
|
||||||
|
phone: String
|
||||||
|
postIDs: [ID!]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Define a Relay Cursor type:
|
||||||
|
https://relay.dev/graphql/connections.htm#sec-Cursor
|
||||||
|
"""
|
||||||
|
scalar Cursor
|
||||||
|
"""
|
||||||
|
An object with an ID.
|
||||||
|
Follows the [Relay Global Object Identification Specification](https://relay.dev/graphql/objectidentification.htm)
|
||||||
|
"""
|
||||||
|
interface Node @goModel(model: "code.icod.de/dalu/ka/ent.Noder") {
|
||||||
|
"""
|
||||||
|
The id of the object.
|
||||||
|
"""
|
||||||
|
id: ID!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Possible directions in which to order a list of items when provided an `orderBy` argument.
|
||||||
|
"""
|
||||||
|
enum OrderDirection {
|
||||||
|
"""
|
||||||
|
Specifies an ascending order for a given `orderBy` argument.
|
||||||
|
"""
|
||||||
|
ASC
|
||||||
|
"""
|
||||||
|
Specifies a descending order for a given `orderBy` argument.
|
||||||
|
"""
|
||||||
|
DESC
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Information about pagination in a connection.
|
||||||
|
https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo
|
||||||
|
"""
|
||||||
|
type PageInfo {
|
||||||
|
"""
|
||||||
|
When paginating forwards, are there more items?
|
||||||
|
"""
|
||||||
|
hasNextPage: Boolean!
|
||||||
|
"""
|
||||||
|
When paginating backwards, are there more items?
|
||||||
|
"""
|
||||||
|
hasPreviousPage: Boolean!
|
||||||
|
"""
|
||||||
|
When paginating backwards, the cursor to continue.
|
||||||
|
"""
|
||||||
|
startCursor: Cursor
|
||||||
|
"""
|
||||||
|
When paginating forwards, the cursor to continue.
|
||||||
|
"""
|
||||||
|
endCursor: Cursor
|
||||||
|
}
|
||||||
|
type Post implements Node {
|
||||||
|
id: ID!
|
||||||
|
createdAt: Time!
|
||||||
|
updatedAt: Time
|
||||||
|
expires: Boolean!
|
||||||
|
expireTime: Time
|
||||||
|
title: String!
|
||||||
|
body: String!
|
||||||
|
category: Category
|
||||||
|
profile: Profile
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
A connection to a list of items.
|
||||||
|
"""
|
||||||
|
type PostConnection {
|
||||||
|
"""
|
||||||
|
A list of edges.
|
||||||
|
"""
|
||||||
|
edges: [PostEdge]
|
||||||
|
"""
|
||||||
|
Information to aid in pagination.
|
||||||
|
"""
|
||||||
|
pageInfo: PageInfo!
|
||||||
|
"""
|
||||||
|
Identifies the total count of items in the connection.
|
||||||
|
"""
|
||||||
|
totalCount: Int!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
An edge in a connection.
|
||||||
|
"""
|
||||||
|
type PostEdge {
|
||||||
|
"""
|
||||||
|
The item at the end of the edge.
|
||||||
|
"""
|
||||||
|
node: Post
|
||||||
|
"""
|
||||||
|
A cursor for use in pagination.
|
||||||
|
"""
|
||||||
|
cursor: Cursor!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Ordering options for Post connections
|
||||||
|
"""
|
||||||
|
input PostOrder {
|
||||||
|
"""
|
||||||
|
The ordering direction.
|
||||||
|
"""
|
||||||
|
direction: OrderDirection! = ASC
|
||||||
|
"""
|
||||||
|
The field by which to order Posts.
|
||||||
|
"""
|
||||||
|
field: PostOrderField!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Properties by which Post connections can be ordered.
|
||||||
|
"""
|
||||||
|
enum PostOrderField {
|
||||||
|
CREATED_AT
|
||||||
|
UPDATED_AT
|
||||||
|
EXPIRE_TIME
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
PostWhereInput is used for filtering Post objects.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input PostWhereInput {
|
||||||
|
not: PostWhereInput
|
||||||
|
and: [PostWhereInput!]
|
||||||
|
or: [PostWhereInput!]
|
||||||
|
"""
|
||||||
|
id field predicates
|
||||||
|
"""
|
||||||
|
id: ID
|
||||||
|
idNEQ: ID
|
||||||
|
idIn: [ID!]
|
||||||
|
idNotIn: [ID!]
|
||||||
|
idGT: ID
|
||||||
|
idGTE: ID
|
||||||
|
idLT: ID
|
||||||
|
idLTE: ID
|
||||||
|
"""
|
||||||
|
created_at field predicates
|
||||||
|
"""
|
||||||
|
createdAt: Time
|
||||||
|
createdAtNEQ: Time
|
||||||
|
createdAtIn: [Time!]
|
||||||
|
createdAtNotIn: [Time!]
|
||||||
|
createdAtGT: Time
|
||||||
|
createdAtGTE: Time
|
||||||
|
createdAtLT: Time
|
||||||
|
createdAtLTE: Time
|
||||||
|
"""
|
||||||
|
updated_at field predicates
|
||||||
|
"""
|
||||||
|
updatedAt: Time
|
||||||
|
updatedAtNEQ: Time
|
||||||
|
updatedAtIn: [Time!]
|
||||||
|
updatedAtNotIn: [Time!]
|
||||||
|
updatedAtGT: Time
|
||||||
|
updatedAtGTE: Time
|
||||||
|
updatedAtLT: Time
|
||||||
|
updatedAtLTE: Time
|
||||||
|
updatedAtIsNil: Boolean
|
||||||
|
updatedAtNotNil: Boolean
|
||||||
|
"""
|
||||||
|
expires field predicates
|
||||||
|
"""
|
||||||
|
expires: Boolean
|
||||||
|
expiresNEQ: Boolean
|
||||||
|
"""
|
||||||
|
expire_time field predicates
|
||||||
|
"""
|
||||||
|
expireTime: Time
|
||||||
|
expireTimeNEQ: Time
|
||||||
|
expireTimeIn: [Time!]
|
||||||
|
expireTimeNotIn: [Time!]
|
||||||
|
expireTimeGT: Time
|
||||||
|
expireTimeGTE: Time
|
||||||
|
expireTimeLT: Time
|
||||||
|
expireTimeLTE: Time
|
||||||
|
expireTimeIsNil: Boolean
|
||||||
|
expireTimeNotNil: Boolean
|
||||||
|
"""
|
||||||
|
title field predicates
|
||||||
|
"""
|
||||||
|
title: String
|
||||||
|
titleNEQ: String
|
||||||
|
titleIn: [String!]
|
||||||
|
titleNotIn: [String!]
|
||||||
|
titleGT: String
|
||||||
|
titleGTE: String
|
||||||
|
titleLT: String
|
||||||
|
titleLTE: String
|
||||||
|
titleContains: String
|
||||||
|
titleHasPrefix: String
|
||||||
|
titleHasSuffix: String
|
||||||
|
titleEqualFold: String
|
||||||
|
titleContainsFold: String
|
||||||
|
"""
|
||||||
|
body field predicates
|
||||||
|
"""
|
||||||
|
body: String
|
||||||
|
bodyNEQ: String
|
||||||
|
bodyIn: [String!]
|
||||||
|
bodyNotIn: [String!]
|
||||||
|
bodyGT: String
|
||||||
|
bodyGTE: String
|
||||||
|
bodyLT: String
|
||||||
|
bodyLTE: String
|
||||||
|
bodyContains: String
|
||||||
|
bodyHasPrefix: String
|
||||||
|
bodyHasSuffix: String
|
||||||
|
bodyEqualFold: String
|
||||||
|
bodyContainsFold: String
|
||||||
|
"""
|
||||||
|
category edge predicates
|
||||||
|
"""
|
||||||
|
hasCategory: Boolean
|
||||||
|
hasCategoryWith: [CategoryWhereInput!]
|
||||||
|
"""
|
||||||
|
profile edge predicates
|
||||||
|
"""
|
||||||
|
hasProfile: Boolean
|
||||||
|
hasProfileWith: [ProfileWhereInput!]
|
||||||
|
}
|
||||||
|
type Profile implements Node {
|
||||||
|
id: ID!
|
||||||
|
createdAt: Time!
|
||||||
|
updatedAt: Time
|
||||||
|
name: String
|
||||||
|
address: String
|
||||||
|
phone: String
|
||||||
|
posts(
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come after the specified cursor.
|
||||||
|
"""
|
||||||
|
after: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the first _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
first: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come before the specified cursor.
|
||||||
|
"""
|
||||||
|
before: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the last _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
last: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ordering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
orderBy: PostOrder
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
where: PostWhereInput
|
||||||
|
): PostConnection!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
A connection to a list of items.
|
||||||
|
"""
|
||||||
|
type ProfileConnection {
|
||||||
|
"""
|
||||||
|
A list of edges.
|
||||||
|
"""
|
||||||
|
edges: [ProfileEdge]
|
||||||
|
"""
|
||||||
|
Information to aid in pagination.
|
||||||
|
"""
|
||||||
|
pageInfo: PageInfo!
|
||||||
|
"""
|
||||||
|
Identifies the total count of items in the connection.
|
||||||
|
"""
|
||||||
|
totalCount: Int!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
An edge in a connection.
|
||||||
|
"""
|
||||||
|
type ProfileEdge {
|
||||||
|
"""
|
||||||
|
The item at the end of the edge.
|
||||||
|
"""
|
||||||
|
node: Profile
|
||||||
|
"""
|
||||||
|
A cursor for use in pagination.
|
||||||
|
"""
|
||||||
|
cursor: Cursor!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Ordering options for Profile connections
|
||||||
|
"""
|
||||||
|
input ProfileOrder {
|
||||||
|
"""
|
||||||
|
The ordering direction.
|
||||||
|
"""
|
||||||
|
direction: OrderDirection! = ASC
|
||||||
|
"""
|
||||||
|
The field by which to order Profiles.
|
||||||
|
"""
|
||||||
|
field: ProfileOrderField!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
Properties by which Profile connections can be ordered.
|
||||||
|
"""
|
||||||
|
enum ProfileOrderField {
|
||||||
|
CREATED_AT
|
||||||
|
UPDATED_AT
|
||||||
|
POSTS_COUNT
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
ProfileWhereInput is used for filtering Profile objects.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input ProfileWhereInput {
|
||||||
|
not: ProfileWhereInput
|
||||||
|
and: [ProfileWhereInput!]
|
||||||
|
or: [ProfileWhereInput!]
|
||||||
|
"""
|
||||||
|
id field predicates
|
||||||
|
"""
|
||||||
|
id: ID
|
||||||
|
idNEQ: ID
|
||||||
|
idIn: [ID!]
|
||||||
|
idNotIn: [ID!]
|
||||||
|
idGT: ID
|
||||||
|
idGTE: ID
|
||||||
|
idLT: ID
|
||||||
|
idLTE: ID
|
||||||
|
"""
|
||||||
|
created_at field predicates
|
||||||
|
"""
|
||||||
|
createdAt: Time
|
||||||
|
createdAtNEQ: Time
|
||||||
|
createdAtIn: [Time!]
|
||||||
|
createdAtNotIn: [Time!]
|
||||||
|
createdAtGT: Time
|
||||||
|
createdAtGTE: Time
|
||||||
|
createdAtLT: Time
|
||||||
|
createdAtLTE: Time
|
||||||
|
"""
|
||||||
|
updated_at field predicates
|
||||||
|
"""
|
||||||
|
updatedAt: Time
|
||||||
|
updatedAtNEQ: Time
|
||||||
|
updatedAtIn: [Time!]
|
||||||
|
updatedAtNotIn: [Time!]
|
||||||
|
updatedAtGT: Time
|
||||||
|
updatedAtGTE: Time
|
||||||
|
updatedAtLT: Time
|
||||||
|
updatedAtLTE: Time
|
||||||
|
updatedAtIsNil: Boolean
|
||||||
|
updatedAtNotNil: Boolean
|
||||||
|
"""
|
||||||
|
name field predicates
|
||||||
|
"""
|
||||||
|
name: String
|
||||||
|
nameNEQ: String
|
||||||
|
nameIn: [String!]
|
||||||
|
nameNotIn: [String!]
|
||||||
|
nameGT: String
|
||||||
|
nameGTE: String
|
||||||
|
nameLT: String
|
||||||
|
nameLTE: String
|
||||||
|
nameContains: String
|
||||||
|
nameHasPrefix: String
|
||||||
|
nameHasSuffix: String
|
||||||
|
nameIsNil: Boolean
|
||||||
|
nameNotNil: Boolean
|
||||||
|
nameEqualFold: String
|
||||||
|
nameContainsFold: String
|
||||||
|
"""
|
||||||
|
address field predicates
|
||||||
|
"""
|
||||||
|
address: String
|
||||||
|
addressNEQ: String
|
||||||
|
addressIn: [String!]
|
||||||
|
addressNotIn: [String!]
|
||||||
|
addressGT: String
|
||||||
|
addressGTE: String
|
||||||
|
addressLT: String
|
||||||
|
addressLTE: String
|
||||||
|
addressContains: String
|
||||||
|
addressHasPrefix: String
|
||||||
|
addressHasSuffix: String
|
||||||
|
addressIsNil: Boolean
|
||||||
|
addressNotNil: Boolean
|
||||||
|
addressEqualFold: String
|
||||||
|
addressContainsFold: String
|
||||||
|
"""
|
||||||
|
phone field predicates
|
||||||
|
"""
|
||||||
|
phone: String
|
||||||
|
phoneNEQ: String
|
||||||
|
phoneIn: [String!]
|
||||||
|
phoneNotIn: [String!]
|
||||||
|
phoneGT: String
|
||||||
|
phoneGTE: String
|
||||||
|
phoneLT: String
|
||||||
|
phoneLTE: String
|
||||||
|
phoneContains: String
|
||||||
|
phoneHasPrefix: String
|
||||||
|
phoneHasSuffix: String
|
||||||
|
phoneIsNil: Boolean
|
||||||
|
phoneNotNil: Boolean
|
||||||
|
phoneEqualFold: String
|
||||||
|
phoneContainsFold: String
|
||||||
|
"""
|
||||||
|
posts edge predicates
|
||||||
|
"""
|
||||||
|
hasPosts: Boolean
|
||||||
|
hasPostsWith: [PostWhereInput!]
|
||||||
|
}
|
||||||
|
type Query {
|
||||||
|
"""
|
||||||
|
Fetches an object given its ID.
|
||||||
|
"""
|
||||||
|
node(
|
||||||
|
"""
|
||||||
|
ID of the object.
|
||||||
|
"""
|
||||||
|
id: ID!
|
||||||
|
): Node
|
||||||
|
"""
|
||||||
|
Lookup nodes by a list of IDs.
|
||||||
|
"""
|
||||||
|
nodes(
|
||||||
|
"""
|
||||||
|
The list of node IDs.
|
||||||
|
"""
|
||||||
|
ids: [ID!]!
|
||||||
|
): [Node]!
|
||||||
|
categories(
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come after the specified cursor.
|
||||||
|
"""
|
||||||
|
after: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the first _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
first: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come before the specified cursor.
|
||||||
|
"""
|
||||||
|
before: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the last _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
last: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ordering options for Categories returned from the connection.
|
||||||
|
"""
|
||||||
|
orderBy: CategoryOrder
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtering options for Categories returned from the connection.
|
||||||
|
"""
|
||||||
|
where: CategoryWhereInput
|
||||||
|
): CategoryConnection!
|
||||||
|
posts(
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come after the specified cursor.
|
||||||
|
"""
|
||||||
|
after: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the first _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
first: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come before the specified cursor.
|
||||||
|
"""
|
||||||
|
before: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the last _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
last: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ordering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
orderBy: PostOrder
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtering options for Posts returned from the connection.
|
||||||
|
"""
|
||||||
|
where: PostWhereInput
|
||||||
|
): PostConnection!
|
||||||
|
profiles(
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come after the specified cursor.
|
||||||
|
"""
|
||||||
|
after: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the first _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
first: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the elements in the list that come before the specified cursor.
|
||||||
|
"""
|
||||||
|
before: Cursor
|
||||||
|
|
||||||
|
"""
|
||||||
|
Returns the last _n_ elements from the list.
|
||||||
|
"""
|
||||||
|
last: Int
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ordering options for Profiles returned from the connection.
|
||||||
|
"""
|
||||||
|
orderBy: ProfileOrder
|
||||||
|
|
||||||
|
"""
|
||||||
|
Filtering options for Profiles returned from the connection.
|
||||||
|
"""
|
||||||
|
where: ProfileWhereInput
|
||||||
|
): ProfileConnection!
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
The builtin Time type
|
||||||
|
"""
|
||||||
|
scalar Time
|
||||||
|
"""
|
||||||
|
UpdateCategoryInput is used for update Category object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input UpdateCategoryInput {
|
||||||
|
updatedAt: Time
|
||||||
|
clearUpdatedAt: Boolean
|
||||||
|
title: String
|
||||||
|
description: String
|
||||||
|
clearDescription: Boolean
|
||||||
|
addPostIDs: [ID!]
|
||||||
|
removePostIDs: [ID!]
|
||||||
|
clearPosts: Boolean
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
UpdatePostInput is used for update Post object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input UpdatePostInput {
|
||||||
|
updatedAt: Time
|
||||||
|
clearUpdatedAt: Boolean
|
||||||
|
expires: Boolean
|
||||||
|
expireTime: Time
|
||||||
|
clearExpireTime: Boolean
|
||||||
|
title: String
|
||||||
|
body: String
|
||||||
|
categoryID: ID
|
||||||
|
clearCategory: Boolean
|
||||||
|
profileID: ID
|
||||||
|
clearProfile: Boolean
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
UpdateProfileInput is used for update Profile object.
|
||||||
|
Input was generated by ent.
|
||||||
|
"""
|
||||||
|
input UpdateProfileInput {
|
||||||
|
updatedAt: Time
|
||||||
|
clearUpdatedAt: Boolean
|
||||||
|
name: String
|
||||||
|
clearName: Boolean
|
||||||
|
address: String
|
||||||
|
clearAddress: Boolean
|
||||||
|
phone: String
|
||||||
|
clearPhone: Boolean
|
||||||
|
addPostIDs: [ID!]
|
||||||
|
removePostIDs: [ID!]
|
||||||
|
clearPosts: Boolean
|
||||||
|
}
|
194
ent/category.go
Normal file
194
ent/category.go
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Category is the model entity for the Category schema.
|
||||||
|
type Category struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID uuid.UUID `json:"id,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// Title holds the value of the "title" field.
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
// Description holds the value of the "description" field.
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the CategoryQuery when eager-loading is set.
|
||||||
|
Edges CategoryEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type CategoryEdges struct {
|
||||||
|
// Posts holds the value of the posts edge.
|
||||||
|
Posts []*Post `json:"posts,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
// totalCount holds the count of the edges above.
|
||||||
|
totalCount [1]map[string]int
|
||||||
|
|
||||||
|
namedPosts map[string][]*Post
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostsOrErr returns the Posts value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e CategoryEdges) PostsOrErr() ([]*Post, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.Posts, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "posts"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Category) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case category.FieldTitle, category.FieldDescription:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case category.FieldCreatedAt, category.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
case category.FieldID:
|
||||||
|
values[i] = new(uuid.UUID)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Category fields.
|
||||||
|
func (c *Category) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case category.FieldID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
c.ID = *value
|
||||||
|
}
|
||||||
|
case category.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
c.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case category.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
c.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case category.FieldTitle:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
c.Title = value.String
|
||||||
|
}
|
||||||
|
case category.FieldDescription:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
c.Description = value.String
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
c.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Category.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (c *Category) Value(name string) (ent.Value, error) {
|
||||||
|
return c.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts queries the "posts" edge of the Category entity.
|
||||||
|
func (c *Category) QueryPosts() *PostQuery {
|
||||||
|
return NewCategoryClient(c.config).QueryPosts(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Category.
|
||||||
|
// Note that you need to call Category.Unwrap() before calling this method if this Category
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (c *Category) Update() *CategoryUpdateOne {
|
||||||
|
return NewCategoryClient(c.config).UpdateOne(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Category entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (c *Category) Unwrap() *Category {
|
||||||
|
_tx, ok := c.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Category is not a transactional entity")
|
||||||
|
}
|
||||||
|
c.config.driver = _tx.drv
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (c *Category) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Category(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(c.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("title=")
|
||||||
|
builder.WriteString(c.Title)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("description=")
|
||||||
|
builder.WriteString(c.Description)
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NamedPosts returns the Posts named value or an error if the edge was not
|
||||||
|
// loaded in eager-loading with this name.
|
||||||
|
func (c *Category) NamedPosts(name string) ([]*Post, error) {
|
||||||
|
if c.Edges.namedPosts == nil {
|
||||||
|
return nil, &NotLoadedError{edge: name}
|
||||||
|
}
|
||||||
|
nodes, ok := c.Edges.namedPosts[name]
|
||||||
|
if !ok {
|
||||||
|
return nil, &NotLoadedError{edge: name}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Category) appendNamedPosts(name string, edges ...*Post) {
|
||||||
|
if c.Edges.namedPosts == nil {
|
||||||
|
c.Edges.namedPosts = make(map[string][]*Post)
|
||||||
|
}
|
||||||
|
if len(edges) == 0 {
|
||||||
|
c.Edges.namedPosts[name] = []*Post{}
|
||||||
|
} else {
|
||||||
|
c.Edges.namedPosts[name] = append(c.Edges.namedPosts[name], edges...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Categories is a parsable slice of Category.
|
||||||
|
type Categories []*Category
|
118
ent/category/category.go
Normal file
118
ent/category/category.go
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package category
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the category type in the database.
|
||||||
|
Label = "category"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldTitle holds the string denoting the title field in the database.
|
||||||
|
FieldTitle = "title"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// EdgePosts holds the string denoting the posts edge name in mutations.
|
||||||
|
EdgePosts = "posts"
|
||||||
|
// Table holds the table name of the category in the database.
|
||||||
|
Table = "categories"
|
||||||
|
// PostsTable is the table that holds the posts relation/edge.
|
||||||
|
PostsTable = "posts"
|
||||||
|
// PostsInverseTable is the table name for the Post entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "post" package.
|
||||||
|
PostsInverseTable = "posts"
|
||||||
|
// PostsColumn is the table column denoting the posts relation/edge.
|
||||||
|
PostsColumn = "category_posts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for category fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldTitle,
|
||||||
|
FieldDescription,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
TitleValidator func(string) error
|
||||||
|
// DefaultID holds the default value on creation for the "id" field.
|
||||||
|
DefaultID func() uuid.UUID
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Category queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTitle orders the results by the title field.
|
||||||
|
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDescription orders the results by the description field.
|
||||||
|
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPostsCount orders the results by posts count.
|
||||||
|
func ByPostsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newPostsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPosts orders the results by posts terms.
|
||||||
|
func ByPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newPostsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newPostsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(PostsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn),
|
||||||
|
)
|
||||||
|
}
|
345
ent/category/where.go
Normal file
345
ent/category/where.go
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package category
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id uuid.UUID) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||||
|
func Title(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIsNil() predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIsNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotNil() predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEQ applies the EQ predicate on the "title" field.
|
||||||
|
func TitleEQ(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||||
|
func TitleNEQ(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleIn applies the In predicate on the "title" field.
|
||||||
|
func TitleIn(vs ...string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||||
|
func TitleNotIn(vs ...string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGT applies the GT predicate on the "title" field.
|
||||||
|
func TitleGT(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGTE applies the GTE predicate on the "title" field.
|
||||||
|
func TitleGTE(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLT applies the LT predicate on the "title" field.
|
||||||
|
func TitleLT(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLTE applies the LTE predicate on the "title" field.
|
||||||
|
func TitleLTE(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContains applies the Contains predicate on the "title" field.
|
||||||
|
func TitleContains(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldContains(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||||
|
func TitleHasPrefix(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldHasPrefix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||||
|
func TitleHasSuffix(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldHasSuffix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||||
|
func TitleEqualFold(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEqualFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||||
|
func TitleContainsFold(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldContainsFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNEQ(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotIn(FieldDescription, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldGTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLT(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldLTE(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldContains(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldHasPrefix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldHasSuffix(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||||
|
func DescriptionIsNil() predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldIsNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||||
|
func DescriptionNotNil() predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldNotNull(FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldEqualFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.Category {
|
||||||
|
return predicate.Category(sql.FieldContainsFold(FieldDescription, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPosts applies the HasEdge predicate on the "posts" edge.
|
||||||
|
func HasPosts() predicate.Category {
|
||||||
|
return predicate.Category(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates).
|
||||||
|
func HasPostsWith(preds ...predicate.Post) predicate.Category {
|
||||||
|
return predicate.Category(func(s *sql.Selector) {
|
||||||
|
step := newPostsStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Category) predicate.Category {
|
||||||
|
return predicate.Category(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Category) predicate.Category {
|
||||||
|
return predicate.Category(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Category) predicate.Category {
|
||||||
|
return predicate.Category(sql.NotPredicates(p))
|
||||||
|
}
|
316
ent/category_create.go
Normal file
316
ent/category_create.go
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CategoryCreate is the builder for creating a Category entity.
|
||||||
|
type CategoryCreate struct {
|
||||||
|
config
|
||||||
|
mutation *CategoryMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (cc *CategoryCreate) SetCreatedAt(t time.Time) *CategoryCreate {
|
||||||
|
cc.mutation.SetCreatedAt(t)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (cc *CategoryCreate) SetNillableCreatedAt(t *time.Time) *CategoryCreate {
|
||||||
|
if t != nil {
|
||||||
|
cc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (cc *CategoryCreate) SetUpdatedAt(t time.Time) *CategoryCreate {
|
||||||
|
cc.mutation.SetUpdatedAt(t)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (cc *CategoryCreate) SetNillableUpdatedAt(t *time.Time) *CategoryCreate {
|
||||||
|
if t != nil {
|
||||||
|
cc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (cc *CategoryCreate) SetTitle(s string) *CategoryCreate {
|
||||||
|
cc.mutation.SetTitle(s)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (cc *CategoryCreate) SetDescription(s string) *CategoryCreate {
|
||||||
|
cc.mutation.SetDescription(s)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (cc *CategoryCreate) SetNillableDescription(s *string) *CategoryCreate {
|
||||||
|
if s != nil {
|
||||||
|
cc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (cc *CategoryCreate) SetID(u uuid.UUID) *CategoryCreate {
|
||||||
|
cc.mutation.SetID(u)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableID sets the "id" field if the given value is not nil.
|
||||||
|
func (cc *CategoryCreate) SetNillableID(u *uuid.UUID) *CategoryCreate {
|
||||||
|
if u != nil {
|
||||||
|
cc.SetID(*u)
|
||||||
|
}
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (cc *CategoryCreate) AddPostIDs(ids ...uuid.UUID) *CategoryCreate {
|
||||||
|
cc.mutation.AddPostIDs(ids...)
|
||||||
|
return cc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (cc *CategoryCreate) AddPosts(p ...*Post) *CategoryCreate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return cc.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CategoryMutation object of the builder.
|
||||||
|
func (cc *CategoryCreate) Mutation() *CategoryMutation {
|
||||||
|
return cc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Category in the database.
|
||||||
|
func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) {
|
||||||
|
cc.defaults()
|
||||||
|
return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (cc *CategoryCreate) SaveX(ctx context.Context) *Category {
|
||||||
|
v, err := cc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (cc *CategoryCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := cc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cc *CategoryCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := cc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (cc *CategoryCreate) defaults() {
|
||||||
|
if _, ok := cc.mutation.CreatedAt(); !ok {
|
||||||
|
v := category.DefaultCreatedAt()
|
||||||
|
cc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := cc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := category.DefaultUpdatedAt()
|
||||||
|
cc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := cc.mutation.ID(); !ok {
|
||||||
|
v := category.DefaultID()
|
||||||
|
cc.mutation.SetID(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (cc *CategoryCreate) check() error {
|
||||||
|
if _, ok := cc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Category.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := cc.mutation.Title(); !ok {
|
||||||
|
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Category.title"`)}
|
||||||
|
}
|
||||||
|
if v, ok := cc.mutation.Title(); ok {
|
||||||
|
if err := category.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *CategoryCreate) sqlSave(ctx context.Context) (*Category, error) {
|
||||||
|
if err := cc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := cc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != nil {
|
||||||
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||||
|
_node.ID = *id
|
||||||
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cc.mutation.id = &_node.ID
|
||||||
|
cc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Category{config: cc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID))
|
||||||
|
)
|
||||||
|
if id, ok := cc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = &id
|
||||||
|
}
|
||||||
|
if value, ok := cc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(category.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := cc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(category.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := cc.mutation.Title(); ok {
|
||||||
|
_spec.SetField(category.FieldTitle, field.TypeString, value)
|
||||||
|
_node.Title = value
|
||||||
|
}
|
||||||
|
if value, ok := cc.mutation.Description(); ok {
|
||||||
|
_spec.SetField(category.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = value
|
||||||
|
}
|
||||||
|
if nodes := cc.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryCreateBulk is the builder for creating many Category entities in bulk.
|
||||||
|
type CategoryCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*CategoryCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Category entities in the database.
|
||||||
|
func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) {
|
||||||
|
if ccb.err != nil {
|
||||||
|
return nil, ccb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
|
||||||
|
nodes := make([]*Category, len(ccb.builders))
|
||||||
|
mutators := make([]Mutator, len(ccb.builders))
|
||||||
|
for i := range ccb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := ccb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*CategoryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (ccb *CategoryCreateBulk) SaveX(ctx context.Context) []*Category {
|
||||||
|
v, err := ccb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ccb *CategoryCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := ccb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ccb *CategoryCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := ccb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/category_delete.go
Normal file
88
ent/category_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CategoryDelete is the builder for deleting a Category entity.
|
||||||
|
type CategoryDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CategoryDelete builder.
|
||||||
|
func (cd *CategoryDelete) Where(ps ...predicate.Category) *CategoryDelete {
|
||||||
|
cd.mutation.Where(ps...)
|
||||||
|
return cd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (cd *CategoryDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cd *CategoryDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := cd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cd *CategoryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID))
|
||||||
|
if ps := cd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, cd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
cd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryDeleteOne is the builder for deleting a single Category entity.
|
||||||
|
type CategoryDeleteOne struct {
|
||||||
|
cd *CategoryDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CategoryDelete builder.
|
||||||
|
func (cdo *CategoryDeleteOne) Where(ps ...predicate.Category) *CategoryDeleteOne {
|
||||||
|
cdo.cd.mutation.Where(ps...)
|
||||||
|
return cdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (cdo *CategoryDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := cdo.cd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{category.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cdo *CategoryDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := cdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
643
ent/category_query.go
Normal file
643
ent/category_query.go
Normal file
@ -0,0 +1,643 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CategoryQuery is the builder for querying Category entities.
|
||||||
|
type CategoryQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []category.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Category
|
||||||
|
withPosts *PostQuery
|
||||||
|
modifiers []func(*sql.Selector)
|
||||||
|
loadTotal []func(context.Context, []*Category) error
|
||||||
|
withNamedPosts map[string]*PostQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the CategoryQuery builder.
|
||||||
|
func (cq *CategoryQuery) Where(ps ...predicate.Category) *CategoryQuery {
|
||||||
|
cq.predicates = append(cq.predicates, ps...)
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (cq *CategoryQuery) Limit(limit int) *CategoryQuery {
|
||||||
|
cq.ctx.Limit = &limit
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (cq *CategoryQuery) Offset(offset int) *CategoryQuery {
|
||||||
|
cq.ctx.Offset = &offset
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (cq *CategoryQuery) Unique(unique bool) *CategoryQuery {
|
||||||
|
cq.ctx.Unique = &unique
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (cq *CategoryQuery) Order(o ...category.OrderOption) *CategoryQuery {
|
||||||
|
cq.order = append(cq.order, o...)
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts chains the current query on the "posts" edge.
|
||||||
|
func (cq *CategoryQuery) QueryPosts() *PostQuery {
|
||||||
|
query := (&PostClient{config: cq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := cq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := cq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(category.Table, category.FieldID, selector),
|
||||||
|
sqlgraph.To(post.Table, post.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, category.PostsTable, category.PostsColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Category entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Category was found.
|
||||||
|
func (cq *CategoryQuery) First(ctx context.Context) (*Category, error) {
|
||||||
|
nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{category.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) FirstX(ctx context.Context) *Category {
|
||||||
|
node, err := cq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Category ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Category ID was found.
|
||||||
|
func (cq *CategoryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{category.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := cq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Category entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Category entity is found.
|
||||||
|
// Returns a *NotFoundError when no Category entities are found.
|
||||||
|
func (cq *CategoryQuery) Only(ctx context.Context) (*Category, error) {
|
||||||
|
nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{category.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{category.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) OnlyX(ctx context.Context) *Category {
|
||||||
|
node, err := cq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Category ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Category ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (cq *CategoryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{category.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{category.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := cq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Categories.
|
||||||
|
func (cq *CategoryQuery) All(ctx context.Context) ([]*Category, error) {
|
||||||
|
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryAll)
|
||||||
|
if err := cq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Category, *CategoryQuery]()
|
||||||
|
return withInterceptors[[]*Category](ctx, cq, qr, cq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) AllX(ctx context.Context) []*Category {
|
||||||
|
nodes, err := cq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Category IDs.
|
||||||
|
func (cq *CategoryQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||||
|
if cq.ctx.Unique == nil && cq.path != nil {
|
||||||
|
cq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryIDs)
|
||||||
|
if err = cq.Select(category.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||||
|
ids, err := cq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (cq *CategoryQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryCount)
|
||||||
|
if err := cq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, cq, querierCount[*CategoryQuery](), cq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := cq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (cq *CategoryQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := cq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (cq *CategoryQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := cq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the CategoryQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (cq *CategoryQuery) Clone() *CategoryQuery {
|
||||||
|
if cq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &CategoryQuery{
|
||||||
|
config: cq.config,
|
||||||
|
ctx: cq.ctx.Clone(),
|
||||||
|
order: append([]category.OrderOption{}, cq.order...),
|
||||||
|
inters: append([]Interceptor{}, cq.inters...),
|
||||||
|
predicates: append([]predicate.Category{}, cq.predicates...),
|
||||||
|
withPosts: cq.withPosts.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: cq.sql.Clone(),
|
||||||
|
path: cq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPosts tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "posts" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (cq *CategoryQuery) WithPosts(opts ...func(*PostQuery)) *CategoryQuery {
|
||||||
|
query := (&PostClient{config: cq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
cq.withPosts = query
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Category.Query().
|
||||||
|
// GroupBy(category.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (cq *CategoryQuery) GroupBy(field string, fields ...string) *CategoryGroupBy {
|
||||||
|
cq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &CategoryGroupBy{build: cq}
|
||||||
|
grbuild.flds = &cq.ctx.Fields
|
||||||
|
grbuild.label = category.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Category.Query().
|
||||||
|
// Select(category.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (cq *CategoryQuery) Select(fields ...string) *CategorySelect {
|
||||||
|
cq.ctx.Fields = append(cq.ctx.Fields, fields...)
|
||||||
|
sbuild := &CategorySelect{CategoryQuery: cq}
|
||||||
|
sbuild.label = category.Label
|
||||||
|
sbuild.flds, sbuild.scan = &cq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a CategorySelect configured with the given aggregations.
|
||||||
|
func (cq *CategoryQuery) Aggregate(fns ...AggregateFunc) *CategorySelect {
|
||||||
|
return cq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range cq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, cq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range cq.ctx.Fields {
|
||||||
|
if !category.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cq.path != nil {
|
||||||
|
prev, err := cq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Category, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Category{}
|
||||||
|
_spec = cq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
cq.withPosts != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Category).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Category{config: cq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if len(cq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = cq.modifiers
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := cq.withPosts; query != nil {
|
||||||
|
if err := cq.loadPosts(ctx, query, nodes,
|
||||||
|
func(n *Category) { n.Edges.Posts = []*Post{} },
|
||||||
|
func(n *Category, e *Post) { n.Edges.Posts = append(n.Edges.Posts, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for name, query := range cq.withNamedPosts {
|
||||||
|
if err := cq.loadPosts(ctx, query, nodes,
|
||||||
|
func(n *Category) { n.appendNamedPosts(name) },
|
||||||
|
func(n *Category, e *Post) { n.appendNamedPosts(name, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range cq.loadTotal {
|
||||||
|
if err := cq.loadTotal[i](ctx, nodes); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) loadPosts(ctx context.Context, query *PostQuery, nodes []*Category, init func(*Category), assign func(*Category, *Post)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID]*Category)
|
||||||
|
for i := range nodes {
|
||||||
|
fks = append(fks, nodes[i].ID)
|
||||||
|
nodeids[nodes[i].ID] = nodes[i]
|
||||||
|
if init != nil {
|
||||||
|
init(nodes[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.withFKs = true
|
||||||
|
query.Where(predicate.Post(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(category.PostsColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.category_posts
|
||||||
|
if fk == nil {
|
||||||
|
return fmt.Errorf(`foreign-key "category_posts" is nil for node %v`, n.ID)
|
||||||
|
}
|
||||||
|
node, ok := nodeids[*fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "category_posts" returned %v for node %v`, *fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := cq.querySpec()
|
||||||
|
if len(cq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = cq.modifiers
|
||||||
|
}
|
||||||
|
_spec.Node.Columns = cq.ctx.Fields
|
||||||
|
if len(cq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = cq.ctx.Unique != nil && *cq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, cq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID))
|
||||||
|
_spec.From = cq.sql
|
||||||
|
if unique := cq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if cq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := cq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, category.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != category.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := cq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := cq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := cq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := cq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cq *CategoryQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(cq.driver.Dialect())
|
||||||
|
t1 := builder.Table(category.Table)
|
||||||
|
columns := cq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = category.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if cq.sql != nil {
|
||||||
|
selector = cq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if cq.ctx.Unique != nil && *cq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range cq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range cq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := cq.ctx.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.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := cq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithNamedPosts tells the query-builder to eager-load the nodes that are connected to the "posts"
|
||||||
|
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (cq *CategoryQuery) WithNamedPosts(name string, opts ...func(*PostQuery)) *CategoryQuery {
|
||||||
|
query := (&PostClient{config: cq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
if cq.withNamedPosts == nil {
|
||||||
|
cq.withNamedPosts = make(map[string]*PostQuery)
|
||||||
|
}
|
||||||
|
cq.withNamedPosts[name] = query
|
||||||
|
return cq
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryGroupBy is the group-by builder for Category entities.
|
||||||
|
type CategoryGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *CategoryQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (cgb *CategoryGroupBy) Aggregate(fns ...AggregateFunc) *CategoryGroupBy {
|
||||||
|
cgb.fns = append(cgb.fns, fns...)
|
||||||
|
return cgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (cgb *CategoryGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, cgb.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := cgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*CategoryQuery, *CategoryGroupBy](ctx, cgb.build, cgb, cgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cgb *CategoryGroupBy) sqlScan(ctx context.Context, root *CategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(cgb.fns))
|
||||||
|
for _, fn := range cgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*cgb.flds)+len(cgb.fns))
|
||||||
|
for _, f := range *cgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*cgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := cgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategorySelect is the builder for selecting fields of Category entities.
|
||||||
|
type CategorySelect struct {
|
||||||
|
*CategoryQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (cs *CategorySelect) Aggregate(fns ...AggregateFunc) *CategorySelect {
|
||||||
|
cs.fns = append(cs.fns, fns...)
|
||||||
|
return cs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (cs *CategorySelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, cs.ctx, ent.OpQuerySelect)
|
||||||
|
if err := cs.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*CategoryQuery, *CategorySelect](ctx, cs.CategoryQuery, cs, cs.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *CategorySelect) sqlScan(ctx context.Context, root *CategoryQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(cs.fns))
|
||||||
|
for _, fn := range cs.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*cs.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := cs.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
506
ent/category_update.go
Normal file
506
ent/category_update.go
Normal file
@ -0,0 +1,506 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CategoryUpdate is the builder for updating Category entities.
|
||||||
|
type CategoryUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CategoryUpdate builder.
|
||||||
|
func (cu *CategoryUpdate) Where(ps ...predicate.Category) *CategoryUpdate {
|
||||||
|
cu.mutation.Where(ps...)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (cu *CategoryUpdate) SetUpdatedAt(t time.Time) *CategoryUpdate {
|
||||||
|
cu.mutation.SetUpdatedAt(t)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (cu *CategoryUpdate) ClearUpdatedAt() *CategoryUpdate {
|
||||||
|
cu.mutation.ClearUpdatedAt()
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (cu *CategoryUpdate) SetTitle(s string) *CategoryUpdate {
|
||||||
|
cu.mutation.SetTitle(s)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (cu *CategoryUpdate) SetNillableTitle(s *string) *CategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
cu.SetTitle(*s)
|
||||||
|
}
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (cu *CategoryUpdate) SetDescription(s string) *CategoryUpdate {
|
||||||
|
cu.mutation.SetDescription(s)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (cu *CategoryUpdate) SetNillableDescription(s *string) *CategoryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
cu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (cu *CategoryUpdate) ClearDescription() *CategoryUpdate {
|
||||||
|
cu.mutation.ClearDescription()
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (cu *CategoryUpdate) AddPostIDs(ids ...uuid.UUID) *CategoryUpdate {
|
||||||
|
cu.mutation.AddPostIDs(ids...)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (cu *CategoryUpdate) AddPosts(p ...*Post) *CategoryUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return cu.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CategoryMutation object of the builder.
|
||||||
|
func (cu *CategoryUpdate) Mutation() *CategoryMutation {
|
||||||
|
return cu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPosts clears all "posts" edges to the Post entity.
|
||||||
|
func (cu *CategoryUpdate) ClearPosts() *CategoryUpdate {
|
||||||
|
cu.mutation.ClearPosts()
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePostIDs removes the "posts" edge to Post entities by IDs.
|
||||||
|
func (cu *CategoryUpdate) RemovePostIDs(ids ...uuid.UUID) *CategoryUpdate {
|
||||||
|
cu.mutation.RemovePostIDs(ids...)
|
||||||
|
return cu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePosts removes "posts" edges to Post entities.
|
||||||
|
func (cu *CategoryUpdate) RemovePosts(p ...*Post) *CategoryUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return cu.RemovePostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (cu *CategoryUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
cu.defaults()
|
||||||
|
return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (cu *CategoryUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := cu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (cu *CategoryUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := cu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cu *CategoryUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := cu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (cu *CategoryUpdate) defaults() {
|
||||||
|
if _, ok := cu.mutation.UpdatedAt(); !ok && !cu.mutation.UpdatedAtCleared() {
|
||||||
|
v := category.UpdateDefaultUpdatedAt()
|
||||||
|
cu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (cu *CategoryUpdate) check() error {
|
||||||
|
if v, ok := cu.mutation.Title(); ok {
|
||||||
|
if err := category.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cu *CategoryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := cu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID))
|
||||||
|
if ps := cu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := cu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(category.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if cu.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(category.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := cu.mutation.Title(); ok {
|
||||||
|
_spec.SetField(category.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := cu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(category.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if cu.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(category.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if cu.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := cu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !cu.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := cu.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{category.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
cu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryUpdateOne is the builder for updating a single Category entity.
|
||||||
|
type CategoryUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *CategoryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (cuo *CategoryUpdateOne) SetUpdatedAt(t time.Time) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.SetUpdatedAt(t)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (cuo *CategoryUpdateOne) ClearUpdatedAt() *CategoryUpdateOne {
|
||||||
|
cuo.mutation.ClearUpdatedAt()
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (cuo *CategoryUpdateOne) SetTitle(s string) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.SetTitle(s)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (cuo *CategoryUpdateOne) SetNillableTitle(s *string) *CategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
cuo.SetTitle(*s)
|
||||||
|
}
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (cuo *CategoryUpdateOne) SetDescription(s string) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.SetDescription(s)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (cuo *CategoryUpdateOne) SetNillableDescription(s *string) *CategoryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
cuo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (cuo *CategoryUpdateOne) ClearDescription() *CategoryUpdateOne {
|
||||||
|
cuo.mutation.ClearDescription()
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (cuo *CategoryUpdateOne) AddPostIDs(ids ...uuid.UUID) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.AddPostIDs(ids...)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (cuo *CategoryUpdateOne) AddPosts(p ...*Post) *CategoryUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return cuo.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the CategoryMutation object of the builder.
|
||||||
|
func (cuo *CategoryUpdateOne) Mutation() *CategoryMutation {
|
||||||
|
return cuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPosts clears all "posts" edges to the Post entity.
|
||||||
|
func (cuo *CategoryUpdateOne) ClearPosts() *CategoryUpdateOne {
|
||||||
|
cuo.mutation.ClearPosts()
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePostIDs removes the "posts" edge to Post entities by IDs.
|
||||||
|
func (cuo *CategoryUpdateOne) RemovePostIDs(ids ...uuid.UUID) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.RemovePostIDs(ids...)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePosts removes "posts" edges to Post entities.
|
||||||
|
func (cuo *CategoryUpdateOne) RemovePosts(p ...*Post) *CategoryUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return cuo.RemovePostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the CategoryUpdate builder.
|
||||||
|
func (cuo *CategoryUpdateOne) Where(ps ...predicate.Category) *CategoryUpdateOne {
|
||||||
|
cuo.mutation.Where(ps...)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (cuo *CategoryUpdateOne) Select(field string, fields ...string) *CategoryUpdateOne {
|
||||||
|
cuo.fields = append([]string{field}, fields...)
|
||||||
|
return cuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Category entity.
|
||||||
|
func (cuo *CategoryUpdateOne) Save(ctx context.Context) (*Category, error) {
|
||||||
|
cuo.defaults()
|
||||||
|
return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (cuo *CategoryUpdateOne) SaveX(ctx context.Context) *Category {
|
||||||
|
node, err := cuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (cuo *CategoryUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := cuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (cuo *CategoryUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := cuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (cuo *CategoryUpdateOne) defaults() {
|
||||||
|
if _, ok := cuo.mutation.UpdatedAt(); !ok && !cuo.mutation.UpdatedAtCleared() {
|
||||||
|
v := category.UpdateDefaultUpdatedAt()
|
||||||
|
cuo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (cuo *CategoryUpdateOne) check() error {
|
||||||
|
if v, ok := cuo.mutation.Title(); ok {
|
||||||
|
if err := category.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Category.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cuo *CategoryUpdateOne) sqlSave(ctx context.Context) (_node *Category, err error) {
|
||||||
|
if err := cuo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(category.Table, category.Columns, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID))
|
||||||
|
id, ok := cuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Category.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := cuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, category.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !category.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != category.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := cuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := cuo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(category.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if cuo.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(category.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := cuo.mutation.Title(); ok {
|
||||||
|
_spec.SetField(category.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := cuo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(category.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if cuo.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(category.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if cuo.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := cuo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !cuo.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := cuo.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Category{config: cuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{category.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cuo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
692
ent/client.go
Normal file
692
ent/client.go
Normal file
@ -0,0 +1,692 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/migrate"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// Category is the client for interacting with the Category builders.
|
||||||
|
Category *CategoryClient
|
||||||
|
// Post is the client for interacting with the Post builders.
|
||||||
|
Post *PostClient
|
||||||
|
// Profile is the client for interacting with the Profile builders.
|
||||||
|
Profile *ProfileClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
client := &Client{config: newConfig(opts...)}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.Category = NewCategoryClient(c.config)
|
||||||
|
c.Post = NewPostClient(c.config)
|
||||||
|
c.Profile = NewProfileClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// config is the configuration for the client and its builder.
|
||||||
|
config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...any)
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
// interceptors to execute on queries.
|
||||||
|
inters *inters
|
||||||
|
}
|
||||||
|
// Option function to configure the client.
|
||||||
|
Option func(*config)
|
||||||
|
)
|
||||||
|
|
||||||
|
// newConfig creates a new config for the client.
|
||||||
|
func newConfig(opts ...Option) config {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...any)) 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||||
|
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, ErrTxStarted
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Category: NewCategoryClient(cfg),
|
||||||
|
Post: NewPostClient(cfg),
|
||||||
|
Profile: NewProfileClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Category: NewCategoryClient(cfg),
|
||||||
|
Post: NewPostClient(cfg),
|
||||||
|
Profile: NewProfileClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// Category.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds the mutation hooks to all the entity clients.
|
||||||
|
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||||
|
func (c *Client) Use(hooks ...Hook) {
|
||||||
|
c.Category.Use(hooks...)
|
||||||
|
c.Post.Use(hooks...)
|
||||||
|
c.Profile.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds the query interceptors to all the entity clients.
|
||||||
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||||
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.Category.Intercept(interceptors...)
|
||||||
|
c.Post.Intercept(interceptors...)
|
||||||
|
c.Profile.Intercept(interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate implements the ent.Mutator interface.
|
||||||
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *CategoryMutation:
|
||||||
|
return c.Category.mutate(ctx, m)
|
||||||
|
case *PostMutation:
|
||||||
|
return c.Post.mutate(ctx, m)
|
||||||
|
case *ProfileMutation:
|
||||||
|
return c.Profile.mutate(ctx, m)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryClient is a client for the Category schema.
|
||||||
|
type CategoryClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCategoryClient returns a client for the Category from the given config.
|
||||||
|
func NewCategoryClient(c config) *CategoryClient {
|
||||||
|
return &CategoryClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `category.Hooks(f(g(h())))`.
|
||||||
|
func (c *CategoryClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Category = append(c.hooks.Category, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `category.Intercept(f(g(h())))`.
|
||||||
|
func (c *CategoryClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Category = append(c.inters.Category, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Category entity.
|
||||||
|
func (c *CategoryClient) Create() *CategoryCreate {
|
||||||
|
mutation := newCategoryMutation(c.config, OpCreate)
|
||||||
|
return &CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Category entities.
|
||||||
|
func (c *CategoryClient) CreateBulk(builders ...*CategoryCreate) *CategoryCreateBulk {
|
||||||
|
return &CategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *CategoryClient) MapCreateBulk(slice any, setFunc func(*CategoryCreate, int)) *CategoryCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &CategoryCreateBulk{err: fmt.Errorf("calling to CategoryClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*CategoryCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &CategoryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Category.
|
||||||
|
func (c *CategoryClient) Update() *CategoryUpdate {
|
||||||
|
mutation := newCategoryMutation(c.config, OpUpdate)
|
||||||
|
return &CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *CategoryClient) UpdateOne(ca *Category) *CategoryUpdateOne {
|
||||||
|
mutation := newCategoryMutation(c.config, OpUpdateOne, withCategory(ca))
|
||||||
|
return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *CategoryClient) UpdateOneID(id uuid.UUID) *CategoryUpdateOne {
|
||||||
|
mutation := newCategoryMutation(c.config, OpUpdateOne, withCategoryID(id))
|
||||||
|
return &CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Category.
|
||||||
|
func (c *CategoryClient) Delete() *CategoryDelete {
|
||||||
|
mutation := newCategoryMutation(c.config, OpDelete)
|
||||||
|
return &CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *CategoryClient) DeleteOne(ca *Category) *CategoryDeleteOne {
|
||||||
|
return c.DeleteOneID(ca.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *CategoryClient) DeleteOneID(id uuid.UUID) *CategoryDeleteOne {
|
||||||
|
builder := c.Delete().Where(category.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &CategoryDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Category.
|
||||||
|
func (c *CategoryClient) Query() *CategoryQuery {
|
||||||
|
return &CategoryQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeCategory},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Category entity by its id.
|
||||||
|
func (c *CategoryClient) Get(ctx context.Context, id uuid.UUID) (*Category, error) {
|
||||||
|
return c.Query().Where(category.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *CategoryClient) GetX(ctx context.Context, id uuid.UUID) *Category {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts queries the posts edge of a Category.
|
||||||
|
func (c *CategoryClient) QueryPosts(ca *Category) *PostQuery {
|
||||||
|
query := (&PostClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := ca.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(category.Table, category.FieldID, id),
|
||||||
|
sqlgraph.To(post.Table, post.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, category.PostsTable, category.PostsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *CategoryClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Category
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *CategoryClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Category
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CategoryClient) mutate(ctx context.Context, m *CategoryMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&CategoryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&CategoryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&CategoryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&CategoryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown Category mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostClient is a client for the Post schema.
|
||||||
|
type PostClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPostClient returns a client for the Post from the given config.
|
||||||
|
func NewPostClient(c config) *PostClient {
|
||||||
|
return &PostClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `post.Hooks(f(g(h())))`.
|
||||||
|
func (c *PostClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Post = append(c.hooks.Post, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `post.Intercept(f(g(h())))`.
|
||||||
|
func (c *PostClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Post = append(c.inters.Post, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Post entity.
|
||||||
|
func (c *PostClient) Create() *PostCreate {
|
||||||
|
mutation := newPostMutation(c.config, OpCreate)
|
||||||
|
return &PostCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Post entities.
|
||||||
|
func (c *PostClient) CreateBulk(builders ...*PostCreate) *PostCreateBulk {
|
||||||
|
return &PostCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *PostClient) MapCreateBulk(slice any, setFunc func(*PostCreate, int)) *PostCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &PostCreateBulk{err: fmt.Errorf("calling to PostClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*PostCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &PostCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Post.
|
||||||
|
func (c *PostClient) Update() *PostUpdate {
|
||||||
|
mutation := newPostMutation(c.config, OpUpdate)
|
||||||
|
return &PostUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *PostClient) UpdateOne(po *Post) *PostUpdateOne {
|
||||||
|
mutation := newPostMutation(c.config, OpUpdateOne, withPost(po))
|
||||||
|
return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *PostClient) UpdateOneID(id uuid.UUID) *PostUpdateOne {
|
||||||
|
mutation := newPostMutation(c.config, OpUpdateOne, withPostID(id))
|
||||||
|
return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Post.
|
||||||
|
func (c *PostClient) Delete() *PostDelete {
|
||||||
|
mutation := newPostMutation(c.config, OpDelete)
|
||||||
|
return &PostDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *PostClient) DeleteOne(po *Post) *PostDeleteOne {
|
||||||
|
return c.DeleteOneID(po.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *PostClient) DeleteOneID(id uuid.UUID) *PostDeleteOne {
|
||||||
|
builder := c.Delete().Where(post.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &PostDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Post.
|
||||||
|
func (c *PostClient) Query() *PostQuery {
|
||||||
|
return &PostQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypePost},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Post entity by its id.
|
||||||
|
func (c *PostClient) Get(ctx context.Context, id uuid.UUID) (*Post, error) {
|
||||||
|
return c.Query().Where(post.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *PostClient) GetX(ctx context.Context, id uuid.UUID) *Post {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryCategory queries the category edge of a Post.
|
||||||
|
func (c *PostClient) QueryCategory(po *Post) *CategoryQuery {
|
||||||
|
query := (&CategoryClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := po.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(post.Table, post.FieldID, id),
|
||||||
|
sqlgraph.To(category.Table, category.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, post.CategoryTable, post.CategoryColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(po.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProfile queries the profile edge of a Post.
|
||||||
|
func (c *PostClient) QueryProfile(po *Post) *ProfileQuery {
|
||||||
|
query := (&ProfileClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := po.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(post.Table, post.FieldID, id),
|
||||||
|
sqlgraph.To(profile.Table, profile.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, post.ProfileTable, post.ProfileColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(po.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *PostClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Post
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *PostClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Post
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileClient is a client for the Profile schema.
|
||||||
|
type ProfileClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewProfileClient returns a client for the Profile from the given config.
|
||||||
|
func NewProfileClient(c config) *ProfileClient {
|
||||||
|
return &ProfileClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `profile.Hooks(f(g(h())))`.
|
||||||
|
func (c *ProfileClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Profile = append(c.hooks.Profile, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||||
|
// A call to `Intercept(f, g, h)` equals to `profile.Intercept(f(g(h())))`.
|
||||||
|
func (c *ProfileClient) Intercept(interceptors ...Interceptor) {
|
||||||
|
c.inters.Profile = append(c.inters.Profile, interceptors...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a Profile entity.
|
||||||
|
func (c *ProfileClient) Create() *ProfileCreate {
|
||||||
|
mutation := newProfileMutation(c.config, OpCreate)
|
||||||
|
return &ProfileCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Profile entities.
|
||||||
|
func (c *ProfileClient) CreateBulk(builders ...*ProfileCreate) *ProfileCreateBulk {
|
||||||
|
return &ProfileCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||||
|
// a builder and applies setFunc on it.
|
||||||
|
func (c *ProfileClient) MapCreateBulk(slice any, setFunc func(*ProfileCreate, int)) *ProfileCreateBulk {
|
||||||
|
rv := reflect.ValueOf(slice)
|
||||||
|
if rv.Kind() != reflect.Slice {
|
||||||
|
return &ProfileCreateBulk{err: fmt.Errorf("calling to ProfileClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||||
|
}
|
||||||
|
builders := make([]*ProfileCreate, rv.Len())
|
||||||
|
for i := 0; i < rv.Len(); i++ {
|
||||||
|
builders[i] = c.Create()
|
||||||
|
setFunc(builders[i], i)
|
||||||
|
}
|
||||||
|
return &ProfileCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Profile.
|
||||||
|
func (c *ProfileClient) Update() *ProfileUpdate {
|
||||||
|
mutation := newProfileMutation(c.config, OpUpdate)
|
||||||
|
return &ProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *ProfileClient) UpdateOne(pr *Profile) *ProfileUpdateOne {
|
||||||
|
mutation := newProfileMutation(c.config, OpUpdateOne, withProfile(pr))
|
||||||
|
return &ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *ProfileClient) UpdateOneID(id uuid.UUID) *ProfileUpdateOne {
|
||||||
|
mutation := newProfileMutation(c.config, OpUpdateOne, withProfileID(id))
|
||||||
|
return &ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Profile.
|
||||||
|
func (c *ProfileClient) Delete() *ProfileDelete {
|
||||||
|
mutation := newProfileMutation(c.config, OpDelete)
|
||||||
|
return &ProfileDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *ProfileClient) DeleteOne(pr *Profile) *ProfileDeleteOne {
|
||||||
|
return c.DeleteOneID(pr.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *ProfileClient) DeleteOneID(id uuid.UUID) *ProfileDeleteOne {
|
||||||
|
builder := c.Delete().Where(profile.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &ProfileDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Profile.
|
||||||
|
func (c *ProfileClient) Query() *ProfileQuery {
|
||||||
|
return &ProfileQuery{
|
||||||
|
config: c.config,
|
||||||
|
ctx: &QueryContext{Type: TypeProfile},
|
||||||
|
inters: c.Interceptors(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Profile entity by its id.
|
||||||
|
func (c *ProfileClient) Get(ctx context.Context, id uuid.UUID) (*Profile, error) {
|
||||||
|
return c.Query().Where(profile.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *ProfileClient) GetX(ctx context.Context, id uuid.UUID) *Profile {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts queries the posts edge of a Profile.
|
||||||
|
func (c *ProfileClient) QueryPosts(pr *Profile) *PostQuery {
|
||||||
|
query := (&PostClient{config: c.config}).Query()
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := pr.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(profile.Table, profile.FieldID, id),
|
||||||
|
sqlgraph.To(post.Table, post.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, profile.PostsTable, profile.PostsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(pr.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *ProfileClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Profile
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interceptors returns the client interceptors.
|
||||||
|
func (c *ProfileClient) Interceptors() []Interceptor {
|
||||||
|
return c.inters.Profile
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ProfileClient) mutate(ctx context.Context, m *ProfileMutation) (Value, error) {
|
||||||
|
switch m.Op() {
|
||||||
|
case OpCreate:
|
||||||
|
return (&ProfileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdate:
|
||||||
|
return (&ProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpUpdateOne:
|
||||||
|
return (&ProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||||
|
case OpDelete, OpDeleteOne:
|
||||||
|
return (&ProfileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ent: unknown Profile mutation op: %q", m.Op())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks and interceptors per client, for fast access.
|
||||||
|
type (
|
||||||
|
hooks struct {
|
||||||
|
Category, Post, Profile []ent.Hook
|
||||||
|
}
|
||||||
|
inters struct {
|
||||||
|
Category, Post, Profile []ent.Interceptor
|
||||||
|
}
|
||||||
|
)
|
612
ent/ent.go
Normal file
612
ent/ent.go
Normal file
@ -0,0 +1,612 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
QueryContext = ent.QueryContext
|
||||||
|
Querier = ent.Querier
|
||||||
|
QuerierFunc = ent.QuerierFunc
|
||||||
|
Interceptor = ent.Interceptor
|
||||||
|
InterceptFunc = ent.InterceptFunc
|
||||||
|
Traverser = ent.Traverser
|
||||||
|
TraverseFunc = ent.TraverseFunc
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
var (
|
||||||
|
initCheck sync.Once
|
||||||
|
columnCheck sql.ColumnCheck
|
||||||
|
)
|
||||||
|
|
||||||
|
// checkColumn checks if the column exists in the given table.
|
||||||
|
func checkColumn(table, column string) error {
|
||||||
|
initCheck.Do(func() {
|
||||||
|
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||||
|
category.Table: category.ValidColumn,
|
||||||
|
post.Table: post.ValidColumn,
|
||||||
|
profile.Table: profile.ValidColumn,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return columnCheck(table, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) func(*sql.Selector) {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := checkColumn(s.TableName(), f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
if err := checkColumn(s.TableName(), field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "ent: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "ent: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "ent: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError 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 ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "ent: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selector embedded by the different Select/GroupBy builders.
|
||||||
|
type selector struct {
|
||||||
|
label string
|
||||||
|
flds *[]string
|
||||||
|
fns []AggregateFunc
|
||||||
|
scan func(context.Context, any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||||
|
if err := s.scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (s *selector) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := s.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = s.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (s *selector) StringX(ctx context.Context) string {
|
||||||
|
v, err := s.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (s *selector) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := s.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = s.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (s *selector) IntX(ctx context.Context) int {
|
||||||
|
v, err := s.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := s.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = s.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := s.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(*s.flds) > 1 {
|
||||||
|
return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := s.scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := s.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = s.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{s.label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (s *selector) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := s.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// withHooks invokes the builder operation with the given hooks, if any.
|
||||||
|
func withHooks[V Value, M any, PM interface {
|
||||||
|
*M
|
||||||
|
Mutation
|
||||||
|
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||||
|
if len(hooks) == 0 {
|
||||||
|
return exec(ctx)
|
||||||
|
}
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutationT, ok := any(m).(PM)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
// Set the mutation to the builder.
|
||||||
|
*mutation = *mutationT
|
||||||
|
return exec(ctx)
|
||||||
|
})
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
if hooks[i] == nil {
|
||||||
|
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mutation)
|
||||||
|
if err != nil {
|
||||||
|
return value, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(V)
|
||||||
|
if !ok {
|
||||||
|
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||||
|
}
|
||||||
|
return nv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||||
|
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||||
|
if ent.QueryFromContext(ctx) == nil {
|
||||||
|
qc.Op = op
|
||||||
|
ctx = ent.NewQueryContext(ctx, qc)
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierAll[V Value, Q interface {
|
||||||
|
sqlAll(context.Context, ...queryHook) (V, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlAll(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func querierCount[Q interface {
|
||||||
|
sqlCount(context.Context) (int, error)
|
||||||
|
}]() Querier {
|
||||||
|
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
return query.sqlCount(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
rv, err := qr.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return v, err
|
||||||
|
}
|
||||||
|
vt, ok := rv.(V)
|
||||||
|
if !ok {
|
||||||
|
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||||
|
}
|
||||||
|
return vt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||||
|
sqlScan(context.Context, Q1, any) error
|
||||||
|
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||||
|
query, ok := q.(Q1)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||||
|
}
|
||||||
|
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||||
|
return rv.Elem().Interface(), nil
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
for i := len(inters) - 1; i >= 0; i-- {
|
||||||
|
qr = inters[i].Intercept(qr)
|
||||||
|
}
|
||||||
|
vv, err := qr.Query(ctx, rootQuery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch rv2 := reflect.ValueOf(vv); {
|
||||||
|
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||||
|
case rv.Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2.Elem())
|
||||||
|
case rv.Elem().Type() == rv2.Type():
|
||||||
|
rv.Elem().Set(rv2)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// queryHook describes an internal hook for the different sqlAll methods.
|
||||||
|
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
@ -12,9 +12,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ex, err := entgql.NewExtension(
|
ex, err := entgql.NewExtension(
|
||||||
entgql.WithConfigPath("gqlgen.yml"),
|
entgql.WithConfigPath("./gqlgen.yml"),
|
||||||
entgql.WithSchemaGenerator(),
|
entgql.WithSchemaGenerator(),
|
||||||
entgql.WithSchemaPath("ent.graphql"),
|
entgql.WithSchemaPath("./ent.graphql"),
|
||||||
entgql.WithWhereInputs(true),
|
entgql.WithWhereInputs(true),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
380
ent/entql.go
Normal file
380
ent/entql.go
Normal file
@ -0,0 +1,380 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/entql"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// schemaGraph holds a representation of ent/schema at runtime.
|
||||||
|
var schemaGraph = func() *sqlgraph.Schema {
|
||||||
|
graph := &sqlgraph.Schema{Nodes: make([]*sqlgraph.Node, 3)}
|
||||||
|
graph.Nodes[0] = &sqlgraph.Node{
|
||||||
|
NodeSpec: sqlgraph.NodeSpec{
|
||||||
|
Table: category.Table,
|
||||||
|
Columns: category.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: category.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Type: "Category",
|
||||||
|
Fields: map[string]*sqlgraph.FieldSpec{
|
||||||
|
category.FieldCreatedAt: {Type: field.TypeTime, Column: category.FieldCreatedAt},
|
||||||
|
category.FieldUpdatedAt: {Type: field.TypeTime, Column: category.FieldUpdatedAt},
|
||||||
|
category.FieldTitle: {Type: field.TypeString, Column: category.FieldTitle},
|
||||||
|
category.FieldDescription: {Type: field.TypeString, Column: category.FieldDescription},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
graph.Nodes[1] = &sqlgraph.Node{
|
||||||
|
NodeSpec: sqlgraph.NodeSpec{
|
||||||
|
Table: post.Table,
|
||||||
|
Columns: post.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: post.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Type: "Post",
|
||||||
|
Fields: map[string]*sqlgraph.FieldSpec{
|
||||||
|
post.FieldCreatedAt: {Type: field.TypeTime, Column: post.FieldCreatedAt},
|
||||||
|
post.FieldUpdatedAt: {Type: field.TypeTime, Column: post.FieldUpdatedAt},
|
||||||
|
post.FieldExpires: {Type: field.TypeBool, Column: post.FieldExpires},
|
||||||
|
post.FieldExpireTime: {Type: field.TypeTime, Column: post.FieldExpireTime},
|
||||||
|
post.FieldTitle: {Type: field.TypeString, Column: post.FieldTitle},
|
||||||
|
post.FieldBody: {Type: field.TypeString, Column: post.FieldBody},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
graph.Nodes[2] = &sqlgraph.Node{
|
||||||
|
NodeSpec: sqlgraph.NodeSpec{
|
||||||
|
Table: profile.Table,
|
||||||
|
Columns: profile.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: profile.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Type: "Profile",
|
||||||
|
Fields: map[string]*sqlgraph.FieldSpec{
|
||||||
|
profile.FieldCreatedAt: {Type: field.TypeTime, Column: profile.FieldCreatedAt},
|
||||||
|
profile.FieldUpdatedAt: {Type: field.TypeTime, Column: profile.FieldUpdatedAt},
|
||||||
|
profile.FieldName: {Type: field.TypeString, Column: profile.FieldName},
|
||||||
|
profile.FieldAddress: {Type: field.TypeString, Column: profile.FieldAddress},
|
||||||
|
profile.FieldPhone: {Type: field.TypeString, Column: profile.FieldPhone},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
graph.MustAddE(
|
||||||
|
"posts",
|
||||||
|
&sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: category.PostsTable,
|
||||||
|
Columns: []string{category.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
},
|
||||||
|
"Category",
|
||||||
|
"Post",
|
||||||
|
)
|
||||||
|
graph.MustAddE(
|
||||||
|
"category",
|
||||||
|
&sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
},
|
||||||
|
"Post",
|
||||||
|
"Category",
|
||||||
|
)
|
||||||
|
graph.MustAddE(
|
||||||
|
"profile",
|
||||||
|
&sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
},
|
||||||
|
"Post",
|
||||||
|
"Profile",
|
||||||
|
)
|
||||||
|
graph.MustAddE(
|
||||||
|
"posts",
|
||||||
|
&sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
},
|
||||||
|
"Profile",
|
||||||
|
"Post",
|
||||||
|
)
|
||||||
|
return graph
|
||||||
|
}()
|
||||||
|
|
||||||
|
// predicateAdder wraps the addPredicate method.
|
||||||
|
// All update, update-one and query builders implement this interface.
|
||||||
|
type predicateAdder interface {
|
||||||
|
addPredicate(func(s *sql.Selector))
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (cq *CategoryQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
cq.predicates = append(cq.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns a Filter implementation to apply filters on the CategoryQuery builder.
|
||||||
|
func (cq *CategoryQuery) Filter() *CategoryFilter {
|
||||||
|
return &CategoryFilter{config: cq.config, predicateAdder: cq}
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (m *CategoryMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
m.predicates = append(m.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns an entql.Where implementation to apply filters on the CategoryMutation builder.
|
||||||
|
func (m *CategoryMutation) Filter() *CategoryFilter {
|
||||||
|
return &CategoryFilter{config: m.config, predicateAdder: m}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryFilter provides a generic filtering capability at runtime for CategoryQuery.
|
||||||
|
type CategoryFilter struct {
|
||||||
|
predicateAdder
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where applies the entql predicate on the query filter.
|
||||||
|
func (f *CategoryFilter) Where(p entql.P) {
|
||||||
|
f.addPredicate(func(s *sql.Selector) {
|
||||||
|
if err := schemaGraph.EvalP(schemaGraph.Nodes[0].Type, p, s); err != nil {
|
||||||
|
s.AddError(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereID applies the entql [16]byte predicate on the id field.
|
||||||
|
func (f *CategoryFilter) WhereID(p entql.ValueP) {
|
||||||
|
f.Where(p.Field(category.FieldID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereCreatedAt applies the entql time.Time predicate on the created_at field.
|
||||||
|
func (f *CategoryFilter) WhereCreatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(category.FieldCreatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field.
|
||||||
|
func (f *CategoryFilter) WhereUpdatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(category.FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereTitle applies the entql string predicate on the title field.
|
||||||
|
func (f *CategoryFilter) WhereTitle(p entql.StringP) {
|
||||||
|
f.Where(p.Field(category.FieldTitle))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereDescription applies the entql string predicate on the description field.
|
||||||
|
func (f *CategoryFilter) WhereDescription(p entql.StringP) {
|
||||||
|
f.Where(p.Field(category.FieldDescription))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasPosts applies a predicate to check if query has an edge posts.
|
||||||
|
func (f *CategoryFilter) WhereHasPosts() {
|
||||||
|
f.Where(entql.HasEdge("posts"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasPostsWith applies a predicate to check if query has an edge posts with a given conditions (other predicates).
|
||||||
|
func (f *CategoryFilter) WhereHasPostsWith(preds ...predicate.Post) {
|
||||||
|
f.Where(entql.HasEdgeWith("posts", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (pq *PostQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
pq.predicates = append(pq.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns a Filter implementation to apply filters on the PostQuery builder.
|
||||||
|
func (pq *PostQuery) Filter() *PostFilter {
|
||||||
|
return &PostFilter{config: pq.config, predicateAdder: pq}
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (m *PostMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
m.predicates = append(m.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns an entql.Where implementation to apply filters on the PostMutation builder.
|
||||||
|
func (m *PostMutation) Filter() *PostFilter {
|
||||||
|
return &PostFilter{config: m.config, predicateAdder: m}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostFilter provides a generic filtering capability at runtime for PostQuery.
|
||||||
|
type PostFilter struct {
|
||||||
|
predicateAdder
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where applies the entql predicate on the query filter.
|
||||||
|
func (f *PostFilter) Where(p entql.P) {
|
||||||
|
f.addPredicate(func(s *sql.Selector) {
|
||||||
|
if err := schemaGraph.EvalP(schemaGraph.Nodes[1].Type, p, s); err != nil {
|
||||||
|
s.AddError(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereID applies the entql [16]byte predicate on the id field.
|
||||||
|
func (f *PostFilter) WhereID(p entql.ValueP) {
|
||||||
|
f.Where(p.Field(post.FieldID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereCreatedAt applies the entql time.Time predicate on the created_at field.
|
||||||
|
func (f *PostFilter) WhereCreatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(post.FieldCreatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field.
|
||||||
|
func (f *PostFilter) WhereUpdatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(post.FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereExpires applies the entql bool predicate on the expires field.
|
||||||
|
func (f *PostFilter) WhereExpires(p entql.BoolP) {
|
||||||
|
f.Where(p.Field(post.FieldExpires))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereExpireTime applies the entql time.Time predicate on the expire_time field.
|
||||||
|
func (f *PostFilter) WhereExpireTime(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(post.FieldExpireTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereTitle applies the entql string predicate on the title field.
|
||||||
|
func (f *PostFilter) WhereTitle(p entql.StringP) {
|
||||||
|
f.Where(p.Field(post.FieldTitle))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereBody applies the entql string predicate on the body field.
|
||||||
|
func (f *PostFilter) WhereBody(p entql.StringP) {
|
||||||
|
f.Where(p.Field(post.FieldBody))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasCategory applies a predicate to check if query has an edge category.
|
||||||
|
func (f *PostFilter) WhereHasCategory() {
|
||||||
|
f.Where(entql.HasEdge("category"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasCategoryWith applies a predicate to check if query has an edge category with a given conditions (other predicates).
|
||||||
|
func (f *PostFilter) WhereHasCategoryWith(preds ...predicate.Category) {
|
||||||
|
f.Where(entql.HasEdgeWith("category", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasProfile applies a predicate to check if query has an edge profile.
|
||||||
|
func (f *PostFilter) WhereHasProfile() {
|
||||||
|
f.Where(entql.HasEdge("profile"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasProfileWith applies a predicate to check if query has an edge profile with a given conditions (other predicates).
|
||||||
|
func (f *PostFilter) WhereHasProfileWith(preds ...predicate.Profile) {
|
||||||
|
f.Where(entql.HasEdgeWith("profile", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (pq *ProfileQuery) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
pq.predicates = append(pq.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns a Filter implementation to apply filters on the ProfileQuery builder.
|
||||||
|
func (pq *ProfileQuery) Filter() *ProfileFilter {
|
||||||
|
return &ProfileFilter{config: pq.config, predicateAdder: pq}
|
||||||
|
}
|
||||||
|
|
||||||
|
// addPredicate implements the predicateAdder interface.
|
||||||
|
func (m *ProfileMutation) addPredicate(pred func(s *sql.Selector)) {
|
||||||
|
m.predicates = append(m.predicates, pred)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter returns an entql.Where implementation to apply filters on the ProfileMutation builder.
|
||||||
|
func (m *ProfileMutation) Filter() *ProfileFilter {
|
||||||
|
return &ProfileFilter{config: m.config, predicateAdder: m}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileFilter provides a generic filtering capability at runtime for ProfileQuery.
|
||||||
|
type ProfileFilter struct {
|
||||||
|
predicateAdder
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where applies the entql predicate on the query filter.
|
||||||
|
func (f *ProfileFilter) Where(p entql.P) {
|
||||||
|
f.addPredicate(func(s *sql.Selector) {
|
||||||
|
if err := schemaGraph.EvalP(schemaGraph.Nodes[2].Type, p, s); err != nil {
|
||||||
|
s.AddError(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereID applies the entql [16]byte predicate on the id field.
|
||||||
|
func (f *ProfileFilter) WhereID(p entql.ValueP) {
|
||||||
|
f.Where(p.Field(profile.FieldID))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereCreatedAt applies the entql time.Time predicate on the created_at field.
|
||||||
|
func (f *ProfileFilter) WhereCreatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(profile.FieldCreatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereUpdatedAt applies the entql time.Time predicate on the updated_at field.
|
||||||
|
func (f *ProfileFilter) WhereUpdatedAt(p entql.TimeP) {
|
||||||
|
f.Where(p.Field(profile.FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereName applies the entql string predicate on the name field.
|
||||||
|
func (f *ProfileFilter) WhereName(p entql.StringP) {
|
||||||
|
f.Where(p.Field(profile.FieldName))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereAddress applies the entql string predicate on the address field.
|
||||||
|
func (f *ProfileFilter) WhereAddress(p entql.StringP) {
|
||||||
|
f.Where(p.Field(profile.FieldAddress))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WherePhone applies the entql string predicate on the phone field.
|
||||||
|
func (f *ProfileFilter) WherePhone(p entql.StringP) {
|
||||||
|
f.Where(p.Field(profile.FieldPhone))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasPosts applies a predicate to check if query has an edge posts.
|
||||||
|
func (f *ProfileFilter) WhereHasPosts() {
|
||||||
|
f.Where(entql.HasEdge("posts"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WhereHasPostsWith applies a predicate to check if query has an edge posts with a given conditions (other predicates).
|
||||||
|
func (f *ProfileFilter) WhereHasPostsWith(preds ...predicate.Post) {
|
||||||
|
f.Where(entql.HasEdgeWith("posts", sqlgraph.WrapFunc(func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
}
|
84
ent/enttest/enttest.go
Normal file
84
ent/enttest/enttest.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "code.icod.de/dalu/ka/ent/runtime"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/migrate"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []ent.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...ent.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls ent.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls ent.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := ent.NewClient(o.opts...)
|
||||||
|
migrateSchema(t, c, o)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
func migrateSchema(t TestingT, c *ent.Client, o *options) {
|
||||||
|
tables, err := schema.CopyTables(migrate.Tables)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
611
ent/gql_collection.go
Normal file
611
ent/gql_collection.go
Normal file
@ -0,0 +1,611 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/contrib/entgql"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CollectFields tells the query-builder to eagerly load connected nodes by resolver context.
|
||||||
|
func (c *CategoryQuery) CollectFields(ctx context.Context, satisfies ...string) (*CategoryQuery, error) {
|
||||||
|
fc := graphql.GetFieldContext(ctx)
|
||||||
|
if fc == nil {
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
if err := c.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CategoryQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error {
|
||||||
|
path = append([]string(nil), path...)
|
||||||
|
var (
|
||||||
|
unknownSeen bool
|
||||||
|
fieldSeen = make(map[string]struct{}, len(category.Columns))
|
||||||
|
selectedFields = []string{category.FieldID}
|
||||||
|
)
|
||||||
|
for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) {
|
||||||
|
switch field.Name {
|
||||||
|
|
||||||
|
case "posts":
|
||||||
|
var (
|
||||||
|
alias = field.Alias
|
||||||
|
path = append(path, alias)
|
||||||
|
query = (&PostClient{config: c.config}).Query()
|
||||||
|
)
|
||||||
|
args := newPostPaginateArgs(fieldArgs(ctx, new(PostWhereInput), path...))
|
||||||
|
if err := validateFirstLast(args.first, args.last); err != nil {
|
||||||
|
return fmt.Errorf("validate first and last in path %q: %w", path, err)
|
||||||
|
}
|
||||||
|
pager, err := newPostPager(args.opts, args.last != nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create new pager in path %q: %w", path, err)
|
||||||
|
}
|
||||||
|
if query, err = pager.applyFilter(query); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ignoredEdges := !hasCollectedField(ctx, append(path, edgesField)...)
|
||||||
|
if hasCollectedField(ctx, append(path, totalCountField)...) || hasCollectedField(ctx, append(path, pageInfoField)...) {
|
||||||
|
hasPagination := args.after != nil || args.first != nil || args.before != nil || args.last != nil
|
||||||
|
if hasPagination || ignoredEdges {
|
||||||
|
query := query.Clone()
|
||||||
|
c.loadTotal = append(c.loadTotal, func(ctx context.Context, nodes []*Category) error {
|
||||||
|
ids := make([]driver.Value, len(nodes))
|
||||||
|
for i := range nodes {
|
||||||
|
ids[i] = nodes[i].ID
|
||||||
|
}
|
||||||
|
var v []struct {
|
||||||
|
NodeID uuid.UUID `sql:"category_posts"`
|
||||||
|
Count int `sql:"count"`
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(category.PostsColumn), ids...))
|
||||||
|
})
|
||||||
|
if err := query.GroupBy(category.PostsColumn).Aggregate(Count()).Scan(ctx, &v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m := make(map[uuid.UUID]int, len(v))
|
||||||
|
for i := range v {
|
||||||
|
m[v[i].NodeID] = v[i].Count
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
n := m[nodes[i].ID]
|
||||||
|
if nodes[i].Edges.totalCount[0] == nil {
|
||||||
|
nodes[i].Edges.totalCount[0] = make(map[string]int)
|
||||||
|
}
|
||||||
|
nodes[i].Edges.totalCount[0][alias] = n
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
c.loadTotal = append(c.loadTotal, func(_ context.Context, nodes []*Category) error {
|
||||||
|
for i := range nodes {
|
||||||
|
n := len(nodes[i].Edges.Posts)
|
||||||
|
if nodes[i].Edges.totalCount[0] == nil {
|
||||||
|
nodes[i].Edges.totalCount[0] = make(map[string]int)
|
||||||
|
}
|
||||||
|
nodes[i].Edges.totalCount[0][alias] = n
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ignoredEdges || (args.first != nil && *args.first == 0) || (args.last != nil && *args.last == 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if query, err = pager.applyCursors(query, args.after, args.before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path = append(path, edgesField, nodeField)
|
||||||
|
if field := collectedField(ctx, path...); field != nil {
|
||||||
|
if err := query.collectField(ctx, false, opCtx, *field, path, mayAddCondition(satisfies, postImplementors)...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := paginateLimit(args.first, args.last); limit > 0 {
|
||||||
|
if oneNode {
|
||||||
|
pager.applyOrder(query.Limit(limit))
|
||||||
|
} else {
|
||||||
|
modify := entgql.LimitPerRow(category.PostsColumn, limit, pager.orderExpr(query))
|
||||||
|
query.modifiers = append(query.modifiers, modify)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
query = pager.applyOrder(query)
|
||||||
|
}
|
||||||
|
c.WithNamedPosts(alias, func(wq *PostQuery) {
|
||||||
|
*wq = *query
|
||||||
|
})
|
||||||
|
case "createdAt":
|
||||||
|
if _, ok := fieldSeen[category.FieldCreatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, category.FieldCreatedAt)
|
||||||
|
fieldSeen[category.FieldCreatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "updatedAt":
|
||||||
|
if _, ok := fieldSeen[category.FieldUpdatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, category.FieldUpdatedAt)
|
||||||
|
fieldSeen[category.FieldUpdatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "title":
|
||||||
|
if _, ok := fieldSeen[category.FieldTitle]; !ok {
|
||||||
|
selectedFields = append(selectedFields, category.FieldTitle)
|
||||||
|
fieldSeen[category.FieldTitle] = struct{}{}
|
||||||
|
}
|
||||||
|
case "description":
|
||||||
|
if _, ok := fieldSeen[category.FieldDescription]; !ok {
|
||||||
|
selectedFields = append(selectedFields, category.FieldDescription)
|
||||||
|
fieldSeen[category.FieldDescription] = struct{}{}
|
||||||
|
}
|
||||||
|
case "id":
|
||||||
|
case "__typename":
|
||||||
|
default:
|
||||||
|
unknownSeen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !unknownSeen {
|
||||||
|
c.Select(selectedFields...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type categoryPaginateArgs struct {
|
||||||
|
first, last *int
|
||||||
|
after, before *Cursor
|
||||||
|
opts []CategoryPaginateOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCategoryPaginateArgs(rv map[string]any) *categoryPaginateArgs {
|
||||||
|
args := &categoryPaginateArgs{}
|
||||||
|
if rv == nil {
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
if v := rv[firstField]; v != nil {
|
||||||
|
args.first = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[lastField]; v != nil {
|
||||||
|
args.last = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[afterField]; v != nil {
|
||||||
|
args.after = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v := rv[beforeField]; v != nil {
|
||||||
|
args.before = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v, ok := rv[orderByField]; ok {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case map[string]any:
|
||||||
|
var (
|
||||||
|
err1, err2 error
|
||||||
|
order = &CategoryOrder{Field: &CategoryOrderField{}, Direction: entgql.OrderDirectionAsc}
|
||||||
|
)
|
||||||
|
if d, ok := v[directionField]; ok {
|
||||||
|
err1 = order.Direction.UnmarshalGQL(d)
|
||||||
|
}
|
||||||
|
if f, ok := v[fieldField]; ok {
|
||||||
|
err2 = order.Field.UnmarshalGQL(f)
|
||||||
|
}
|
||||||
|
if err1 == nil && err2 == nil {
|
||||||
|
args.opts = append(args.opts, WithCategoryOrder(order))
|
||||||
|
}
|
||||||
|
case *CategoryOrder:
|
||||||
|
if v != nil {
|
||||||
|
args.opts = append(args.opts, WithCategoryOrder(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := rv[whereField].(*CategoryWhereInput); ok {
|
||||||
|
args.opts = append(args.opts, WithCategoryFilter(v.Filter))
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
// CollectFields tells the query-builder to eagerly load connected nodes by resolver context.
|
||||||
|
func (po *PostQuery) CollectFields(ctx context.Context, satisfies ...string) (*PostQuery, error) {
|
||||||
|
fc := graphql.GetFieldContext(ctx)
|
||||||
|
if fc == nil {
|
||||||
|
return po, nil
|
||||||
|
}
|
||||||
|
if err := po.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return po, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (po *PostQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error {
|
||||||
|
path = append([]string(nil), path...)
|
||||||
|
var (
|
||||||
|
unknownSeen bool
|
||||||
|
fieldSeen = make(map[string]struct{}, len(post.Columns))
|
||||||
|
selectedFields = []string{post.FieldID}
|
||||||
|
)
|
||||||
|
for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) {
|
||||||
|
switch field.Name {
|
||||||
|
|
||||||
|
case "category":
|
||||||
|
var (
|
||||||
|
alias = field.Alias
|
||||||
|
path = append(path, alias)
|
||||||
|
query = (&CategoryClient{config: po.config}).Query()
|
||||||
|
)
|
||||||
|
if err := query.collectField(ctx, oneNode, opCtx, field, path, mayAddCondition(satisfies, categoryImplementors)...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
po.withCategory = query
|
||||||
|
|
||||||
|
case "profile":
|
||||||
|
var (
|
||||||
|
alias = field.Alias
|
||||||
|
path = append(path, alias)
|
||||||
|
query = (&ProfileClient{config: po.config}).Query()
|
||||||
|
)
|
||||||
|
if err := query.collectField(ctx, oneNode, opCtx, field, path, mayAddCondition(satisfies, profileImplementors)...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
po.withProfile = query
|
||||||
|
case "createdAt":
|
||||||
|
if _, ok := fieldSeen[post.FieldCreatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldCreatedAt)
|
||||||
|
fieldSeen[post.FieldCreatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "updatedAt":
|
||||||
|
if _, ok := fieldSeen[post.FieldUpdatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldUpdatedAt)
|
||||||
|
fieldSeen[post.FieldUpdatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "expires":
|
||||||
|
if _, ok := fieldSeen[post.FieldExpires]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldExpires)
|
||||||
|
fieldSeen[post.FieldExpires] = struct{}{}
|
||||||
|
}
|
||||||
|
case "expireTime":
|
||||||
|
if _, ok := fieldSeen[post.FieldExpireTime]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldExpireTime)
|
||||||
|
fieldSeen[post.FieldExpireTime] = struct{}{}
|
||||||
|
}
|
||||||
|
case "title":
|
||||||
|
if _, ok := fieldSeen[post.FieldTitle]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldTitle)
|
||||||
|
fieldSeen[post.FieldTitle] = struct{}{}
|
||||||
|
}
|
||||||
|
case "body":
|
||||||
|
if _, ok := fieldSeen[post.FieldBody]; !ok {
|
||||||
|
selectedFields = append(selectedFields, post.FieldBody)
|
||||||
|
fieldSeen[post.FieldBody] = struct{}{}
|
||||||
|
}
|
||||||
|
case "id":
|
||||||
|
case "__typename":
|
||||||
|
default:
|
||||||
|
unknownSeen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !unknownSeen {
|
||||||
|
po.Select(selectedFields...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type postPaginateArgs struct {
|
||||||
|
first, last *int
|
||||||
|
after, before *Cursor
|
||||||
|
opts []PostPaginateOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPostPaginateArgs(rv map[string]any) *postPaginateArgs {
|
||||||
|
args := &postPaginateArgs{}
|
||||||
|
if rv == nil {
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
if v := rv[firstField]; v != nil {
|
||||||
|
args.first = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[lastField]; v != nil {
|
||||||
|
args.last = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[afterField]; v != nil {
|
||||||
|
args.after = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v := rv[beforeField]; v != nil {
|
||||||
|
args.before = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v, ok := rv[orderByField]; ok {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case map[string]any:
|
||||||
|
var (
|
||||||
|
err1, err2 error
|
||||||
|
order = &PostOrder{Field: &PostOrderField{}, Direction: entgql.OrderDirectionAsc}
|
||||||
|
)
|
||||||
|
if d, ok := v[directionField]; ok {
|
||||||
|
err1 = order.Direction.UnmarshalGQL(d)
|
||||||
|
}
|
||||||
|
if f, ok := v[fieldField]; ok {
|
||||||
|
err2 = order.Field.UnmarshalGQL(f)
|
||||||
|
}
|
||||||
|
if err1 == nil && err2 == nil {
|
||||||
|
args.opts = append(args.opts, WithPostOrder(order))
|
||||||
|
}
|
||||||
|
case *PostOrder:
|
||||||
|
if v != nil {
|
||||||
|
args.opts = append(args.opts, WithPostOrder(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := rv[whereField].(*PostWhereInput); ok {
|
||||||
|
args.opts = append(args.opts, WithPostFilter(v.Filter))
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
// CollectFields tells the query-builder to eagerly load connected nodes by resolver context.
|
||||||
|
func (pr *ProfileQuery) CollectFields(ctx context.Context, satisfies ...string) (*ProfileQuery, error) {
|
||||||
|
fc := graphql.GetFieldContext(ctx)
|
||||||
|
if fc == nil {
|
||||||
|
return pr, nil
|
||||||
|
}
|
||||||
|
if err := pr.collectField(ctx, false, graphql.GetOperationContext(ctx), fc.Field, nil, satisfies...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *ProfileQuery) collectField(ctx context.Context, oneNode bool, opCtx *graphql.OperationContext, collected graphql.CollectedField, path []string, satisfies ...string) error {
|
||||||
|
path = append([]string(nil), path...)
|
||||||
|
var (
|
||||||
|
unknownSeen bool
|
||||||
|
fieldSeen = make(map[string]struct{}, len(profile.Columns))
|
||||||
|
selectedFields = []string{profile.FieldID}
|
||||||
|
)
|
||||||
|
for _, field := range graphql.CollectFields(opCtx, collected.Selections, satisfies) {
|
||||||
|
switch field.Name {
|
||||||
|
|
||||||
|
case "posts":
|
||||||
|
var (
|
||||||
|
alias = field.Alias
|
||||||
|
path = append(path, alias)
|
||||||
|
query = (&PostClient{config: pr.config}).Query()
|
||||||
|
)
|
||||||
|
args := newPostPaginateArgs(fieldArgs(ctx, new(PostWhereInput), path...))
|
||||||
|
if err := validateFirstLast(args.first, args.last); err != nil {
|
||||||
|
return fmt.Errorf("validate first and last in path %q: %w", path, err)
|
||||||
|
}
|
||||||
|
pager, err := newPostPager(args.opts, args.last != nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create new pager in path %q: %w", path, err)
|
||||||
|
}
|
||||||
|
if query, err = pager.applyFilter(query); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ignoredEdges := !hasCollectedField(ctx, append(path, edgesField)...)
|
||||||
|
if hasCollectedField(ctx, append(path, totalCountField)...) || hasCollectedField(ctx, append(path, pageInfoField)...) {
|
||||||
|
hasPagination := args.after != nil || args.first != nil || args.before != nil || args.last != nil
|
||||||
|
if hasPagination || ignoredEdges {
|
||||||
|
query := query.Clone()
|
||||||
|
pr.loadTotal = append(pr.loadTotal, func(ctx context.Context, nodes []*Profile) error {
|
||||||
|
ids := make([]driver.Value, len(nodes))
|
||||||
|
for i := range nodes {
|
||||||
|
ids[i] = nodes[i].ID
|
||||||
|
}
|
||||||
|
var v []struct {
|
||||||
|
NodeID uuid.UUID `sql:"profile_posts"`
|
||||||
|
Count int `sql:"count"`
|
||||||
|
}
|
||||||
|
query.Where(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(profile.PostsColumn), ids...))
|
||||||
|
})
|
||||||
|
if err := query.GroupBy(profile.PostsColumn).Aggregate(Count()).Scan(ctx, &v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m := make(map[uuid.UUID]int, len(v))
|
||||||
|
for i := range v {
|
||||||
|
m[v[i].NodeID] = v[i].Count
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
n := m[nodes[i].ID]
|
||||||
|
if nodes[i].Edges.totalCount[0] == nil {
|
||||||
|
nodes[i].Edges.totalCount[0] = make(map[string]int)
|
||||||
|
}
|
||||||
|
nodes[i].Edges.totalCount[0][alias] = n
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
pr.loadTotal = append(pr.loadTotal, func(_ context.Context, nodes []*Profile) error {
|
||||||
|
for i := range nodes {
|
||||||
|
n := len(nodes[i].Edges.Posts)
|
||||||
|
if nodes[i].Edges.totalCount[0] == nil {
|
||||||
|
nodes[i].Edges.totalCount[0] = make(map[string]int)
|
||||||
|
}
|
||||||
|
nodes[i].Edges.totalCount[0][alias] = n
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ignoredEdges || (args.first != nil && *args.first == 0) || (args.last != nil && *args.last == 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if query, err = pager.applyCursors(query, args.after, args.before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
path = append(path, edgesField, nodeField)
|
||||||
|
if field := collectedField(ctx, path...); field != nil {
|
||||||
|
if err := query.collectField(ctx, false, opCtx, *field, path, mayAddCondition(satisfies, postImplementors)...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := paginateLimit(args.first, args.last); limit > 0 {
|
||||||
|
if oneNode {
|
||||||
|
pager.applyOrder(query.Limit(limit))
|
||||||
|
} else {
|
||||||
|
modify := entgql.LimitPerRow(profile.PostsColumn, limit, pager.orderExpr(query))
|
||||||
|
query.modifiers = append(query.modifiers, modify)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
query = pager.applyOrder(query)
|
||||||
|
}
|
||||||
|
pr.WithNamedPosts(alias, func(wq *PostQuery) {
|
||||||
|
*wq = *query
|
||||||
|
})
|
||||||
|
case "createdAt":
|
||||||
|
if _, ok := fieldSeen[profile.FieldCreatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, profile.FieldCreatedAt)
|
||||||
|
fieldSeen[profile.FieldCreatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "updatedAt":
|
||||||
|
if _, ok := fieldSeen[profile.FieldUpdatedAt]; !ok {
|
||||||
|
selectedFields = append(selectedFields, profile.FieldUpdatedAt)
|
||||||
|
fieldSeen[profile.FieldUpdatedAt] = struct{}{}
|
||||||
|
}
|
||||||
|
case "name":
|
||||||
|
if _, ok := fieldSeen[profile.FieldName]; !ok {
|
||||||
|
selectedFields = append(selectedFields, profile.FieldName)
|
||||||
|
fieldSeen[profile.FieldName] = struct{}{}
|
||||||
|
}
|
||||||
|
case "address":
|
||||||
|
if _, ok := fieldSeen[profile.FieldAddress]; !ok {
|
||||||
|
selectedFields = append(selectedFields, profile.FieldAddress)
|
||||||
|
fieldSeen[profile.FieldAddress] = struct{}{}
|
||||||
|
}
|
||||||
|
case "phone":
|
||||||
|
if _, ok := fieldSeen[profile.FieldPhone]; !ok {
|
||||||
|
selectedFields = append(selectedFields, profile.FieldPhone)
|
||||||
|
fieldSeen[profile.FieldPhone] = struct{}{}
|
||||||
|
}
|
||||||
|
case "id":
|
||||||
|
case "__typename":
|
||||||
|
default:
|
||||||
|
unknownSeen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !unknownSeen {
|
||||||
|
pr.Select(selectedFields...)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type profilePaginateArgs struct {
|
||||||
|
first, last *int
|
||||||
|
after, before *Cursor
|
||||||
|
opts []ProfilePaginateOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func newProfilePaginateArgs(rv map[string]any) *profilePaginateArgs {
|
||||||
|
args := &profilePaginateArgs{}
|
||||||
|
if rv == nil {
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
if v := rv[firstField]; v != nil {
|
||||||
|
args.first = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[lastField]; v != nil {
|
||||||
|
args.last = v.(*int)
|
||||||
|
}
|
||||||
|
if v := rv[afterField]; v != nil {
|
||||||
|
args.after = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v := rv[beforeField]; v != nil {
|
||||||
|
args.before = v.(*Cursor)
|
||||||
|
}
|
||||||
|
if v, ok := rv[orderByField]; ok {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case map[string]any:
|
||||||
|
var (
|
||||||
|
err1, err2 error
|
||||||
|
order = &ProfileOrder{Field: &ProfileOrderField{}, Direction: entgql.OrderDirectionAsc}
|
||||||
|
)
|
||||||
|
if d, ok := v[directionField]; ok {
|
||||||
|
err1 = order.Direction.UnmarshalGQL(d)
|
||||||
|
}
|
||||||
|
if f, ok := v[fieldField]; ok {
|
||||||
|
err2 = order.Field.UnmarshalGQL(f)
|
||||||
|
}
|
||||||
|
if err1 == nil && err2 == nil {
|
||||||
|
args.opts = append(args.opts, WithProfileOrder(order))
|
||||||
|
}
|
||||||
|
case *ProfileOrder:
|
||||||
|
if v != nil {
|
||||||
|
args.opts = append(args.opts, WithProfileOrder(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := rv[whereField].(*ProfileWhereInput); ok {
|
||||||
|
args.opts = append(args.opts, WithProfileFilter(v.Filter))
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
afterField = "after"
|
||||||
|
firstField = "first"
|
||||||
|
beforeField = "before"
|
||||||
|
lastField = "last"
|
||||||
|
orderByField = "orderBy"
|
||||||
|
directionField = "direction"
|
||||||
|
fieldField = "field"
|
||||||
|
whereField = "where"
|
||||||
|
)
|
||||||
|
|
||||||
|
func fieldArgs(ctx context.Context, whereInput any, path ...string) map[string]any {
|
||||||
|
field := collectedField(ctx, path...)
|
||||||
|
if field == nil || field.Arguments == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
oc := graphql.GetOperationContext(ctx)
|
||||||
|
args := field.ArgumentMap(oc.Variables)
|
||||||
|
return unmarshalArgs(ctx, whereInput, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
// unmarshalArgs allows extracting the field arguments from their raw representation.
|
||||||
|
func unmarshalArgs(ctx context.Context, whereInput any, args map[string]any) map[string]any {
|
||||||
|
for _, k := range []string{firstField, lastField} {
|
||||||
|
v, ok := args[k]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i, err := graphql.UnmarshalInt(v)
|
||||||
|
if err == nil {
|
||||||
|
args[k] = &i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, k := range []string{beforeField, afterField} {
|
||||||
|
v, ok := args[k]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
c := &Cursor{}
|
||||||
|
if c.UnmarshalGQL(v) == nil {
|
||||||
|
args[k] = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := args[whereField]; ok && whereInput != nil {
|
||||||
|
if err := graphql.UnmarshalInputFromContext(ctx, v, whereInput); err == nil {
|
||||||
|
args[whereField] = whereInput
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
// mayAddCondition appends another type condition to the satisfies list
|
||||||
|
// if it does not exist in the list.
|
||||||
|
func mayAddCondition(satisfies []string, typeCond []string) []string {
|
||||||
|
Cond:
|
||||||
|
for _, c := range typeCond {
|
||||||
|
for _, s := range satisfies {
|
||||||
|
if c == s {
|
||||||
|
continue Cond
|
||||||
|
}
|
||||||
|
}
|
||||||
|
satisfies = append(satisfies, c)
|
||||||
|
}
|
||||||
|
return satisfies
|
||||||
|
}
|
67
ent/gql_edge.go
Normal file
67
ent/gql_edge.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Category) Posts(
|
||||||
|
ctx context.Context, after *Cursor, first *int, before *Cursor, last *int, orderBy *PostOrder, where *PostWhereInput,
|
||||||
|
) (*PostConnection, error) {
|
||||||
|
opts := []PostPaginateOption{
|
||||||
|
WithPostOrder(orderBy),
|
||||||
|
WithPostFilter(where.Filter),
|
||||||
|
}
|
||||||
|
alias := graphql.GetFieldContext(ctx).Field.Alias
|
||||||
|
totalCount, hasTotalCount := c.Edges.totalCount[0][alias]
|
||||||
|
if nodes, err := c.NamedPosts(alias); err == nil || hasTotalCount {
|
||||||
|
pager, err := newPostPager(opts, last != nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn := &PostConnection{Edges: []*PostEdge{}, TotalCount: totalCount}
|
||||||
|
conn.build(nodes, pager, after, first, before, last)
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
return c.QueryPosts().Paginate(ctx, after, first, before, last, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (po *Post) Category(ctx context.Context) (*Category, error) {
|
||||||
|
result, err := po.Edges.CategoryOrErr()
|
||||||
|
if IsNotLoaded(err) {
|
||||||
|
result, err = po.QueryCategory().Only(ctx)
|
||||||
|
}
|
||||||
|
return result, MaskNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (po *Post) Profile(ctx context.Context) (*Profile, error) {
|
||||||
|
result, err := po.Edges.ProfileOrErr()
|
||||||
|
if IsNotLoaded(err) {
|
||||||
|
result, err = po.QueryProfile().Only(ctx)
|
||||||
|
}
|
||||||
|
return result, MaskNotFound(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *Profile) Posts(
|
||||||
|
ctx context.Context, after *Cursor, first *int, before *Cursor, last *int, orderBy *PostOrder, where *PostWhereInput,
|
||||||
|
) (*PostConnection, error) {
|
||||||
|
opts := []PostPaginateOption{
|
||||||
|
WithPostOrder(orderBy),
|
||||||
|
WithPostFilter(where.Filter),
|
||||||
|
}
|
||||||
|
alias := graphql.GetFieldContext(ctx).Field.Alias
|
||||||
|
totalCount, hasTotalCount := pr.Edges.totalCount[0][alias]
|
||||||
|
if nodes, err := pr.NamedPosts(alias); err == nil || hasTotalCount {
|
||||||
|
pager, err := newPostPager(opts, last != nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn := &PostConnection{Edges: []*PostEdge{}, TotalCount: totalCount}
|
||||||
|
conn.build(nodes, pager, after, first, before, last)
|
||||||
|
return conn, nil
|
||||||
|
}
|
||||||
|
return pr.QueryPosts().Paginate(ctx, after, first, before, last, opts...)
|
||||||
|
}
|
301
ent/gql_mutation_input.go
Normal file
301
ent/gql_mutation_input.go
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateCategoryInput represents a mutation input for creating categories.
|
||||||
|
type CreateCategoryInput struct {
|
||||||
|
CreatedAt *time.Time
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
Title string
|
||||||
|
Description *string
|
||||||
|
PostIDs []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the CreateCategoryInput on the CategoryMutation builder.
|
||||||
|
func (i *CreateCategoryInput) Mutate(m *CategoryMutation) {
|
||||||
|
if v := i.CreatedAt; v != nil {
|
||||||
|
m.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
m.SetTitle(i.Title)
|
||||||
|
if v := i.Description; v != nil {
|
||||||
|
m.SetDescription(*v)
|
||||||
|
}
|
||||||
|
if v := i.PostIDs; len(v) > 0 {
|
||||||
|
m.AddPostIDs(v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the CreateCategoryInput on the CategoryCreate builder.
|
||||||
|
func (c *CategoryCreate) SetInput(i CreateCategoryInput) *CategoryCreate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateCategoryInput represents a mutation input for updating categories.
|
||||||
|
type UpdateCategoryInput struct {
|
||||||
|
ClearUpdatedAt bool
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
Title *string
|
||||||
|
ClearDescription bool
|
||||||
|
Description *string
|
||||||
|
ClearPosts bool
|
||||||
|
AddPostIDs []uuid.UUID
|
||||||
|
RemovePostIDs []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the UpdateCategoryInput on the CategoryMutation builder.
|
||||||
|
func (i *UpdateCategoryInput) Mutate(m *CategoryMutation) {
|
||||||
|
if i.ClearUpdatedAt {
|
||||||
|
m.ClearUpdatedAt()
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.Title; v != nil {
|
||||||
|
m.SetTitle(*v)
|
||||||
|
}
|
||||||
|
if i.ClearDescription {
|
||||||
|
m.ClearDescription()
|
||||||
|
}
|
||||||
|
if v := i.Description; v != nil {
|
||||||
|
m.SetDescription(*v)
|
||||||
|
}
|
||||||
|
if i.ClearPosts {
|
||||||
|
m.ClearPosts()
|
||||||
|
}
|
||||||
|
if v := i.AddPostIDs; len(v) > 0 {
|
||||||
|
m.AddPostIDs(v...)
|
||||||
|
}
|
||||||
|
if v := i.RemovePostIDs; len(v) > 0 {
|
||||||
|
m.RemovePostIDs(v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdateCategoryInput on the CategoryUpdate builder.
|
||||||
|
func (c *CategoryUpdate) SetInput(i UpdateCategoryInput) *CategoryUpdate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdateCategoryInput on the CategoryUpdateOne builder.
|
||||||
|
func (c *CategoryUpdateOne) SetInput(i UpdateCategoryInput) *CategoryUpdateOne {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatePostInput represents a mutation input for creating posts.
|
||||||
|
type CreatePostInput struct {
|
||||||
|
CreatedAt *time.Time
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
Expires *bool
|
||||||
|
ExpireTime *time.Time
|
||||||
|
Title string
|
||||||
|
Body string
|
||||||
|
CategoryID *uuid.UUID
|
||||||
|
ProfileID *uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the CreatePostInput on the PostMutation builder.
|
||||||
|
func (i *CreatePostInput) Mutate(m *PostMutation) {
|
||||||
|
if v := i.CreatedAt; v != nil {
|
||||||
|
m.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.Expires; v != nil {
|
||||||
|
m.SetExpires(*v)
|
||||||
|
}
|
||||||
|
if v := i.ExpireTime; v != nil {
|
||||||
|
m.SetExpireTime(*v)
|
||||||
|
}
|
||||||
|
m.SetTitle(i.Title)
|
||||||
|
m.SetBody(i.Body)
|
||||||
|
if v := i.CategoryID; v != nil {
|
||||||
|
m.SetCategoryID(*v)
|
||||||
|
}
|
||||||
|
if v := i.ProfileID; v != nil {
|
||||||
|
m.SetProfileID(*v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the CreatePostInput on the PostCreate builder.
|
||||||
|
func (c *PostCreate) SetInput(i CreatePostInput) *PostCreate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePostInput represents a mutation input for updating posts.
|
||||||
|
type UpdatePostInput struct {
|
||||||
|
ClearUpdatedAt bool
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
Expires *bool
|
||||||
|
ClearExpireTime bool
|
||||||
|
ExpireTime *time.Time
|
||||||
|
Title *string
|
||||||
|
Body *string
|
||||||
|
ClearCategory bool
|
||||||
|
CategoryID *uuid.UUID
|
||||||
|
ClearProfile bool
|
||||||
|
ProfileID *uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the UpdatePostInput on the PostMutation builder.
|
||||||
|
func (i *UpdatePostInput) Mutate(m *PostMutation) {
|
||||||
|
if i.ClearUpdatedAt {
|
||||||
|
m.ClearUpdatedAt()
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.Expires; v != nil {
|
||||||
|
m.SetExpires(*v)
|
||||||
|
}
|
||||||
|
if i.ClearExpireTime {
|
||||||
|
m.ClearExpireTime()
|
||||||
|
}
|
||||||
|
if v := i.ExpireTime; v != nil {
|
||||||
|
m.SetExpireTime(*v)
|
||||||
|
}
|
||||||
|
if v := i.Title; v != nil {
|
||||||
|
m.SetTitle(*v)
|
||||||
|
}
|
||||||
|
if v := i.Body; v != nil {
|
||||||
|
m.SetBody(*v)
|
||||||
|
}
|
||||||
|
if i.ClearCategory {
|
||||||
|
m.ClearCategory()
|
||||||
|
}
|
||||||
|
if v := i.CategoryID; v != nil {
|
||||||
|
m.SetCategoryID(*v)
|
||||||
|
}
|
||||||
|
if i.ClearProfile {
|
||||||
|
m.ClearProfile()
|
||||||
|
}
|
||||||
|
if v := i.ProfileID; v != nil {
|
||||||
|
m.SetProfileID(*v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdatePostInput on the PostUpdate builder.
|
||||||
|
func (c *PostUpdate) SetInput(i UpdatePostInput) *PostUpdate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdatePostInput on the PostUpdateOne builder.
|
||||||
|
func (c *PostUpdateOne) SetInput(i UpdatePostInput) *PostUpdateOne {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateProfileInput represents a mutation input for creating profiles.
|
||||||
|
type CreateProfileInput struct {
|
||||||
|
CreatedAt *time.Time
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
Name *string
|
||||||
|
Address *string
|
||||||
|
Phone *string
|
||||||
|
PostIDs []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the CreateProfileInput on the ProfileMutation builder.
|
||||||
|
func (i *CreateProfileInput) Mutate(m *ProfileMutation) {
|
||||||
|
if v := i.CreatedAt; v != nil {
|
||||||
|
m.SetCreatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
if v := i.Name; v != nil {
|
||||||
|
m.SetName(*v)
|
||||||
|
}
|
||||||
|
if v := i.Address; v != nil {
|
||||||
|
m.SetAddress(*v)
|
||||||
|
}
|
||||||
|
if v := i.Phone; v != nil {
|
||||||
|
m.SetPhone(*v)
|
||||||
|
}
|
||||||
|
if v := i.PostIDs; len(v) > 0 {
|
||||||
|
m.AddPostIDs(v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the CreateProfileInput on the ProfileCreate builder.
|
||||||
|
func (c *ProfileCreate) SetInput(i CreateProfileInput) *ProfileCreate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateProfileInput represents a mutation input for updating profiles.
|
||||||
|
type UpdateProfileInput struct {
|
||||||
|
ClearUpdatedAt bool
|
||||||
|
UpdatedAt *time.Time
|
||||||
|
ClearName bool
|
||||||
|
Name *string
|
||||||
|
ClearAddress bool
|
||||||
|
Address *string
|
||||||
|
ClearPhone bool
|
||||||
|
Phone *string
|
||||||
|
ClearPosts bool
|
||||||
|
AddPostIDs []uuid.UUID
|
||||||
|
RemovePostIDs []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutate applies the UpdateProfileInput on the ProfileMutation builder.
|
||||||
|
func (i *UpdateProfileInput) Mutate(m *ProfileMutation) {
|
||||||
|
if i.ClearUpdatedAt {
|
||||||
|
m.ClearUpdatedAt()
|
||||||
|
}
|
||||||
|
if v := i.UpdatedAt; v != nil {
|
||||||
|
m.SetUpdatedAt(*v)
|
||||||
|
}
|
||||||
|
if i.ClearName {
|
||||||
|
m.ClearName()
|
||||||
|
}
|
||||||
|
if v := i.Name; v != nil {
|
||||||
|
m.SetName(*v)
|
||||||
|
}
|
||||||
|
if i.ClearAddress {
|
||||||
|
m.ClearAddress()
|
||||||
|
}
|
||||||
|
if v := i.Address; v != nil {
|
||||||
|
m.SetAddress(*v)
|
||||||
|
}
|
||||||
|
if i.ClearPhone {
|
||||||
|
m.ClearPhone()
|
||||||
|
}
|
||||||
|
if v := i.Phone; v != nil {
|
||||||
|
m.SetPhone(*v)
|
||||||
|
}
|
||||||
|
if i.ClearPosts {
|
||||||
|
m.ClearPosts()
|
||||||
|
}
|
||||||
|
if v := i.AddPostIDs; len(v) > 0 {
|
||||||
|
m.AddPostIDs(v...)
|
||||||
|
}
|
||||||
|
if v := i.RemovePostIDs; len(v) > 0 {
|
||||||
|
m.RemovePostIDs(v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdateProfileInput on the ProfileUpdate builder.
|
||||||
|
func (c *ProfileUpdate) SetInput(i UpdateProfileInput) *ProfileUpdate {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetInput applies the change-set in the UpdateProfileInput on the ProfileUpdateOne builder.
|
||||||
|
func (c *ProfileUpdateOne) SetInput(i UpdateProfileInput) *ProfileUpdateOne {
|
||||||
|
i.Mutate(c.Mutation())
|
||||||
|
return c
|
||||||
|
}
|
248
ent/gql_node.go
Normal file
248
ent/gql_node.go
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/contrib/entgql"
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hashicorp/go-multierror"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Noder wraps the basic Node method.
|
||||||
|
type Noder interface {
|
||||||
|
IsNode()
|
||||||
|
}
|
||||||
|
|
||||||
|
var categoryImplementors = []string{"Category", "Node"}
|
||||||
|
|
||||||
|
// IsNode implements the Node interface check for GQLGen.
|
||||||
|
func (*Category) IsNode() {}
|
||||||
|
|
||||||
|
var postImplementors = []string{"Post", "Node"}
|
||||||
|
|
||||||
|
// IsNode implements the Node interface check for GQLGen.
|
||||||
|
func (*Post) IsNode() {}
|
||||||
|
|
||||||
|
var profileImplementors = []string{"Profile", "Node"}
|
||||||
|
|
||||||
|
// IsNode implements the Node interface check for GQLGen.
|
||||||
|
func (*Profile) IsNode() {}
|
||||||
|
|
||||||
|
var errNodeInvalidID = &NotFoundError{"node"}
|
||||||
|
|
||||||
|
// NodeOption allows configuring the Noder execution using functional options.
|
||||||
|
type NodeOption func(*nodeOptions)
|
||||||
|
|
||||||
|
// WithNodeType sets the node Type resolver function (i.e. the table to query).
|
||||||
|
// If was not provided, the table will be derived from the universal-id
|
||||||
|
// configuration as described in: https://entgo.io/docs/migrate/#universal-ids.
|
||||||
|
func WithNodeType(f func(context.Context, uuid.UUID) (string, error)) NodeOption {
|
||||||
|
return func(o *nodeOptions) {
|
||||||
|
o.nodeType = f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFixedNodeType sets the Type of the node to a fixed value.
|
||||||
|
func WithFixedNodeType(t string) NodeOption {
|
||||||
|
return WithNodeType(func(context.Context, uuid.UUID) (string, error) {
|
||||||
|
return t, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type nodeOptions struct {
|
||||||
|
nodeType func(context.Context, uuid.UUID) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) newNodeOpts(opts []NodeOption) *nodeOptions {
|
||||||
|
nopts := &nodeOptions{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(nopts)
|
||||||
|
}
|
||||||
|
if nopts.nodeType == nil {
|
||||||
|
nopts.nodeType = func(ctx context.Context, id uuid.UUID) (string, error) {
|
||||||
|
return "", fmt.Errorf("cannot resolve noder (%v) without its type", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nopts
|
||||||
|
}
|
||||||
|
|
||||||
|
// Noder returns a Node by its id. If the NodeType was not provided, it will
|
||||||
|
// be derived from the id value according to the universal-id configuration.
|
||||||
|
//
|
||||||
|
// c.Noder(ctx, id)
|
||||||
|
// c.Noder(ctx, id, ent.WithNodeType(typeResolver))
|
||||||
|
func (c *Client) Noder(ctx context.Context, id uuid.UUID, opts ...NodeOption) (_ Noder, err error) {
|
||||||
|
defer func() {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
err = multierror.Append(err, entgql.ErrNodeNotFound(id))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
table, err := c.newNodeOpts(opts).nodeType(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.noder(ctx, table, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) noder(ctx context.Context, table string, id uuid.UUID) (Noder, error) {
|
||||||
|
switch table {
|
||||||
|
case category.Table:
|
||||||
|
query := c.Category.Query().
|
||||||
|
Where(category.ID(id))
|
||||||
|
if fc := graphql.GetFieldContext(ctx); fc != nil {
|
||||||
|
if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, categoryImplementors...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query.Only(ctx)
|
||||||
|
case post.Table:
|
||||||
|
query := c.Post.Query().
|
||||||
|
Where(post.ID(id))
|
||||||
|
if fc := graphql.GetFieldContext(ctx); fc != nil {
|
||||||
|
if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, postImplementors...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query.Only(ctx)
|
||||||
|
case profile.Table:
|
||||||
|
query := c.Profile.Query().
|
||||||
|
Where(profile.ID(id))
|
||||||
|
if fc := graphql.GetFieldContext(ctx); fc != nil {
|
||||||
|
if err := query.collectField(ctx, true, graphql.GetOperationContext(ctx), fc.Field, nil, profileImplementors...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query.Only(ctx)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("cannot resolve noder from table %q: %w", table, errNodeInvalidID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Noders(ctx context.Context, ids []uuid.UUID, opts ...NodeOption) ([]Noder, error) {
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
noder, err := c.Noder(ctx, ids[0], opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return []Noder{noder}, nil
|
||||||
|
case 0:
|
||||||
|
return []Noder{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
noders := make([]Noder, len(ids))
|
||||||
|
errors := make([]error, len(ids))
|
||||||
|
tables := make(map[string][]uuid.UUID)
|
||||||
|
id2idx := make(map[uuid.UUID][]int, len(ids))
|
||||||
|
nopts := c.newNodeOpts(opts)
|
||||||
|
for i, id := range ids {
|
||||||
|
table, err := nopts.nodeType(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
errors[i] = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tables[table] = append(tables[table], id)
|
||||||
|
id2idx[id] = append(id2idx[id], i)
|
||||||
|
}
|
||||||
|
|
||||||
|
for table, ids := range tables {
|
||||||
|
nodes, err := c.noders(ctx, table, ids)
|
||||||
|
if err != nil {
|
||||||
|
for _, id := range ids {
|
||||||
|
for _, idx := range id2idx[id] {
|
||||||
|
errors[idx] = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i, id := range ids {
|
||||||
|
for _, idx := range id2idx[id] {
|
||||||
|
noders[idx] = nodes[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, id := range ids {
|
||||||
|
if errors[i] == nil {
|
||||||
|
if noders[i] != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
errors[i] = entgql.ErrNodeNotFound(id)
|
||||||
|
} else if IsNotFound(errors[i]) {
|
||||||
|
errors[i] = multierror.Append(errors[i], entgql.ErrNodeNotFound(id))
|
||||||
|
}
|
||||||
|
ctx := graphql.WithPathContext(ctx,
|
||||||
|
graphql.NewPathWithIndex(i),
|
||||||
|
)
|
||||||
|
graphql.AddError(ctx, errors[i])
|
||||||
|
}
|
||||||
|
return noders, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) noders(ctx context.Context, table string, ids []uuid.UUID) ([]Noder, error) {
|
||||||
|
noders := make([]Noder, len(ids))
|
||||||
|
idmap := make(map[uuid.UUID][]*Noder, len(ids))
|
||||||
|
for i, id := range ids {
|
||||||
|
idmap[id] = append(idmap[id], &noders[i])
|
||||||
|
}
|
||||||
|
switch table {
|
||||||
|
case category.Table:
|
||||||
|
query := c.Category.Query().
|
||||||
|
Where(category.IDIn(ids...))
|
||||||
|
query, err := query.CollectFields(ctx, categoryImplementors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodes, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, node := range nodes {
|
||||||
|
for _, noder := range idmap[node.ID] {
|
||||||
|
*noder = node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case post.Table:
|
||||||
|
query := c.Post.Query().
|
||||||
|
Where(post.IDIn(ids...))
|
||||||
|
query, err := query.CollectFields(ctx, postImplementors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodes, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, node := range nodes {
|
||||||
|
for _, noder := range idmap[node.ID] {
|
||||||
|
*noder = node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case profile.Table:
|
||||||
|
query := c.Profile.Query().
|
||||||
|
Where(profile.IDIn(ids...))
|
||||||
|
query, err := query.CollectFields(ctx, profileImplementors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodes, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, node := range nodes {
|
||||||
|
for _, noder := range idmap[node.ID] {
|
||||||
|
*noder = node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("cannot resolve noders from table %q: %w", table, errNodeInvalidID)
|
||||||
|
}
|
||||||
|
return noders, nil
|
||||||
|
}
|
1126
ent/gql_pagination.go
Normal file
1126
ent/gql_pagination.go
Normal file
File diff suppressed because it is too large
Load Diff
30
ent/gql_transaction.go
Normal file
30
ent/gql_transaction.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// OpenTx opens a transaction and returns a transactional
|
||||||
|
// context along with the created transaction.
|
||||||
|
func (c *Client) OpenTx(ctx context.Context) (context.Context, driver.Tx, error) {
|
||||||
|
tx, err := c.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
ctx = NewTxContext(ctx, tx)
|
||||||
|
ctx = NewContext(ctx, tx.Client())
|
||||||
|
return ctx, tx, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenTxFromContext open transactions from client stored in context.
|
||||||
|
func OpenTxFromContext(ctx context.Context) (context.Context, driver.Tx, error) {
|
||||||
|
client := FromContext(ctx)
|
||||||
|
if client == nil {
|
||||||
|
return nil, nil, errors.New("no client attached to context")
|
||||||
|
}
|
||||||
|
return client.OpenTx(ctx)
|
||||||
|
}
|
1165
ent/gql_where_input.go
Normal file
1165
ent/gql_where_input.go
Normal file
File diff suppressed because it is too large
Load Diff
223
ent/hook/hook.go
Normal file
223
ent/hook/hook.go
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The CategoryFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Category mutator.
|
||||||
|
type CategoryFunc func(context.Context, *ent.CategoryMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f CategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.CategoryMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CategoryMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The PostFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Post mutator.
|
||||||
|
type PostFunc func(context.Context, *ent.PostMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f PostFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.PostMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PostMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ProfileFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Profile mutator.
|
||||||
|
type ProfileFunc func(context.Context, *ent.ProfileMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f ProfileFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if mv, ok := m.(*ent.ProfileMutation); ok {
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProfileMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, ent.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op ent.Op) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||||
|
return func(next ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, ent.Delete|ent.Create)
|
||||||
|
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||||
|
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) ent.Hook {
|
||||||
|
return func(ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []ent.Hook {
|
||||||
|
// return []ent.Hook{
|
||||||
|
// Reject(ent.Delete|ent.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func Reject(op ent.Op) ent.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []ent.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...ent.Hook) Chain {
|
||||||
|
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() ent.Hook {
|
||||||
|
return func(mutator ent.Mutator) ent.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||||
|
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
9
ent/internal/schema.go
Normal file
9
ent/internal/schema.go
Normal file
File diff suppressed because one or more lines are too long
64
ent/migrate/migrate.go
Normal file
64
ent/migrate/migrate.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, s, Tables, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates all table resources using the given schema driver.
|
||||||
|
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||||
|
}
|
83
ent/migrate/schema.go
Normal file
83
ent/migrate/schema.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// CategoriesColumns holds the columns for the "categories" table.
|
||||||
|
CategoriesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "title", Type: field.TypeString},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||||
|
}
|
||||||
|
// CategoriesTable holds the schema information for the "categories" table.
|
||||||
|
CategoriesTable = &schema.Table{
|
||||||
|
Name: "categories",
|
||||||
|
Columns: CategoriesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{CategoriesColumns[0]},
|
||||||
|
}
|
||||||
|
// PostsColumns holds the columns for the "posts" table.
|
||||||
|
PostsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "expires", Type: field.TypeBool, Default: false},
|
||||||
|
{Name: "expire_time", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "title", Type: field.TypeString},
|
||||||
|
{Name: "body", Type: field.TypeString, Size: 2147483647},
|
||||||
|
{Name: "category_posts", Type: field.TypeUUID, Nullable: true},
|
||||||
|
{Name: "profile_posts", Type: field.TypeUUID, Nullable: true},
|
||||||
|
}
|
||||||
|
// PostsTable holds the schema information for the "posts" table.
|
||||||
|
PostsTable = &schema.Table{
|
||||||
|
Name: "posts",
|
||||||
|
Columns: PostsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{PostsColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "posts_categories_posts",
|
||||||
|
Columns: []*schema.Column{PostsColumns[7]},
|
||||||
|
RefColumns: []*schema.Column{CategoriesColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "posts_profiles_posts",
|
||||||
|
Columns: []*schema.Column{PostsColumns[8]},
|
||||||
|
RefColumns: []*schema.Column{ProfilesColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// ProfilesColumns holds the columns for the "profiles" table.
|
||||||
|
ProfilesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "address", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||||
|
{Name: "phone", Type: field.TypeString, Nullable: true},
|
||||||
|
}
|
||||||
|
// ProfilesTable holds the schema information for the "profiles" table.
|
||||||
|
ProfilesTable = &schema.Table{
|
||||||
|
Name: "profiles",
|
||||||
|
Columns: ProfilesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{ProfilesColumns[0]},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
CategoriesTable,
|
||||||
|
PostsTable,
|
||||||
|
ProfilesTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
PostsTable.ForeignKeys[0].RefTable = CategoriesTable
|
||||||
|
PostsTable.ForeignKeys[1].RefTable = ProfilesTable
|
||||||
|
}
|
2150
ent/mutation.go
Normal file
2150
ent/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
237
ent/post.go
Normal file
237
ent/post.go
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Post is the model entity for the Post schema.
|
||||||
|
type Post struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID uuid.UUID `json:"id,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// Expires holds the value of the "expires" field.
|
||||||
|
Expires bool `json:"expires,omitempty"`
|
||||||
|
// ExpireTime holds the value of the "expire_time" field.
|
||||||
|
ExpireTime *time.Time `json:"expire_time,omitempty"`
|
||||||
|
// Title holds the value of the "title" field.
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
// Body holds the value of the "body" field.
|
||||||
|
Body string `json:"body,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the PostQuery when eager-loading is set.
|
||||||
|
Edges PostEdges `json:"edges"`
|
||||||
|
category_posts *uuid.UUID
|
||||||
|
profile_posts *uuid.UUID
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type PostEdges struct {
|
||||||
|
// Category holds the value of the category edge.
|
||||||
|
Category *Category `json:"category,omitempty"`
|
||||||
|
// Profile holds the value of the profile edge.
|
||||||
|
Profile *Profile `json:"profile,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
// totalCount holds the count of the edges above.
|
||||||
|
totalCount [2]map[string]int
|
||||||
|
}
|
||||||
|
|
||||||
|
// CategoryOrErr returns the Category value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e PostEdges) CategoryOrErr() (*Category, error) {
|
||||||
|
if e.Category != nil {
|
||||||
|
return e.Category, nil
|
||||||
|
} else if e.loadedTypes[0] {
|
||||||
|
return nil, &NotFoundError{label: category.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "category"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileOrErr returns the Profile value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e PostEdges) ProfileOrErr() (*Profile, error) {
|
||||||
|
if e.Profile != nil {
|
||||||
|
return e.Profile, nil
|
||||||
|
} else if e.loadedTypes[1] {
|
||||||
|
return nil, &NotFoundError{label: profile.Label}
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "profile"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Post) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case post.FieldExpires:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case post.FieldTitle, post.FieldBody:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case post.FieldCreatedAt, post.FieldUpdatedAt, post.FieldExpireTime:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
case post.FieldID:
|
||||||
|
values[i] = new(uuid.UUID)
|
||||||
|
case post.ForeignKeys[0]: // category_posts
|
||||||
|
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||||
|
case post.ForeignKeys[1]: // profile_posts
|
||||||
|
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Post fields.
|
||||||
|
func (po *Post) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case post.FieldID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
po.ID = *value
|
||||||
|
}
|
||||||
|
case post.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case post.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case post.FieldExpires:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field expires", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.Expires = value.Bool
|
||||||
|
}
|
||||||
|
case post.FieldExpireTime:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field expire_time", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.ExpireTime = new(time.Time)
|
||||||
|
*po.ExpireTime = value.Time
|
||||||
|
}
|
||||||
|
case post.FieldTitle:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.Title = value.String
|
||||||
|
}
|
||||||
|
case post.FieldBody:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field body", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.Body = value.String
|
||||||
|
}
|
||||||
|
case post.ForeignKeys[0]:
|
||||||
|
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field category_posts", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.category_posts = new(uuid.UUID)
|
||||||
|
*po.category_posts = *value.S.(*uuid.UUID)
|
||||||
|
}
|
||||||
|
case post.ForeignKeys[1]:
|
||||||
|
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field profile_posts", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
po.profile_posts = new(uuid.UUID)
|
||||||
|
*po.profile_posts = *value.S.(*uuid.UUID)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
po.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Post.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (po *Post) Value(name string) (ent.Value, error) {
|
||||||
|
return po.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryCategory queries the "category" edge of the Post entity.
|
||||||
|
func (po *Post) QueryCategory() *CategoryQuery {
|
||||||
|
return NewPostClient(po.config).QueryCategory(po)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProfile queries the "profile" edge of the Post entity.
|
||||||
|
func (po *Post) QueryProfile() *ProfileQuery {
|
||||||
|
return NewPostClient(po.config).QueryProfile(po)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Post.
|
||||||
|
// Note that you need to call Post.Unwrap() before calling this method if this Post
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (po *Post) Update() *PostUpdateOne {
|
||||||
|
return NewPostClient(po.config).UpdateOne(po)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Post entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (po *Post) Unwrap() *Post {
|
||||||
|
_tx, ok := po.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Post is not a transactional entity")
|
||||||
|
}
|
||||||
|
po.config.driver = _tx.drv
|
||||||
|
return po
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (po *Post) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Post(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", po.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(po.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(po.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("expires=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", po.Expires))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := po.ExpireTime; v != nil {
|
||||||
|
builder.WriteString("expire_time=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("title=")
|
||||||
|
builder.WriteString(po.Title)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("body=")
|
||||||
|
builder.WriteString(po.Body)
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posts is a parsable slice of Post.
|
||||||
|
type Posts []*Post
|
166
ent/post/post.go
Normal file
166
ent/post/post.go
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package post
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the post type in the database.
|
||||||
|
Label = "post"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldExpires holds the string denoting the expires field in the database.
|
||||||
|
FieldExpires = "expires"
|
||||||
|
// FieldExpireTime holds the string denoting the expire_time field in the database.
|
||||||
|
FieldExpireTime = "expire_time"
|
||||||
|
// FieldTitle holds the string denoting the title field in the database.
|
||||||
|
FieldTitle = "title"
|
||||||
|
// FieldBody holds the string denoting the body field in the database.
|
||||||
|
FieldBody = "body"
|
||||||
|
// EdgeCategory holds the string denoting the category edge name in mutations.
|
||||||
|
EdgeCategory = "category"
|
||||||
|
// EdgeProfile holds the string denoting the profile edge name in mutations.
|
||||||
|
EdgeProfile = "profile"
|
||||||
|
// Table holds the table name of the post in the database.
|
||||||
|
Table = "posts"
|
||||||
|
// CategoryTable is the table that holds the category relation/edge.
|
||||||
|
CategoryTable = "posts"
|
||||||
|
// CategoryInverseTable is the table name for the Category entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "category" package.
|
||||||
|
CategoryInverseTable = "categories"
|
||||||
|
// CategoryColumn is the table column denoting the category relation/edge.
|
||||||
|
CategoryColumn = "category_posts"
|
||||||
|
// ProfileTable is the table that holds the profile relation/edge.
|
||||||
|
ProfileTable = "posts"
|
||||||
|
// ProfileInverseTable is the table name for the Profile entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "profile" package.
|
||||||
|
ProfileInverseTable = "profiles"
|
||||||
|
// ProfileColumn is the table column denoting the profile relation/edge.
|
||||||
|
ProfileColumn = "profile_posts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for post fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldExpires,
|
||||||
|
FieldExpireTime,
|
||||||
|
FieldTitle,
|
||||||
|
FieldBody,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForeignKeys holds the SQL foreign-keys that are owned by the "posts"
|
||||||
|
// table and are not defined as standalone fields in the schema.
|
||||||
|
var ForeignKeys = []string{
|
||||||
|
"category_posts",
|
||||||
|
"profile_posts",
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range ForeignKeys {
|
||||||
|
if column == ForeignKeys[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// DefaultExpires holds the default value on creation for the "expires" field.
|
||||||
|
DefaultExpires bool
|
||||||
|
// TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
TitleValidator func(string) error
|
||||||
|
// BodyValidator is a validator for the "body" field. It is called by the builders before save.
|
||||||
|
BodyValidator func(string) error
|
||||||
|
// DefaultID holds the default value on creation for the "id" field.
|
||||||
|
DefaultID func() uuid.UUID
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Post queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByExpires orders the results by the expires field.
|
||||||
|
func ByExpires(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldExpires, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByExpireTime orders the results by the expire_time field.
|
||||||
|
func ByExpireTime(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldExpireTime, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTitle orders the results by the title field.
|
||||||
|
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBody orders the results by the body field.
|
||||||
|
func ByBody(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldBody, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCategoryField orders the results by category field.
|
||||||
|
func ByCategoryField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newCategoryStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByProfileField orders the results by profile field.
|
||||||
|
func ByProfileField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newProfileStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newCategoryStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(CategoryInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, CategoryTable, CategoryColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newProfileStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ProfileInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ProfileTable, ProfileColumn),
|
||||||
|
)
|
||||||
|
}
|
428
ent/post/where.go
Normal file
428
ent/post/where.go
Normal file
@ -0,0 +1,428 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package post
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id uuid.UUID) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expires applies equality check predicate on the "expires" field. It's identical to ExpiresEQ.
|
||||||
|
func Expires(v bool) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldExpires, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTime applies equality check predicate on the "expire_time" field. It's identical to ExpireTimeEQ.
|
||||||
|
func ExpireTime(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||||
|
func Title(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Body applies equality check predicate on the "body" field. It's identical to BodyEQ.
|
||||||
|
func Body(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIsNil() predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIsNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotNil() predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresEQ applies the EQ predicate on the "expires" field.
|
||||||
|
func ExpiresEQ(v bool) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldExpires, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpiresNEQ applies the NEQ predicate on the "expires" field.
|
||||||
|
func ExpiresNEQ(v bool) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldExpires, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeEQ applies the EQ predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeNEQ applies the NEQ predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeNEQ(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeIn applies the In predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldExpireTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeNotIn applies the NotIn predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeNotIn(vs ...time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldExpireTime, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeGT applies the GT predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeGT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeGTE applies the GTE predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeGTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeLT applies the LT predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeLT(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeLTE applies the LTE predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeLTE(v time.Time) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldExpireTime, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeIsNil applies the IsNil predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeIsNil() predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIsNull(FieldExpireTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExpireTimeNotNil applies the NotNil predicate on the "expire_time" field.
|
||||||
|
func ExpireTimeNotNil() predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotNull(FieldExpireTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEQ applies the EQ predicate on the "title" field.
|
||||||
|
func TitleEQ(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||||
|
func TitleNEQ(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleIn applies the In predicate on the "title" field.
|
||||||
|
func TitleIn(vs ...string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||||
|
func TitleNotIn(vs ...string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldTitle, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGT applies the GT predicate on the "title" field.
|
||||||
|
func TitleGT(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleGTE applies the GTE predicate on the "title" field.
|
||||||
|
func TitleGTE(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLT applies the LT predicate on the "title" field.
|
||||||
|
func TitleLT(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleLTE applies the LTE predicate on the "title" field.
|
||||||
|
func TitleLTE(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContains applies the Contains predicate on the "title" field.
|
||||||
|
func TitleContains(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldContains(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||||
|
func TitleHasPrefix(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldHasPrefix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||||
|
func TitleHasSuffix(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldHasSuffix(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||||
|
func TitleEqualFold(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEqualFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||||
|
func TitleContainsFold(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldContainsFold(FieldTitle, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyEQ applies the EQ predicate on the "body" field.
|
||||||
|
func BodyEQ(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEQ(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyNEQ applies the NEQ predicate on the "body" field.
|
||||||
|
func BodyNEQ(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNEQ(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyIn applies the In predicate on the "body" field.
|
||||||
|
func BodyIn(vs ...string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldIn(FieldBody, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyNotIn applies the NotIn predicate on the "body" field.
|
||||||
|
func BodyNotIn(vs ...string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldNotIn(FieldBody, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyGT applies the GT predicate on the "body" field.
|
||||||
|
func BodyGT(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGT(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyGTE applies the GTE predicate on the "body" field.
|
||||||
|
func BodyGTE(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldGTE(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyLT applies the LT predicate on the "body" field.
|
||||||
|
func BodyLT(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLT(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyLTE applies the LTE predicate on the "body" field.
|
||||||
|
func BodyLTE(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldLTE(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyContains applies the Contains predicate on the "body" field.
|
||||||
|
func BodyContains(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldContains(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyHasPrefix applies the HasPrefix predicate on the "body" field.
|
||||||
|
func BodyHasPrefix(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldHasPrefix(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyHasSuffix applies the HasSuffix predicate on the "body" field.
|
||||||
|
func BodyHasSuffix(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldHasSuffix(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyEqualFold applies the EqualFold predicate on the "body" field.
|
||||||
|
func BodyEqualFold(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldEqualFold(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BodyContainsFold applies the ContainsFold predicate on the "body" field.
|
||||||
|
func BodyContainsFold(v string) predicate.Post {
|
||||||
|
return predicate.Post(sql.FieldContainsFold(FieldBody, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasCategory applies the HasEdge predicate on the "category" edge.
|
||||||
|
func HasCategory() predicate.Post {
|
||||||
|
return predicate.Post(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, CategoryTable, CategoryColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasCategoryWith applies the HasEdge predicate on the "category" edge with a given conditions (other predicates).
|
||||||
|
func HasCategoryWith(preds ...predicate.Category) predicate.Post {
|
||||||
|
return predicate.Post(func(s *sql.Selector) {
|
||||||
|
step := newCategoryStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProfile applies the HasEdge predicate on the "profile" edge.
|
||||||
|
func HasProfile() predicate.Post {
|
||||||
|
return predicate.Post(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ProfileTable, ProfileColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasProfileWith applies the HasEdge predicate on the "profile" edge with a given conditions (other predicates).
|
||||||
|
func HasProfileWith(preds ...predicate.Profile) predicate.Post {
|
||||||
|
return predicate.Post(func(s *sql.Selector) {
|
||||||
|
step := newProfileStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Post) predicate.Post {
|
||||||
|
return predicate.Post(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Post) predicate.Post {
|
||||||
|
return predicate.Post(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Post) predicate.Post {
|
||||||
|
return predicate.Post(sql.NotPredicates(p))
|
||||||
|
}
|
401
ent/post_create.go
Normal file
401
ent/post_create.go
Normal file
@ -0,0 +1,401 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostCreate is the builder for creating a Post entity.
|
||||||
|
type PostCreate struct {
|
||||||
|
config
|
||||||
|
mutation *PostMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pc *PostCreate) SetCreatedAt(t time.Time) *PostCreate {
|
||||||
|
pc.mutation.SetCreatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableCreatedAt(t *time.Time) *PostCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pc *PostCreate) SetUpdatedAt(t time.Time) *PostCreate {
|
||||||
|
pc.mutation.SetUpdatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableUpdatedAt(t *time.Time) *PostCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpires sets the "expires" field.
|
||||||
|
func (pc *PostCreate) SetExpires(b bool) *PostCreate {
|
||||||
|
pc.mutation.SetExpires(b)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpires sets the "expires" field if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableExpires(b *bool) *PostCreate {
|
||||||
|
if b != nil {
|
||||||
|
pc.SetExpires(*b)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpireTime sets the "expire_time" field.
|
||||||
|
func (pc *PostCreate) SetExpireTime(t time.Time) *PostCreate {
|
||||||
|
pc.mutation.SetExpireTime(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpireTime sets the "expire_time" field if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableExpireTime(t *time.Time) *PostCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetExpireTime(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (pc *PostCreate) SetTitle(s string) *PostCreate {
|
||||||
|
pc.mutation.SetTitle(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBody sets the "body" field.
|
||||||
|
func (pc *PostCreate) SetBody(s string) *PostCreate {
|
||||||
|
pc.mutation.SetBody(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (pc *PostCreate) SetID(u uuid.UUID) *PostCreate {
|
||||||
|
pc.mutation.SetID(u)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableID sets the "id" field if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableID(u *uuid.UUID) *PostCreate {
|
||||||
|
if u != nil {
|
||||||
|
pc.SetID(*u)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategoryID sets the "category" edge to the Category entity by ID.
|
||||||
|
func (pc *PostCreate) SetCategoryID(id uuid.UUID) *PostCreate {
|
||||||
|
pc.mutation.SetCategoryID(id)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableCategoryID(id *uuid.UUID) *PostCreate {
|
||||||
|
if id != nil {
|
||||||
|
pc = pc.SetCategoryID(*id)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" edge to the Category entity.
|
||||||
|
func (pc *PostCreate) SetCategory(c *Category) *PostCreate {
|
||||||
|
return pc.SetCategoryID(c.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfileID sets the "profile" edge to the Profile entity by ID.
|
||||||
|
func (pc *PostCreate) SetProfileID(id uuid.UUID) *PostCreate {
|
||||||
|
pc.mutation.SetProfileID(id)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil.
|
||||||
|
func (pc *PostCreate) SetNillableProfileID(id *uuid.UUID) *PostCreate {
|
||||||
|
if id != nil {
|
||||||
|
pc = pc.SetProfileID(*id)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfile sets the "profile" edge to the Profile entity.
|
||||||
|
func (pc *PostCreate) SetProfile(p *Profile) *PostCreate {
|
||||||
|
return pc.SetProfileID(p.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PostMutation object of the builder.
|
||||||
|
func (pc *PostCreate) Mutation() *PostMutation {
|
||||||
|
return pc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Post in the database.
|
||||||
|
func (pc *PostCreate) Save(ctx context.Context) (*Post, error) {
|
||||||
|
pc.defaults()
|
||||||
|
return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (pc *PostCreate) SaveX(ctx context.Context) *Post {
|
||||||
|
v, err := pc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pc *PostCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pc *PostCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := pc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pc *PostCreate) defaults() {
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
v := post.DefaultCreatedAt()
|
||||||
|
pc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := post.DefaultUpdatedAt()
|
||||||
|
pc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Expires(); !ok {
|
||||||
|
v := post.DefaultExpires
|
||||||
|
pc.mutation.SetExpires(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.ID(); !ok {
|
||||||
|
v := post.DefaultID()
|
||||||
|
pc.mutation.SetID(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pc *PostCreate) check() error {
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Post.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Expires(); !ok {
|
||||||
|
return &ValidationError{Name: "expires", err: errors.New(`ent: missing required field "Post.expires"`)}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Title(); !ok {
|
||||||
|
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Post.title"`)}
|
||||||
|
}
|
||||||
|
if v, ok := pc.mutation.Title(); ok {
|
||||||
|
if err := post.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.Body(); !ok {
|
||||||
|
return &ValidationError{Name: "body", err: errors.New(`ent: missing required field "Post.body"`)}
|
||||||
|
}
|
||||||
|
if v, ok := pc.mutation.Body(); ok {
|
||||||
|
if err := post.BodyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *PostCreate) sqlSave(ctx context.Context) (*Post, error) {
|
||||||
|
if err := pc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := pc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != nil {
|
||||||
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||||
|
_node.ID = *id
|
||||||
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pc.mutation.id = &_node.ID
|
||||||
|
pc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *PostCreate) createSpec() (*Post, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Post{config: pc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID))
|
||||||
|
)
|
||||||
|
if id, ok := pc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = &id
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(post.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(post.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Expires(); ok {
|
||||||
|
_spec.SetField(post.FieldExpires, field.TypeBool, value)
|
||||||
|
_node.Expires = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.ExpireTime(); ok {
|
||||||
|
_spec.SetField(post.FieldExpireTime, field.TypeTime, value)
|
||||||
|
_node.ExpireTime = &value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Title(); ok {
|
||||||
|
_spec.SetField(post.FieldTitle, field.TypeString, value)
|
||||||
|
_node.Title = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Body(); ok {
|
||||||
|
_spec.SetField(post.FieldBody, field.TypeString, value)
|
||||||
|
_node.Body = value
|
||||||
|
}
|
||||||
|
if nodes := pc.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.category_posts = &nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := pc.mutation.ProfileIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.profile_posts = &nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostCreateBulk is the builder for creating many Post entities in bulk.
|
||||||
|
type PostCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*PostCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Post entities in the database.
|
||||||
|
func (pcb *PostCreateBulk) Save(ctx context.Context) ([]*Post, error) {
|
||||||
|
if pcb.err != nil {
|
||||||
|
return nil, pcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||||
|
nodes := make([]*Post, len(pcb.builders))
|
||||||
|
mutators := make([]Mutator, len(pcb.builders))
|
||||||
|
for i := range pcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := pcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*PostMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pcb *PostCreateBulk) SaveX(ctx context.Context) []*Post {
|
||||||
|
v, err := pcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pcb *PostCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcb *PostCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := pcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/post_delete.go
Normal file
88
ent/post_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostDelete is the builder for deleting a Post entity.
|
||||||
|
type PostDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PostMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PostDelete builder.
|
||||||
|
func (pd *PostDelete) Where(ps ...predicate.Post) *PostDelete {
|
||||||
|
pd.mutation.Where(ps...)
|
||||||
|
return pd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (pd *PostDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pd *PostDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := pd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pd *PostDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID))
|
||||||
|
if ps := pd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
pd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostDeleteOne is the builder for deleting a single Post entity.
|
||||||
|
type PostDeleteOne struct {
|
||||||
|
pd *PostDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PostDelete builder.
|
||||||
|
func (pdo *PostDeleteOne) Where(ps ...predicate.Post) *PostDeleteOne {
|
||||||
|
pdo.pd.mutation.Where(ps...)
|
||||||
|
return pdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (pdo *PostDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := pdo.pd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{post.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pdo *PostDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := pdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
703
ent/post_query.go
Normal file
703
ent/post_query.go
Normal file
@ -0,0 +1,703 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostQuery is the builder for querying Post entities.
|
||||||
|
type PostQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []post.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Post
|
||||||
|
withCategory *CategoryQuery
|
||||||
|
withProfile *ProfileQuery
|
||||||
|
withFKs bool
|
||||||
|
modifiers []func(*sql.Selector)
|
||||||
|
loadTotal []func(context.Context, []*Post) error
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the PostQuery builder.
|
||||||
|
func (pq *PostQuery) Where(ps ...predicate.Post) *PostQuery {
|
||||||
|
pq.predicates = append(pq.predicates, ps...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (pq *PostQuery) Limit(limit int) *PostQuery {
|
||||||
|
pq.ctx.Limit = &limit
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (pq *PostQuery) Offset(offset int) *PostQuery {
|
||||||
|
pq.ctx.Offset = &offset
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (pq *PostQuery) Unique(unique bool) *PostQuery {
|
||||||
|
pq.ctx.Unique = &unique
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (pq *PostQuery) Order(o ...post.OrderOption) *PostQuery {
|
||||||
|
pq.order = append(pq.order, o...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryCategory chains the current query on the "category" edge.
|
||||||
|
func (pq *PostQuery) QueryCategory() *CategoryQuery {
|
||||||
|
query := (&CategoryClient{config: pq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := pq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(post.Table, post.FieldID, selector),
|
||||||
|
sqlgraph.To(category.Table, category.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, post.CategoryTable, post.CategoryColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryProfile chains the current query on the "profile" edge.
|
||||||
|
func (pq *PostQuery) QueryProfile() *ProfileQuery {
|
||||||
|
query := (&ProfileClient{config: pq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := pq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(post.Table, post.FieldID, selector),
|
||||||
|
sqlgraph.To(profile.Table, profile.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, post.ProfileTable, post.ProfileColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Post entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Post was found.
|
||||||
|
func (pq *PostQuery) First(ctx context.Context) (*Post, error) {
|
||||||
|
nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{post.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) FirstX(ctx context.Context) *Post {
|
||||||
|
node, err := pq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Post ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Post ID was found.
|
||||||
|
func (pq *PostQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{post.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := pq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Post entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Post entity is found.
|
||||||
|
// Returns a *NotFoundError when no Post entities are found.
|
||||||
|
func (pq *PostQuery) Only(ctx context.Context) (*Post, error) {
|
||||||
|
nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{post.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{post.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) OnlyX(ctx context.Context) *Post {
|
||||||
|
node, err := pq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Post ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Post ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (pq *PostQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{post.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{post.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := pq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Posts.
|
||||||
|
func (pq *PostQuery) All(ctx context.Context) ([]*Post, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryAll)
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Post, *PostQuery]()
|
||||||
|
return withInterceptors[[]*Post](ctx, pq, qr, pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) AllX(ctx context.Context) []*Post {
|
||||||
|
nodes, err := pq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Post IDs.
|
||||||
|
func (pq *PostQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||||
|
if pq.ctx.Unique == nil && pq.path != nil {
|
||||||
|
pq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryIDs)
|
||||||
|
if err = pq.Select(post.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||||
|
ids, err := pq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (pq *PostQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryCount)
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, pq, querierCount[*PostQuery](), pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := pq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (pq *PostQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := pq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (pq *PostQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := pq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the PostQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (pq *PostQuery) Clone() *PostQuery {
|
||||||
|
if pq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &PostQuery{
|
||||||
|
config: pq.config,
|
||||||
|
ctx: pq.ctx.Clone(),
|
||||||
|
order: append([]post.OrderOption{}, pq.order...),
|
||||||
|
inters: append([]Interceptor{}, pq.inters...),
|
||||||
|
predicates: append([]predicate.Post{}, pq.predicates...),
|
||||||
|
withCategory: pq.withCategory.Clone(),
|
||||||
|
withProfile: pq.withProfile.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: pq.sql.Clone(),
|
||||||
|
path: pq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithCategory tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "category" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pq *PostQuery) WithCategory(opts ...func(*CategoryQuery)) *PostQuery {
|
||||||
|
query := (&CategoryClient{config: pq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
pq.withCategory = query
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithProfile tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "profile" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pq *PostQuery) WithProfile(opts ...func(*ProfileQuery)) *PostQuery {
|
||||||
|
query := (&ProfileClient{config: pq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
pq.withProfile = query
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Post.Query().
|
||||||
|
// GroupBy(post.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *PostQuery) GroupBy(field string, fields ...string) *PostGroupBy {
|
||||||
|
pq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &PostGroupBy{build: pq}
|
||||||
|
grbuild.flds = &pq.ctx.Fields
|
||||||
|
grbuild.label = post.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Post.Query().
|
||||||
|
// Select(post.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *PostQuery) Select(fields ...string) *PostSelect {
|
||||||
|
pq.ctx.Fields = append(pq.ctx.Fields, fields...)
|
||||||
|
sbuild := &PostSelect{PostQuery: pq}
|
||||||
|
sbuild.label = post.Label
|
||||||
|
sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a PostSelect configured with the given aggregations.
|
||||||
|
func (pq *PostQuery) Aggregate(fns ...AggregateFunc) *PostSelect {
|
||||||
|
return pq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range pq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, pq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range pq.ctx.Fields {
|
||||||
|
if !post.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pq.path != nil {
|
||||||
|
prev, err := pq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Post, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Post{}
|
||||||
|
withFKs = pq.withFKs
|
||||||
|
_spec = pq.querySpec()
|
||||||
|
loadedTypes = [2]bool{
|
||||||
|
pq.withCategory != nil,
|
||||||
|
pq.withProfile != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if pq.withCategory != nil || pq.withProfile != nil {
|
||||||
|
withFKs = true
|
||||||
|
}
|
||||||
|
if withFKs {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, post.ForeignKeys...)
|
||||||
|
}
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Post).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Post{config: pq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if len(pq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = pq.modifiers
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := pq.withCategory; query != nil {
|
||||||
|
if err := pq.loadCategory(ctx, query, nodes, nil,
|
||||||
|
func(n *Post, e *Category) { n.Edges.Category = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := pq.withProfile; query != nil {
|
||||||
|
if err := pq.loadProfile(ctx, query, nodes, nil,
|
||||||
|
func(n *Post, e *Profile) { n.Edges.Profile = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range pq.loadTotal {
|
||||||
|
if err := pq.loadTotal[i](ctx, nodes); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) loadCategory(ctx context.Context, query *CategoryQuery, nodes []*Post, init func(*Post), assign func(*Post, *Category)) error {
|
||||||
|
ids := make([]uuid.UUID, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID][]*Post)
|
||||||
|
for i := range nodes {
|
||||||
|
if nodes[i].category_posts == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fk := *nodes[i].category_posts
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(category.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "category_posts" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (pq *PostQuery) loadProfile(ctx context.Context, query *ProfileQuery, nodes []*Post, init func(*Post), assign func(*Post, *Profile)) error {
|
||||||
|
ids := make([]uuid.UUID, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID][]*Post)
|
||||||
|
for i := range nodes {
|
||||||
|
if nodes[i].profile_posts == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fk := *nodes[i].profile_posts
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(profile.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "profile_posts" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := pq.querySpec()
|
||||||
|
if len(pq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = pq.modifiers
|
||||||
|
}
|
||||||
|
_spec.Node.Columns = pq.ctx.Fields
|
||||||
|
if len(pq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, pq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID))
|
||||||
|
_spec.From = pq.sql
|
||||||
|
if unique := pq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if pq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := pq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, post.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != post.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := pq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := pq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *PostQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(pq.driver.Dialect())
|
||||||
|
t1 := builder.Table(post.Table)
|
||||||
|
columns := pq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = post.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if pq.sql != nil {
|
||||||
|
selector = pq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if pq.ctx.Unique != nil && *pq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range pq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range pq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.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.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostGroupBy is the group-by builder for Post entities.
|
||||||
|
type PostGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *PostQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (pgb *PostGroupBy) Aggregate(fns ...AggregateFunc) *PostGroupBy {
|
||||||
|
pgb.fns = append(pgb.fns, fns...)
|
||||||
|
return pgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (pgb *PostGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, pgb.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := pgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*PostQuery, *PostGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pgb *PostGroupBy) sqlScan(ctx context.Context, root *PostQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(pgb.fns))
|
||||||
|
for _, fn := range pgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns))
|
||||||
|
for _, f := range *pgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*pgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostSelect is the builder for selecting fields of Post entities.
|
||||||
|
type PostSelect struct {
|
||||||
|
*PostQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (ps *PostSelect) Aggregate(fns ...AggregateFunc) *PostSelect {
|
||||||
|
ps.fns = append(ps.fns, fns...)
|
||||||
|
return ps
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (ps *PostSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, ps.ctx, ent.OpQuerySelect)
|
||||||
|
if err := ps.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*PostQuery, *PostSelect](ctx, ps.PostQuery, ps, ps.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *PostSelect) sqlScan(ctx context.Context, root *PostQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(ps.fns))
|
||||||
|
for _, fn := range ps.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*ps.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := ps.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
639
ent/post_update.go
Normal file
639
ent/post_update.go
Normal file
@ -0,0 +1,639 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostUpdate is the builder for updating Post entities.
|
||||||
|
type PostUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PostMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PostUpdate builder.
|
||||||
|
func (pu *PostUpdate) Where(ps ...predicate.Post) *PostUpdate {
|
||||||
|
pu.mutation.Where(ps...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pu *PostUpdate) SetUpdatedAt(t time.Time) *PostUpdate {
|
||||||
|
pu.mutation.SetUpdatedAt(t)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (pu *PostUpdate) ClearUpdatedAt() *PostUpdate {
|
||||||
|
pu.mutation.ClearUpdatedAt()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpires sets the "expires" field.
|
||||||
|
func (pu *PostUpdate) SetExpires(b bool) *PostUpdate {
|
||||||
|
pu.mutation.SetExpires(b)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpires sets the "expires" field if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableExpires(b *bool) *PostUpdate {
|
||||||
|
if b != nil {
|
||||||
|
pu.SetExpires(*b)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpireTime sets the "expire_time" field.
|
||||||
|
func (pu *PostUpdate) SetExpireTime(t time.Time) *PostUpdate {
|
||||||
|
pu.mutation.SetExpireTime(t)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpireTime sets the "expire_time" field if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableExpireTime(t *time.Time) *PostUpdate {
|
||||||
|
if t != nil {
|
||||||
|
pu.SetExpireTime(*t)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpireTime clears the value of the "expire_time" field.
|
||||||
|
func (pu *PostUpdate) ClearExpireTime() *PostUpdate {
|
||||||
|
pu.mutation.ClearExpireTime()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (pu *PostUpdate) SetTitle(s string) *PostUpdate {
|
||||||
|
pu.mutation.SetTitle(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableTitle(s *string) *PostUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetTitle(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBody sets the "body" field.
|
||||||
|
func (pu *PostUpdate) SetBody(s string) *PostUpdate {
|
||||||
|
pu.mutation.SetBody(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableBody sets the "body" field if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableBody(s *string) *PostUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetBody(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategoryID sets the "category" edge to the Category entity by ID.
|
||||||
|
func (pu *PostUpdate) SetCategoryID(id uuid.UUID) *PostUpdate {
|
||||||
|
pu.mutation.SetCategoryID(id)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableCategoryID(id *uuid.UUID) *PostUpdate {
|
||||||
|
if id != nil {
|
||||||
|
pu = pu.SetCategoryID(*id)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" edge to the Category entity.
|
||||||
|
func (pu *PostUpdate) SetCategory(c *Category) *PostUpdate {
|
||||||
|
return pu.SetCategoryID(c.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfileID sets the "profile" edge to the Profile entity by ID.
|
||||||
|
func (pu *PostUpdate) SetProfileID(id uuid.UUID) *PostUpdate {
|
||||||
|
pu.mutation.SetProfileID(id)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil.
|
||||||
|
func (pu *PostUpdate) SetNillableProfileID(id *uuid.UUID) *PostUpdate {
|
||||||
|
if id != nil {
|
||||||
|
pu = pu.SetProfileID(*id)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfile sets the "profile" edge to the Profile entity.
|
||||||
|
func (pu *PostUpdate) SetProfile(p *Profile) *PostUpdate {
|
||||||
|
return pu.SetProfileID(p.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PostMutation object of the builder.
|
||||||
|
func (pu *PostUpdate) Mutation() *PostMutation {
|
||||||
|
return pu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCategory clears the "category" edge to the Category entity.
|
||||||
|
func (pu *PostUpdate) ClearCategory() *PostUpdate {
|
||||||
|
pu.mutation.ClearCategory()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProfile clears the "profile" edge to the Profile entity.
|
||||||
|
func (pu *PostUpdate) ClearProfile() *PostUpdate {
|
||||||
|
pu.mutation.ClearProfile()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (pu *PostUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
pu.defaults()
|
||||||
|
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pu *PostUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := pu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pu *PostUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pu *PostUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := pu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pu *PostUpdate) defaults() {
|
||||||
|
if _, ok := pu.mutation.UpdatedAt(); !ok && !pu.mutation.UpdatedAtCleared() {
|
||||||
|
v := post.UpdateDefaultUpdatedAt()
|
||||||
|
pu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pu *PostUpdate) check() error {
|
||||||
|
if v, ok := pu.mutation.Title(); ok {
|
||||||
|
if err := post.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := pu.mutation.Body(); ok {
|
||||||
|
if err := post.BodyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pu *PostUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := pu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID))
|
||||||
|
if ps := pu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(post.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(post.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Expires(); ok {
|
||||||
|
_spec.SetField(post.FieldExpires, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.ExpireTime(); ok {
|
||||||
|
_spec.SetField(post.FieldExpireTime, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.ExpireTimeCleared() {
|
||||||
|
_spec.ClearField(post.FieldExpireTime, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Title(); ok {
|
||||||
|
_spec.SetField(post.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Body(); ok {
|
||||||
|
_spec.SetField(post.FieldBody, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.CategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if pu.mutation.ProfileCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.ProfileIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{post.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
pu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostUpdateOne is the builder for updating a single Post entity.
|
||||||
|
type PostUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *PostMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (puo *PostUpdateOne) SetUpdatedAt(t time.Time) *PostUpdateOne {
|
||||||
|
puo.mutation.SetUpdatedAt(t)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (puo *PostUpdateOne) ClearUpdatedAt() *PostUpdateOne {
|
||||||
|
puo.mutation.ClearUpdatedAt()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpires sets the "expires" field.
|
||||||
|
func (puo *PostUpdateOne) SetExpires(b bool) *PostUpdateOne {
|
||||||
|
puo.mutation.SetExpires(b)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpires sets the "expires" field if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableExpires(b *bool) *PostUpdateOne {
|
||||||
|
if b != nil {
|
||||||
|
puo.SetExpires(*b)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExpireTime sets the "expire_time" field.
|
||||||
|
func (puo *PostUpdateOne) SetExpireTime(t time.Time) *PostUpdateOne {
|
||||||
|
puo.mutation.SetExpireTime(t)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableExpireTime sets the "expire_time" field if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableExpireTime(t *time.Time) *PostUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
puo.SetExpireTime(*t)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearExpireTime clears the value of the "expire_time" field.
|
||||||
|
func (puo *PostUpdateOne) ClearExpireTime() *PostUpdateOne {
|
||||||
|
puo.mutation.ClearExpireTime()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTitle sets the "title" field.
|
||||||
|
func (puo *PostUpdateOne) SetTitle(s string) *PostUpdateOne {
|
||||||
|
puo.mutation.SetTitle(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableTitle(s *string) *PostUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetTitle(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBody sets the "body" field.
|
||||||
|
func (puo *PostUpdateOne) SetBody(s string) *PostUpdateOne {
|
||||||
|
puo.mutation.SetBody(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableBody sets the "body" field if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableBody(s *string) *PostUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetBody(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategoryID sets the "category" edge to the Category entity by ID.
|
||||||
|
func (puo *PostUpdateOne) SetCategoryID(id uuid.UUID) *PostUpdateOne {
|
||||||
|
puo.mutation.SetCategoryID(id)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCategoryID sets the "category" edge to the Category entity by ID if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableCategoryID(id *uuid.UUID) *PostUpdateOne {
|
||||||
|
if id != nil {
|
||||||
|
puo = puo.SetCategoryID(*id)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCategory sets the "category" edge to the Category entity.
|
||||||
|
func (puo *PostUpdateOne) SetCategory(c *Category) *PostUpdateOne {
|
||||||
|
return puo.SetCategoryID(c.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfileID sets the "profile" edge to the Profile entity by ID.
|
||||||
|
func (puo *PostUpdateOne) SetProfileID(id uuid.UUID) *PostUpdateOne {
|
||||||
|
puo.mutation.SetProfileID(id)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableProfileID sets the "profile" edge to the Profile entity by ID if the given value is not nil.
|
||||||
|
func (puo *PostUpdateOne) SetNillableProfileID(id *uuid.UUID) *PostUpdateOne {
|
||||||
|
if id != nil {
|
||||||
|
puo = puo.SetProfileID(*id)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfile sets the "profile" edge to the Profile entity.
|
||||||
|
func (puo *PostUpdateOne) SetProfile(p *Profile) *PostUpdateOne {
|
||||||
|
return puo.SetProfileID(p.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the PostMutation object of the builder.
|
||||||
|
func (puo *PostUpdateOne) Mutation() *PostMutation {
|
||||||
|
return puo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCategory clears the "category" edge to the Category entity.
|
||||||
|
func (puo *PostUpdateOne) ClearCategory() *PostUpdateOne {
|
||||||
|
puo.mutation.ClearCategory()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearProfile clears the "profile" edge to the Profile entity.
|
||||||
|
func (puo *PostUpdateOne) ClearProfile() *PostUpdateOne {
|
||||||
|
puo.mutation.ClearProfile()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the PostUpdate builder.
|
||||||
|
func (puo *PostUpdateOne) Where(ps ...predicate.Post) *PostUpdateOne {
|
||||||
|
puo.mutation.Where(ps...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (puo *PostUpdateOne) Select(field string, fields ...string) *PostUpdateOne {
|
||||||
|
puo.fields = append([]string{field}, fields...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Post entity.
|
||||||
|
func (puo *PostUpdateOne) Save(ctx context.Context) (*Post, error) {
|
||||||
|
puo.defaults()
|
||||||
|
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (puo *PostUpdateOne) SaveX(ctx context.Context) *Post {
|
||||||
|
node, err := puo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (puo *PostUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := puo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (puo *PostUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := puo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (puo *PostUpdateOne) defaults() {
|
||||||
|
if _, ok := puo.mutation.UpdatedAt(); !ok && !puo.mutation.UpdatedAtCleared() {
|
||||||
|
v := post.UpdateDefaultUpdatedAt()
|
||||||
|
puo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (puo *PostUpdateOne) check() error {
|
||||||
|
if v, ok := puo.mutation.Title(); ok {
|
||||||
|
if err := post.TitleValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Post.title": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := puo.mutation.Body(); ok {
|
||||||
|
if err := post.BodyValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "body", err: fmt.Errorf(`ent: validator failed for field "Post.body": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (puo *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error) {
|
||||||
|
if err := puo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID))
|
||||||
|
id, ok := puo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Post.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := puo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, post.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !post.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != post.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := puo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(post.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(post.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Expires(); ok {
|
||||||
|
_spec.SetField(post.FieldExpires, field.TypeBool, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.ExpireTime(); ok {
|
||||||
|
_spec.SetField(post.FieldExpireTime, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.ExpireTimeCleared() {
|
||||||
|
_spec.ClearField(post.FieldExpireTime, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Title(); ok {
|
||||||
|
_spec.SetField(post.FieldTitle, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Body(); ok {
|
||||||
|
_spec.SetField(post.FieldBody, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.CategoryCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.CategoryIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.CategoryTable,
|
||||||
|
Columns: []string{post.CategoryColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(category.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if puo.mutation.ProfileCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.ProfileIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: post.ProfileTable,
|
||||||
|
Columns: []string{post.ProfileColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Post{config: puo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{post.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
puo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
16
ent/predicate/predicate.go
Normal file
16
ent/predicate/predicate.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Category is the predicate function for category builders.
|
||||||
|
type Category func(*sql.Selector)
|
||||||
|
|
||||||
|
// Post is the predicate function for post builders.
|
||||||
|
type Post func(*sql.Selector)
|
||||||
|
|
||||||
|
// Profile is the predicate function for profile builders.
|
||||||
|
type Profile func(*sql.Selector)
|
243
ent/privacy/privacy.go
Normal file
243
ent/privacy/privacy.go
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package privacy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent"
|
||||||
|
|
||||||
|
"entgo.io/ent/entql"
|
||||||
|
"entgo.io/ent/privacy"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Allow may be returned by rules to indicate that the policy
|
||||||
|
// evaluation should terminate with allow decision.
|
||||||
|
Allow = privacy.Allow
|
||||||
|
|
||||||
|
// Deny may be returned by rules to indicate that the policy
|
||||||
|
// evaluation should terminate with deny decision.
|
||||||
|
Deny = privacy.Deny
|
||||||
|
|
||||||
|
// Skip may be returned by rules to indicate that the policy
|
||||||
|
// evaluation should continue to the next rule.
|
||||||
|
Skip = privacy.Skip
|
||||||
|
)
|
||||||
|
|
||||||
|
// Allowf returns a formatted wrapped Allow decision.
|
||||||
|
func Allowf(format string, a ...any) error {
|
||||||
|
return privacy.Allowf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Denyf returns a formatted wrapped Deny decision.
|
||||||
|
func Denyf(format string, a ...any) error {
|
||||||
|
return privacy.Denyf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipf returns a formatted wrapped Skip decision.
|
||||||
|
func Skipf(format string, a ...any) error {
|
||||||
|
return privacy.Skipf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecisionContext creates a new context from the given parent context with
|
||||||
|
// a policy decision attach to it.
|
||||||
|
func DecisionContext(parent context.Context, decision error) context.Context {
|
||||||
|
return privacy.DecisionContext(parent, decision)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecisionFromContext retrieves the policy decision from the context.
|
||||||
|
func DecisionFromContext(ctx context.Context) (error, bool) {
|
||||||
|
return privacy.DecisionFromContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Policy groups query and mutation policies.
|
||||||
|
Policy = privacy.Policy
|
||||||
|
|
||||||
|
// QueryRule defines the interface deciding whether a
|
||||||
|
// query is allowed and optionally modify it.
|
||||||
|
QueryRule = privacy.QueryRule
|
||||||
|
// QueryPolicy combines multiple query rules into a single policy.
|
||||||
|
QueryPolicy = privacy.QueryPolicy
|
||||||
|
|
||||||
|
// MutationRule defines the interface which decides whether a
|
||||||
|
// mutation is allowed and optionally modifies it.
|
||||||
|
MutationRule = privacy.MutationRule
|
||||||
|
// MutationPolicy combines multiple mutation rules into a single policy.
|
||||||
|
MutationPolicy = privacy.MutationPolicy
|
||||||
|
// MutationRuleFunc type is an adapter which allows the use of
|
||||||
|
// ordinary functions as mutation rules.
|
||||||
|
MutationRuleFunc = privacy.MutationRuleFunc
|
||||||
|
|
||||||
|
// QueryMutationRule is an interface which groups query and mutation rules.
|
||||||
|
QueryMutationRule = privacy.QueryMutationRule
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryRuleFunc type is an adapter to allow the use of
|
||||||
|
// ordinary functions as query rules.
|
||||||
|
type QueryRuleFunc func(context.Context, ent.Query) error
|
||||||
|
|
||||||
|
// Eval returns f(ctx, q).
|
||||||
|
func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlwaysAllowRule returns a rule that returns an allow decision.
|
||||||
|
func AlwaysAllowRule() QueryMutationRule {
|
||||||
|
return privacy.AlwaysAllowRule()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlwaysDenyRule returns a rule that returns a deny decision.
|
||||||
|
func AlwaysDenyRule() QueryMutationRule {
|
||||||
|
return privacy.AlwaysDenyRule()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ContextQueryMutationRule creates a query/mutation rule from a context eval func.
|
||||||
|
func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule {
|
||||||
|
return privacy.ContextQueryMutationRule(eval)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnMutationOperation evaluates the given rule only on a given mutation operation.
|
||||||
|
func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule {
|
||||||
|
return privacy.OnMutationOperation(rule, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DenyMutationOperationRule returns a rule denying specified mutation operation.
|
||||||
|
func DenyMutationOperationRule(op ent.Op) MutationRule {
|
||||||
|
rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error {
|
||||||
|
return Denyf("ent/privacy: operation %s is not allowed", m.Op())
|
||||||
|
})
|
||||||
|
return OnMutationOperation(rule, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CategoryQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a query rule.
|
||||||
|
type CategoryQueryRuleFunc func(context.Context, *ent.CategoryQuery) error
|
||||||
|
|
||||||
|
// EvalQuery return f(ctx, q).
|
||||||
|
func (f CategoryQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.CategoryQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected query type %T, expect *ent.CategoryQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CategoryMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a mutation rule.
|
||||||
|
type CategoryMutationRuleFunc func(context.Context, *ent.CategoryMutation) error
|
||||||
|
|
||||||
|
// EvalMutation calls f(ctx, m).
|
||||||
|
func (f CategoryMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||||
|
if m, ok := m.(*ent.CategoryMutation); ok {
|
||||||
|
return f(ctx, m)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CategoryMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The PostQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a query rule.
|
||||||
|
type PostQueryRuleFunc func(context.Context, *ent.PostQuery) error
|
||||||
|
|
||||||
|
// EvalQuery return f(ctx, q).
|
||||||
|
func (f PostQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.PostQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected query type %T, expect *ent.PostQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The PostMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a mutation rule.
|
||||||
|
type PostMutationRuleFunc func(context.Context, *ent.PostMutation) error
|
||||||
|
|
||||||
|
// EvalMutation calls f(ctx, m).
|
||||||
|
func (f PostMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||||
|
if m, ok := m.(*ent.PostMutation); ok {
|
||||||
|
return f(ctx, m)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PostMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ProfileQueryRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a query rule.
|
||||||
|
type ProfileQueryRuleFunc func(context.Context, *ent.ProfileQuery) error
|
||||||
|
|
||||||
|
// EvalQuery return f(ctx, q).
|
||||||
|
func (f ProfileQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||||
|
if q, ok := q.(*ent.ProfileQuery); ok {
|
||||||
|
return f(ctx, q)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected query type %T, expect *ent.ProfileQuery", q)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ProfileMutationRuleFunc type is an adapter to allow the use of ordinary
|
||||||
|
// functions as a mutation rule.
|
||||||
|
type ProfileMutationRuleFunc func(context.Context, *ent.ProfileMutation) error
|
||||||
|
|
||||||
|
// EvalMutation calls f(ctx, m).
|
||||||
|
func (f ProfileMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||||
|
if m, ok := m.(*ent.ProfileMutation); ok {
|
||||||
|
return f(ctx, m)
|
||||||
|
}
|
||||||
|
return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ProfileMutation", m)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Filter is the interface that wraps the Where function
|
||||||
|
// for filtering nodes in queries and mutations.
|
||||||
|
Filter interface {
|
||||||
|
// Where applies a filter on the executed query/mutation.
|
||||||
|
Where(entql.P)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The FilterFunc type is an adapter that allows the use of ordinary
|
||||||
|
// functions as filters for query and mutation types.
|
||||||
|
FilterFunc func(context.Context, Filter) error
|
||||||
|
)
|
||||||
|
|
||||||
|
// EvalQuery calls f(ctx, q) if the query implements the Filter interface, otherwise it is denied.
|
||||||
|
func (f FilterFunc) EvalQuery(ctx context.Context, q ent.Query) error {
|
||||||
|
fr, err := queryFilter(q)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return f(ctx, fr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EvalMutation calls f(ctx, q) if the mutation implements the Filter interface, otherwise it is denied.
|
||||||
|
func (f FilterFunc) EvalMutation(ctx context.Context, m ent.Mutation) error {
|
||||||
|
fr, err := mutationFilter(m)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return f(ctx, fr)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ QueryMutationRule = FilterFunc(nil)
|
||||||
|
|
||||||
|
func queryFilter(q ent.Query) (Filter, error) {
|
||||||
|
switch q := q.(type) {
|
||||||
|
case *ent.CategoryQuery:
|
||||||
|
return q.Filter(), nil
|
||||||
|
case *ent.PostQuery:
|
||||||
|
return q.Filter(), nil
|
||||||
|
case *ent.ProfileQuery:
|
||||||
|
return q.Filter(), nil
|
||||||
|
default:
|
||||||
|
return nil, Denyf("ent/privacy: unexpected query type %T for query filter", q)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mutationFilter(m ent.Mutation) (Filter, error) {
|
||||||
|
switch m := m.(type) {
|
||||||
|
case *ent.CategoryMutation:
|
||||||
|
return m.Filter(), nil
|
||||||
|
case *ent.PostMutation:
|
||||||
|
return m.Filter(), nil
|
||||||
|
case *ent.ProfileMutation:
|
||||||
|
return m.Filter(), nil
|
||||||
|
default:
|
||||||
|
return nil, Denyf("ent/privacy: unexpected mutation type %T for mutation filter", m)
|
||||||
|
}
|
||||||
|
}
|
205
ent/profile.go
Normal file
205
ent/profile.go
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Profile is the model entity for the Profile schema.
|
||||||
|
type Profile struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID uuid.UUID `json:"id,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// Name holds the value of the "name" field.
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
// Address holds the value of the "address" field.
|
||||||
|
Address string `json:"address,omitempty"`
|
||||||
|
// Phone holds the value of the "phone" field.
|
||||||
|
Phone string `json:"phone,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the ProfileQuery when eager-loading is set.
|
||||||
|
Edges ProfileEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type ProfileEdges struct {
|
||||||
|
// Posts holds the value of the posts edge.
|
||||||
|
Posts []*Post `json:"posts,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
// totalCount holds the count of the edges above.
|
||||||
|
totalCount [1]map[string]int
|
||||||
|
|
||||||
|
namedPosts map[string][]*Post
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostsOrErr returns the Posts value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e ProfileEdges) PostsOrErr() ([]*Post, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.Posts, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "posts"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Profile) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case profile.FieldName, profile.FieldAddress, profile.FieldPhone:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case profile.FieldCreatedAt, profile.FieldUpdatedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
case profile.FieldID:
|
||||||
|
values[i] = new(uuid.UUID)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Profile fields.
|
||||||
|
func (pr *Profile) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case profile.FieldID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
pr.ID = *value
|
||||||
|
}
|
||||||
|
case profile.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pr.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case profile.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pr.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case profile.FieldName:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pr.Name = value.String
|
||||||
|
}
|
||||||
|
case profile.FieldAddress:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field address", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pr.Address = value.String
|
||||||
|
}
|
||||||
|
case profile.FieldPhone:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field phone", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
pr.Phone = value.String
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
pr.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Profile.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (pr *Profile) Value(name string) (ent.Value, error) {
|
||||||
|
return pr.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts queries the "posts" edge of the Profile entity.
|
||||||
|
func (pr *Profile) QueryPosts() *PostQuery {
|
||||||
|
return NewProfileClient(pr.config).QueryPosts(pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Profile.
|
||||||
|
// Note that you need to call Profile.Unwrap() before calling this method if this Profile
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (pr *Profile) Update() *ProfileUpdateOne {
|
||||||
|
return NewProfileClient(pr.config).UpdateOne(pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Profile entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (pr *Profile) Unwrap() *Profile {
|
||||||
|
_tx, ok := pr.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Profile is not a transactional entity")
|
||||||
|
}
|
||||||
|
pr.config.driver = _tx.drv
|
||||||
|
return pr
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (pr *Profile) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Profile(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", pr.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(pr.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(pr.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("name=")
|
||||||
|
builder.WriteString(pr.Name)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("address=")
|
||||||
|
builder.WriteString(pr.Address)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("phone=")
|
||||||
|
builder.WriteString(pr.Phone)
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// NamedPosts returns the Posts named value or an error if the edge was not
|
||||||
|
// loaded in eager-loading with this name.
|
||||||
|
func (pr *Profile) NamedPosts(name string) ([]*Post, error) {
|
||||||
|
if pr.Edges.namedPosts == nil {
|
||||||
|
return nil, &NotLoadedError{edge: name}
|
||||||
|
}
|
||||||
|
nodes, ok := pr.Edges.namedPosts[name]
|
||||||
|
if !ok {
|
||||||
|
return nil, &NotLoadedError{edge: name}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pr *Profile) appendNamedPosts(name string, edges ...*Post) {
|
||||||
|
if pr.Edges.namedPosts == nil {
|
||||||
|
pr.Edges.namedPosts = make(map[string][]*Post)
|
||||||
|
}
|
||||||
|
if len(edges) == 0 {
|
||||||
|
pr.Edges.namedPosts[name] = []*Post{}
|
||||||
|
} else {
|
||||||
|
pr.Edges.namedPosts[name] = append(pr.Edges.namedPosts[name], edges...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Profiles is a parsable slice of Profile.
|
||||||
|
type Profiles []*Profile
|
124
ent/profile/profile.go
Normal file
124
ent/profile/profile.go
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package profile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the profile type in the database.
|
||||||
|
Label = "profile"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldAddress holds the string denoting the address field in the database.
|
||||||
|
FieldAddress = "address"
|
||||||
|
// FieldPhone holds the string denoting the phone field in the database.
|
||||||
|
FieldPhone = "phone"
|
||||||
|
// EdgePosts holds the string denoting the posts edge name in mutations.
|
||||||
|
EdgePosts = "posts"
|
||||||
|
// Table holds the table name of the profile in the database.
|
||||||
|
Table = "profiles"
|
||||||
|
// PostsTable is the table that holds the posts relation/edge.
|
||||||
|
PostsTable = "posts"
|
||||||
|
// PostsInverseTable is the table name for the Post entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "post" package.
|
||||||
|
PostsInverseTable = "posts"
|
||||||
|
// PostsColumn is the table column denoting the posts relation/edge.
|
||||||
|
PostsColumn = "profile_posts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for profile fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldName,
|
||||||
|
FieldAddress,
|
||||||
|
FieldPhone,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// DefaultID holds the default value on creation for the "id" field.
|
||||||
|
DefaultID func() uuid.UUID
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the Profile queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByName orders the results by the name field.
|
||||||
|
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByAddress orders the results by the address field.
|
||||||
|
func ByAddress(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldAddress, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPhone orders the results by the phone field.
|
||||||
|
func ByPhone(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPhone, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPostsCount orders the results by posts count.
|
||||||
|
func ByPostsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborsCount(s, newPostsStep(), opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPosts orders the results by posts terms.
|
||||||
|
func ByPosts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newPostsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newPostsStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(PostsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn),
|
||||||
|
)
|
||||||
|
}
|
435
ent/profile/where.go
Normal file
435
ent/profile/where.go
Normal file
@ -0,0 +1,435 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package profile
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id uuid.UUID) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Address applies equality check predicate on the "address" field. It's identical to AddressEQ.
|
||||||
|
func Address(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Phone applies equality check predicate on the "phone" field. It's identical to PhoneEQ.
|
||||||
|
func Phone(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIsNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIsNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotNull(FieldUpdatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldName, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContains(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasPrefix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasSuffix(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIsNil applies the IsNil predicate on the "name" field.
|
||||||
|
func NameIsNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIsNull(FieldName))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotNil applies the NotNil predicate on the "name" field.
|
||||||
|
func NameNotNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotNull(FieldName))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEqualFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContainsFold(FieldName, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressEQ applies the EQ predicate on the "address" field.
|
||||||
|
func AddressEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressNEQ applies the NEQ predicate on the "address" field.
|
||||||
|
func AddressNEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressIn applies the In predicate on the "address" field.
|
||||||
|
func AddressIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldAddress, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressNotIn applies the NotIn predicate on the "address" field.
|
||||||
|
func AddressNotIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldAddress, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressGT applies the GT predicate on the "address" field.
|
||||||
|
func AddressGT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressGTE applies the GTE predicate on the "address" field.
|
||||||
|
func AddressGTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressLT applies the LT predicate on the "address" field.
|
||||||
|
func AddressLT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressLTE applies the LTE predicate on the "address" field.
|
||||||
|
func AddressLTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressContains applies the Contains predicate on the "address" field.
|
||||||
|
func AddressContains(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContains(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressHasPrefix applies the HasPrefix predicate on the "address" field.
|
||||||
|
func AddressHasPrefix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasPrefix(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressHasSuffix applies the HasSuffix predicate on the "address" field.
|
||||||
|
func AddressHasSuffix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasSuffix(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressIsNil applies the IsNil predicate on the "address" field.
|
||||||
|
func AddressIsNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIsNull(FieldAddress))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressNotNil applies the NotNil predicate on the "address" field.
|
||||||
|
func AddressNotNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotNull(FieldAddress))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressEqualFold applies the EqualFold predicate on the "address" field.
|
||||||
|
func AddressEqualFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEqualFold(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddressContainsFold applies the ContainsFold predicate on the "address" field.
|
||||||
|
func AddressContainsFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContainsFold(FieldAddress, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneEQ applies the EQ predicate on the "phone" field.
|
||||||
|
func PhoneEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEQ(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneNEQ applies the NEQ predicate on the "phone" field.
|
||||||
|
func PhoneNEQ(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNEQ(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneIn applies the In predicate on the "phone" field.
|
||||||
|
func PhoneIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIn(FieldPhone, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneNotIn applies the NotIn predicate on the "phone" field.
|
||||||
|
func PhoneNotIn(vs ...string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotIn(FieldPhone, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneGT applies the GT predicate on the "phone" field.
|
||||||
|
func PhoneGT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGT(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneGTE applies the GTE predicate on the "phone" field.
|
||||||
|
func PhoneGTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldGTE(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneLT applies the LT predicate on the "phone" field.
|
||||||
|
func PhoneLT(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLT(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneLTE applies the LTE predicate on the "phone" field.
|
||||||
|
func PhoneLTE(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldLTE(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneContains applies the Contains predicate on the "phone" field.
|
||||||
|
func PhoneContains(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContains(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneHasPrefix applies the HasPrefix predicate on the "phone" field.
|
||||||
|
func PhoneHasPrefix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasPrefix(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneHasSuffix applies the HasSuffix predicate on the "phone" field.
|
||||||
|
func PhoneHasSuffix(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldHasSuffix(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneIsNil applies the IsNil predicate on the "phone" field.
|
||||||
|
func PhoneIsNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldIsNull(FieldPhone))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneNotNil applies the NotNil predicate on the "phone" field.
|
||||||
|
func PhoneNotNil() predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldNotNull(FieldPhone))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneEqualFold applies the EqualFold predicate on the "phone" field.
|
||||||
|
func PhoneEqualFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldEqualFold(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneContainsFold applies the ContainsFold predicate on the "phone" field.
|
||||||
|
func PhoneContainsFold(v string) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.FieldContainsFold(FieldPhone, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPosts applies the HasEdge predicate on the "posts" edge.
|
||||||
|
func HasPosts() predicate.Profile {
|
||||||
|
return predicate.Profile(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, PostsTable, PostsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates).
|
||||||
|
func HasPostsWith(preds ...predicate.Post) predicate.Profile {
|
||||||
|
return predicate.Profile(func(s *sql.Selector) {
|
||||||
|
step := newPostsStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.Profile) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.Profile) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.Profile) predicate.Profile {
|
||||||
|
return predicate.Profile(sql.NotPredicates(p))
|
||||||
|
}
|
334
ent/profile_create.go
Normal file
334
ent/profile_create.go
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProfileCreate is the builder for creating a Profile entity.
|
||||||
|
type ProfileCreate struct {
|
||||||
|
config
|
||||||
|
mutation *ProfileMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (pc *ProfileCreate) SetCreatedAt(t time.Time) *ProfileCreate {
|
||||||
|
pc.mutation.SetCreatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillableCreatedAt(t *time.Time) *ProfileCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pc *ProfileCreate) SetUpdatedAt(t time.Time) *ProfileCreate {
|
||||||
|
pc.mutation.SetUpdatedAt(t)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillableUpdatedAt(t *time.Time) *ProfileCreate {
|
||||||
|
if t != nil {
|
||||||
|
pc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pc *ProfileCreate) SetName(s string) *ProfileCreate {
|
||||||
|
pc.mutation.SetName(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillableName(s *string) *ProfileCreate {
|
||||||
|
if s != nil {
|
||||||
|
pc.SetName(*s)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddress sets the "address" field.
|
||||||
|
func (pc *ProfileCreate) SetAddress(s string) *ProfileCreate {
|
||||||
|
pc.mutation.SetAddress(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAddress sets the "address" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillableAddress(s *string) *ProfileCreate {
|
||||||
|
if s != nil {
|
||||||
|
pc.SetAddress(*s)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPhone sets the "phone" field.
|
||||||
|
func (pc *ProfileCreate) SetPhone(s string) *ProfileCreate {
|
||||||
|
pc.mutation.SetPhone(s)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillablePhone(s *string) *ProfileCreate {
|
||||||
|
if s != nil {
|
||||||
|
pc.SetPhone(*s)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (pc *ProfileCreate) SetID(u uuid.UUID) *ProfileCreate {
|
||||||
|
pc.mutation.SetID(u)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableID sets the "id" field if the given value is not nil.
|
||||||
|
func (pc *ProfileCreate) SetNillableID(u *uuid.UUID) *ProfileCreate {
|
||||||
|
if u != nil {
|
||||||
|
pc.SetID(*u)
|
||||||
|
}
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (pc *ProfileCreate) AddPostIDs(ids ...uuid.UUID) *ProfileCreate {
|
||||||
|
pc.mutation.AddPostIDs(ids...)
|
||||||
|
return pc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (pc *ProfileCreate) AddPosts(p ...*Post) *ProfileCreate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pc.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProfileMutation object of the builder.
|
||||||
|
func (pc *ProfileCreate) Mutation() *ProfileMutation {
|
||||||
|
return pc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Profile in the database.
|
||||||
|
func (pc *ProfileCreate) Save(ctx context.Context) (*Profile, error) {
|
||||||
|
pc.defaults()
|
||||||
|
return withHooks(ctx, pc.sqlSave, pc.mutation, pc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (pc *ProfileCreate) SaveX(ctx context.Context) *Profile {
|
||||||
|
v, err := pc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pc *ProfileCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pc *ProfileCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := pc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pc *ProfileCreate) defaults() {
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
v := profile.DefaultCreatedAt()
|
||||||
|
pc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.UpdatedAt(); !ok {
|
||||||
|
v := profile.DefaultUpdatedAt()
|
||||||
|
pc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := pc.mutation.ID(); !ok {
|
||||||
|
v := profile.DefaultID()
|
||||||
|
pc.mutation.SetID(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (pc *ProfileCreate) check() error {
|
||||||
|
if _, ok := pc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Profile.created_at"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *ProfileCreate) sqlSave(ctx context.Context) (*Profile, error) {
|
||||||
|
if err := pc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := pc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != nil {
|
||||||
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||||
|
_node.ID = *id
|
||||||
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pc.mutation.id = &_node.ID
|
||||||
|
pc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *ProfileCreate) createSpec() (*Profile, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Profile{config: pc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(profile.Table, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||||
|
)
|
||||||
|
if id, ok := pc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = &id
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(profile.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Name(); ok {
|
||||||
|
_spec.SetField(profile.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Address(); ok {
|
||||||
|
_spec.SetField(profile.FieldAddress, field.TypeString, value)
|
||||||
|
_node.Address = value
|
||||||
|
}
|
||||||
|
if value, ok := pc.mutation.Phone(); ok {
|
||||||
|
_spec.SetField(profile.FieldPhone, field.TypeString, value)
|
||||||
|
_node.Phone = value
|
||||||
|
}
|
||||||
|
if nodes := pc.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileCreateBulk is the builder for creating many Profile entities in bulk.
|
||||||
|
type ProfileCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*ProfileCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Profile entities in the database.
|
||||||
|
func (pcb *ProfileCreateBulk) Save(ctx context.Context) ([]*Profile, error) {
|
||||||
|
if pcb.err != nil {
|
||||||
|
return nil, pcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(pcb.builders))
|
||||||
|
nodes := make([]*Profile, len(pcb.builders))
|
||||||
|
mutators := make([]Mutator, len(pcb.builders))
|
||||||
|
for i := range pcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := pcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*ProfileMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
var err error
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, pcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, pcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, pcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pcb *ProfileCreateBulk) SaveX(ctx context.Context) []*Profile {
|
||||||
|
v, err := pcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pcb *ProfileCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := pcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pcb *ProfileCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := pcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
88
ent/profile_delete.go
Normal file
88
ent/profile_delete.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProfileDelete is the builder for deleting a Profile entity.
|
||||||
|
type ProfileDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProfileMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProfileDelete builder.
|
||||||
|
func (pd *ProfileDelete) Where(ps ...predicate.Profile) *ProfileDelete {
|
||||||
|
pd.mutation.Where(ps...)
|
||||||
|
return pd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (pd *ProfileDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, pd.sqlExec, pd.mutation, pd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pd *ProfileDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := pd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pd *ProfileDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(profile.Table, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||||
|
if ps := pd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, pd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
pd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileDeleteOne is the builder for deleting a single Profile entity.
|
||||||
|
type ProfileDeleteOne struct {
|
||||||
|
pd *ProfileDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProfileDelete builder.
|
||||||
|
func (pdo *ProfileDeleteOne) Where(ps ...predicate.Profile) *ProfileDeleteOne {
|
||||||
|
pdo.pd.mutation.Where(ps...)
|
||||||
|
return pdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (pdo *ProfileDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := pdo.pd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{profile.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pdo *ProfileDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := pdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
643
ent/profile_query.go
Normal file
643
ent/profile_query.go
Normal file
@ -0,0 +1,643 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProfileQuery is the builder for querying Profile entities.
|
||||||
|
type ProfileQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []profile.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.Profile
|
||||||
|
withPosts *PostQuery
|
||||||
|
modifiers []func(*sql.Selector)
|
||||||
|
loadTotal []func(context.Context, []*Profile) error
|
||||||
|
withNamedPosts map[string]*PostQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the ProfileQuery builder.
|
||||||
|
func (pq *ProfileQuery) Where(ps ...predicate.Profile) *ProfileQuery {
|
||||||
|
pq.predicates = append(pq.predicates, ps...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (pq *ProfileQuery) Limit(limit int) *ProfileQuery {
|
||||||
|
pq.ctx.Limit = &limit
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (pq *ProfileQuery) Offset(offset int) *ProfileQuery {
|
||||||
|
pq.ctx.Offset = &offset
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (pq *ProfileQuery) Unique(unique bool) *ProfileQuery {
|
||||||
|
pq.ctx.Unique = &unique
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (pq *ProfileQuery) Order(o ...profile.OrderOption) *ProfileQuery {
|
||||||
|
pq.order = append(pq.order, o...)
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryPosts chains the current query on the "posts" edge.
|
||||||
|
func (pq *ProfileQuery) QueryPosts() *PostQuery {
|
||||||
|
query := (&PostClient{config: pq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := pq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(profile.Table, profile.FieldID, selector),
|
||||||
|
sqlgraph.To(post.Table, post.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, profile.PostsTable, profile.PostsColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(pq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Profile entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Profile was found.
|
||||||
|
func (pq *ProfileQuery) First(ctx context.Context) (*Profile, error) {
|
||||||
|
nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, ent.OpQueryFirst))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{profile.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) FirstX(ctx context.Context) *Profile {
|
||||||
|
node, err := pq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Profile ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Profile ID was found.
|
||||||
|
func (pq *ProfileQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{profile.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := pq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Profile entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Profile entity is found.
|
||||||
|
// Returns a *NotFoundError when no Profile entities are found.
|
||||||
|
func (pq *ProfileQuery) Only(ctx context.Context) (*Profile, error) {
|
||||||
|
nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, ent.OpQueryOnly))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{profile.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{profile.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) OnlyX(ctx context.Context) *Profile {
|
||||||
|
node, err := pq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Profile ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Profile ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (pq *ProfileQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{profile.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{profile.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := pq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Profiles.
|
||||||
|
func (pq *ProfileQuery) All(ctx context.Context) ([]*Profile, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryAll)
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*Profile, *ProfileQuery]()
|
||||||
|
return withInterceptors[[]*Profile](ctx, pq, qr, pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) AllX(ctx context.Context) []*Profile {
|
||||||
|
nodes, err := pq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Profile IDs.
|
||||||
|
func (pq *ProfileQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||||
|
if pq.ctx.Unique == nil && pq.path != nil {
|
||||||
|
pq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryIDs)
|
||||||
|
if err = pq.Select(profile.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||||
|
ids, err := pq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (pq *ProfileQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryCount)
|
||||||
|
if err := pq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, pq, querierCount[*ProfileQuery](), pq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := pq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (pq *ProfileQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, pq.ctx, ent.OpQueryExist)
|
||||||
|
switch _, err := pq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (pq *ProfileQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := pq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the ProfileQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (pq *ProfileQuery) Clone() *ProfileQuery {
|
||||||
|
if pq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ProfileQuery{
|
||||||
|
config: pq.config,
|
||||||
|
ctx: pq.ctx.Clone(),
|
||||||
|
order: append([]profile.OrderOption{}, pq.order...),
|
||||||
|
inters: append([]Interceptor{}, pq.inters...),
|
||||||
|
predicates: append([]predicate.Profile{}, pq.predicates...),
|
||||||
|
withPosts: pq.withPosts.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: pq.sql.Clone(),
|
||||||
|
path: pq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPosts tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "posts" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pq *ProfileQuery) WithPosts(opts ...func(*PostQuery)) *ProfileQuery {
|
||||||
|
query := (&PostClient{config: pq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
pq.withPosts = query
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is 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 {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Profile.Query().
|
||||||
|
// GroupBy(profile.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *ProfileQuery) GroupBy(field string, fields ...string) *ProfileGroupBy {
|
||||||
|
pq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &ProfileGroupBy{build: pq}
|
||||||
|
grbuild.flds = &pq.ctx.Fields
|
||||||
|
grbuild.label = profile.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Profile.Query().
|
||||||
|
// Select(profile.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (pq *ProfileQuery) Select(fields ...string) *ProfileSelect {
|
||||||
|
pq.ctx.Fields = append(pq.ctx.Fields, fields...)
|
||||||
|
sbuild := &ProfileSelect{ProfileQuery: pq}
|
||||||
|
sbuild.label = profile.Label
|
||||||
|
sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a ProfileSelect configured with the given aggregations.
|
||||||
|
func (pq *ProfileQuery) Aggregate(fns ...AggregateFunc) *ProfileSelect {
|
||||||
|
return pq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range pq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, pq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range pq.ctx.Fields {
|
||||||
|
if !profile.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pq.path != nil {
|
||||||
|
prev, err := pq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Profile, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Profile{}
|
||||||
|
_spec = pq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
pq.withPosts != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*Profile).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &Profile{config: pq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if len(pq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = pq.modifiers
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := pq.withPosts; query != nil {
|
||||||
|
if err := pq.loadPosts(ctx, query, nodes,
|
||||||
|
func(n *Profile) { n.Edges.Posts = []*Post{} },
|
||||||
|
func(n *Profile, e *Post) { n.Edges.Posts = append(n.Edges.Posts, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for name, query := range pq.withNamedPosts {
|
||||||
|
if err := pq.loadPosts(ctx, query, nodes,
|
||||||
|
func(n *Profile) { n.appendNamedPosts(name) },
|
||||||
|
func(n *Profile, e *Post) { n.appendNamedPosts(name, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range pq.loadTotal {
|
||||||
|
if err := pq.loadTotal[i](ctx, nodes); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) loadPosts(ctx context.Context, query *PostQuery, nodes []*Profile, init func(*Profile), assign func(*Profile, *Post)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID]*Profile)
|
||||||
|
for i := range nodes {
|
||||||
|
fks = append(fks, nodes[i].ID)
|
||||||
|
nodeids[nodes[i].ID] = nodes[i]
|
||||||
|
if init != nil {
|
||||||
|
init(nodes[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.withFKs = true
|
||||||
|
query.Where(predicate.Post(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(s.C(profile.PostsColumn), fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.profile_posts
|
||||||
|
if fk == nil {
|
||||||
|
return fmt.Errorf(`foreign-key "profile_posts" is nil for node %v`, n.ID)
|
||||||
|
}
|
||||||
|
node, ok := nodeids[*fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected referenced foreign-key "profile_posts" returned %v for node %v`, *fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := pq.querySpec()
|
||||||
|
if len(pq.modifiers) > 0 {
|
||||||
|
_spec.Modifiers = pq.modifiers
|
||||||
|
}
|
||||||
|
_spec.Node.Columns = pq.ctx.Fields
|
||||||
|
if len(pq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, pq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||||
|
_spec.From = pq.sql
|
||||||
|
if unique := pq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if pq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := pq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, profile.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != profile.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := pq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := pq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pq *ProfileQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(pq.driver.Dialect())
|
||||||
|
t1 := builder.Table(profile.Table)
|
||||||
|
columns := pq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = profile.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if pq.sql != nil {
|
||||||
|
selector = pq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if pq.ctx.Unique != nil && *pq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range pq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range pq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := pq.ctx.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.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := pq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithNamedPosts tells the query-builder to eager-load the nodes that are connected to the "posts"
|
||||||
|
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (pq *ProfileQuery) WithNamedPosts(name string, opts ...func(*PostQuery)) *ProfileQuery {
|
||||||
|
query := (&PostClient{config: pq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
if pq.withNamedPosts == nil {
|
||||||
|
pq.withNamedPosts = make(map[string]*PostQuery)
|
||||||
|
}
|
||||||
|
pq.withNamedPosts[name] = query
|
||||||
|
return pq
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileGroupBy is the group-by builder for Profile entities.
|
||||||
|
type ProfileGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *ProfileQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (pgb *ProfileGroupBy) Aggregate(fns ...AggregateFunc) *ProfileGroupBy {
|
||||||
|
pgb.fns = append(pgb.fns, fns...)
|
||||||
|
return pgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (pgb *ProfileGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, pgb.build.ctx, ent.OpQueryGroupBy)
|
||||||
|
if err := pgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProfileQuery, *ProfileGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pgb *ProfileGroupBy) sqlScan(ctx context.Context, root *ProfileQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(pgb.fns))
|
||||||
|
for _, fn := range pgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns))
|
||||||
|
for _, f := range *pgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*pgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileSelect is the builder for selecting fields of Profile entities.
|
||||||
|
type ProfileSelect struct {
|
||||||
|
*ProfileQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (ps *ProfileSelect) Aggregate(fns ...AggregateFunc) *ProfileSelect {
|
||||||
|
ps.fns = append(ps.fns, fns...)
|
||||||
|
return ps
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (ps *ProfileSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, ps.ctx, ent.OpQuerySelect)
|
||||||
|
if err := ps.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*ProfileQuery, *ProfileSelect](ctx, ps.ProfileQuery, ps, ps.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ps *ProfileSelect) sqlScan(ctx context.Context, root *ProfileQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(ps.fns))
|
||||||
|
for _, fn := range ps.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*ps.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := ps.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
550
ent/profile_update.go
Normal file
550
ent/profile_update.go
Normal file
@ -0,0 +1,550 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/predicate"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProfileUpdate is the builder for updating Profile entities.
|
||||||
|
type ProfileUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProfileMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProfileUpdate builder.
|
||||||
|
func (pu *ProfileUpdate) Where(ps ...predicate.Profile) *ProfileUpdate {
|
||||||
|
pu.mutation.Where(ps...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (pu *ProfileUpdate) SetUpdatedAt(t time.Time) *ProfileUpdate {
|
||||||
|
pu.mutation.SetUpdatedAt(t)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (pu *ProfileUpdate) ClearUpdatedAt() *ProfileUpdate {
|
||||||
|
pu.mutation.ClearUpdatedAt()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (pu *ProfileUpdate) SetName(s string) *ProfileUpdate {
|
||||||
|
pu.mutation.SetName(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (pu *ProfileUpdate) SetNillableName(s *string) *ProfileUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetName(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearName clears the value of the "name" field.
|
||||||
|
func (pu *ProfileUpdate) ClearName() *ProfileUpdate {
|
||||||
|
pu.mutation.ClearName()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddress sets the "address" field.
|
||||||
|
func (pu *ProfileUpdate) SetAddress(s string) *ProfileUpdate {
|
||||||
|
pu.mutation.SetAddress(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAddress sets the "address" field if the given value is not nil.
|
||||||
|
func (pu *ProfileUpdate) SetNillableAddress(s *string) *ProfileUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetAddress(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAddress clears the value of the "address" field.
|
||||||
|
func (pu *ProfileUpdate) ClearAddress() *ProfileUpdate {
|
||||||
|
pu.mutation.ClearAddress()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPhone sets the "phone" field.
|
||||||
|
func (pu *ProfileUpdate) SetPhone(s string) *ProfileUpdate {
|
||||||
|
pu.mutation.SetPhone(s)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
||||||
|
func (pu *ProfileUpdate) SetNillablePhone(s *string) *ProfileUpdate {
|
||||||
|
if s != nil {
|
||||||
|
pu.SetPhone(*s)
|
||||||
|
}
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPhone clears the value of the "phone" field.
|
||||||
|
func (pu *ProfileUpdate) ClearPhone() *ProfileUpdate {
|
||||||
|
pu.mutation.ClearPhone()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (pu *ProfileUpdate) AddPostIDs(ids ...uuid.UUID) *ProfileUpdate {
|
||||||
|
pu.mutation.AddPostIDs(ids...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (pu *ProfileUpdate) AddPosts(p ...*Post) *ProfileUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pu.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProfileMutation object of the builder.
|
||||||
|
func (pu *ProfileUpdate) Mutation() *ProfileMutation {
|
||||||
|
return pu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPosts clears all "posts" edges to the Post entity.
|
||||||
|
func (pu *ProfileUpdate) ClearPosts() *ProfileUpdate {
|
||||||
|
pu.mutation.ClearPosts()
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePostIDs removes the "posts" edge to Post entities by IDs.
|
||||||
|
func (pu *ProfileUpdate) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdate {
|
||||||
|
pu.mutation.RemovePostIDs(ids...)
|
||||||
|
return pu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePosts removes "posts" edges to Post entities.
|
||||||
|
func (pu *ProfileUpdate) RemovePosts(p ...*Post) *ProfileUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return pu.RemovePostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (pu *ProfileUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
pu.defaults()
|
||||||
|
return withHooks(ctx, pu.sqlSave, pu.mutation, pu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (pu *ProfileUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := pu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (pu *ProfileUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := pu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (pu *ProfileUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := pu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (pu *ProfileUpdate) defaults() {
|
||||||
|
if _, ok := pu.mutation.UpdatedAt(); !ok && !pu.mutation.UpdatedAtCleared() {
|
||||||
|
v := profile.UpdateDefaultUpdatedAt()
|
||||||
|
pu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pu *ProfileUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||||
|
if ps := pu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(profile.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(profile.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.NameCleared() {
|
||||||
|
_spec.ClearField(profile.FieldName, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Address(); ok {
|
||||||
|
_spec.SetField(profile.FieldAddress, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.AddressCleared() {
|
||||||
|
_spec.ClearField(profile.FieldAddress, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := pu.mutation.Phone(); ok {
|
||||||
|
_spec.SetField(profile.FieldPhone, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if pu.mutation.PhoneCleared() {
|
||||||
|
_spec.ClearField(profile.FieldPhone, field.TypeString)
|
||||||
|
}
|
||||||
|
if pu.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !pu.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := pu.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{profile.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
pu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProfileUpdateOne is the builder for updating a single Profile entity.
|
||||||
|
type ProfileUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *ProfileMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (puo *ProfileUpdateOne) SetUpdatedAt(t time.Time) *ProfileUpdateOne {
|
||||||
|
puo.mutation.SetUpdatedAt(t)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUpdatedAt clears the value of the "updated_at" field.
|
||||||
|
func (puo *ProfileUpdateOne) ClearUpdatedAt() *ProfileUpdateOne {
|
||||||
|
puo.mutation.ClearUpdatedAt()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (puo *ProfileUpdateOne) SetName(s string) *ProfileUpdateOne {
|
||||||
|
puo.mutation.SetName(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (puo *ProfileUpdateOne) SetNillableName(s *string) *ProfileUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetName(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearName clears the value of the "name" field.
|
||||||
|
func (puo *ProfileUpdateOne) ClearName() *ProfileUpdateOne {
|
||||||
|
puo.mutation.ClearName()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAddress sets the "address" field.
|
||||||
|
func (puo *ProfileUpdateOne) SetAddress(s string) *ProfileUpdateOne {
|
||||||
|
puo.mutation.SetAddress(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAddress sets the "address" field if the given value is not nil.
|
||||||
|
func (puo *ProfileUpdateOne) SetNillableAddress(s *string) *ProfileUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetAddress(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAddress clears the value of the "address" field.
|
||||||
|
func (puo *ProfileUpdateOne) ClearAddress() *ProfileUpdateOne {
|
||||||
|
puo.mutation.ClearAddress()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPhone sets the "phone" field.
|
||||||
|
func (puo *ProfileUpdateOne) SetPhone(s string) *ProfileUpdateOne {
|
||||||
|
puo.mutation.SetPhone(s)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
||||||
|
func (puo *ProfileUpdateOne) SetNillablePhone(s *string) *ProfileUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
puo.SetPhone(*s)
|
||||||
|
}
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPhone clears the value of the "phone" field.
|
||||||
|
func (puo *ProfileUpdateOne) ClearPhone() *ProfileUpdateOne {
|
||||||
|
puo.mutation.ClearPhone()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
|
||||||
|
func (puo *ProfileUpdateOne) AddPostIDs(ids ...uuid.UUID) *ProfileUpdateOne {
|
||||||
|
puo.mutation.AddPostIDs(ids...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPosts adds the "posts" edges to the Post entity.
|
||||||
|
func (puo *ProfileUpdateOne) AddPosts(p ...*Post) *ProfileUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return puo.AddPostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the ProfileMutation object of the builder.
|
||||||
|
func (puo *ProfileUpdateOne) Mutation() *ProfileMutation {
|
||||||
|
return puo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearPosts clears all "posts" edges to the Post entity.
|
||||||
|
func (puo *ProfileUpdateOne) ClearPosts() *ProfileUpdateOne {
|
||||||
|
puo.mutation.ClearPosts()
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePostIDs removes the "posts" edge to Post entities by IDs.
|
||||||
|
func (puo *ProfileUpdateOne) RemovePostIDs(ids ...uuid.UUID) *ProfileUpdateOne {
|
||||||
|
puo.mutation.RemovePostIDs(ids...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePosts removes "posts" edges to Post entities.
|
||||||
|
func (puo *ProfileUpdateOne) RemovePosts(p ...*Post) *ProfileUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(p))
|
||||||
|
for i := range p {
|
||||||
|
ids[i] = p[i].ID
|
||||||
|
}
|
||||||
|
return puo.RemovePostIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the ProfileUpdate builder.
|
||||||
|
func (puo *ProfileUpdateOne) Where(ps ...predicate.Profile) *ProfileUpdateOne {
|
||||||
|
puo.mutation.Where(ps...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (puo *ProfileUpdateOne) Select(field string, fields ...string) *ProfileUpdateOne {
|
||||||
|
puo.fields = append([]string{field}, fields...)
|
||||||
|
return puo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Profile entity.
|
||||||
|
func (puo *ProfileUpdateOne) Save(ctx context.Context) (*Profile, error) {
|
||||||
|
puo.defaults()
|
||||||
|
return withHooks(ctx, puo.sqlSave, puo.mutation, puo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (puo *ProfileUpdateOne) SaveX(ctx context.Context) *Profile {
|
||||||
|
node, err := puo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (puo *ProfileUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := puo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (puo *ProfileUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := puo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (puo *ProfileUpdateOne) defaults() {
|
||||||
|
if _, ok := puo.mutation.UpdatedAt(); !ok && !puo.mutation.UpdatedAtCleared() {
|
||||||
|
v := profile.UpdateDefaultUpdatedAt()
|
||||||
|
puo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (puo *ProfileUpdateOne) sqlSave(ctx context.Context) (_node *Profile, err error) {
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(profile.Table, profile.Columns, sqlgraph.NewFieldSpec(profile.FieldID, field.TypeUUID))
|
||||||
|
id, ok := puo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Profile.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := puo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, profile.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !profile.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != profile.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := puo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(profile.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.UpdatedAtCleared() {
|
||||||
|
_spec.ClearField(profile.FieldUpdatedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(profile.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.NameCleared() {
|
||||||
|
_spec.ClearField(profile.FieldName, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Address(); ok {
|
||||||
|
_spec.SetField(profile.FieldAddress, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.AddressCleared() {
|
||||||
|
_spec.ClearField(profile.FieldAddress, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := puo.mutation.Phone(); ok {
|
||||||
|
_spec.SetField(profile.FieldPhone, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if puo.mutation.PhoneCleared() {
|
||||||
|
_spec.ClearField(profile.FieldPhone, field.TypeString)
|
||||||
|
}
|
||||||
|
if puo.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !puo.mutation.PostsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := puo.mutation.PostsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: profile.PostsTable,
|
||||||
|
Columns: []string{profile.PostsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeUUID),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Profile{config: puo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, puo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{profile.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
puo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
83
ent/runtime.go
Normal file
83
ent/runtime.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent/category"
|
||||||
|
"code.icod.de/dalu/ka/ent/post"
|
||||||
|
"code.icod.de/dalu/ka/ent/profile"
|
||||||
|
"code.icod.de/dalu/ka/ent/schema"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
categoryFields := schema.Category{}.Fields()
|
||||||
|
_ = categoryFields
|
||||||
|
// categoryDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
categoryDescCreatedAt := categoryFields[1].Descriptor()
|
||||||
|
// category.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
category.DefaultCreatedAt = categoryDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// categoryDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
categoryDescUpdatedAt := categoryFields[2].Descriptor()
|
||||||
|
// category.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
category.DefaultUpdatedAt = categoryDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// category.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
category.UpdateDefaultUpdatedAt = categoryDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// categoryDescTitle is the schema descriptor for title field.
|
||||||
|
categoryDescTitle := categoryFields[3].Descriptor()
|
||||||
|
// category.TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
category.TitleValidator = categoryDescTitle.Validators[0].(func(string) error)
|
||||||
|
// categoryDescID is the schema descriptor for id field.
|
||||||
|
categoryDescID := categoryFields[0].Descriptor()
|
||||||
|
// category.DefaultID holds the default value on creation for the id field.
|
||||||
|
category.DefaultID = categoryDescID.Default.(func() uuid.UUID)
|
||||||
|
postFields := schema.Post{}.Fields()
|
||||||
|
_ = postFields
|
||||||
|
// postDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
postDescCreatedAt := postFields[1].Descriptor()
|
||||||
|
// post.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
post.DefaultCreatedAt = postDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// postDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
postDescUpdatedAt := postFields[2].Descriptor()
|
||||||
|
// post.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
post.DefaultUpdatedAt = postDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// post.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
post.UpdateDefaultUpdatedAt = postDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// postDescExpires is the schema descriptor for expires field.
|
||||||
|
postDescExpires := postFields[3].Descriptor()
|
||||||
|
// post.DefaultExpires holds the default value on creation for the expires field.
|
||||||
|
post.DefaultExpires = postDescExpires.Default.(bool)
|
||||||
|
// postDescTitle is the schema descriptor for title field.
|
||||||
|
postDescTitle := postFields[5].Descriptor()
|
||||||
|
// post.TitleValidator is a validator for the "title" field. It is called by the builders before save.
|
||||||
|
post.TitleValidator = postDescTitle.Validators[0].(func(string) error)
|
||||||
|
// postDescBody is the schema descriptor for body field.
|
||||||
|
postDescBody := postFields[6].Descriptor()
|
||||||
|
// post.BodyValidator is a validator for the "body" field. It is called by the builders before save.
|
||||||
|
post.BodyValidator = postDescBody.Validators[0].(func(string) error)
|
||||||
|
// postDescID is the schema descriptor for id field.
|
||||||
|
postDescID := postFields[0].Descriptor()
|
||||||
|
// post.DefaultID holds the default value on creation for the id field.
|
||||||
|
post.DefaultID = postDescID.Default.(func() uuid.UUID)
|
||||||
|
profileFields := schema.Profile{}.Fields()
|
||||||
|
_ = profileFields
|
||||||
|
// profileDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
profileDescCreatedAt := profileFields[1].Descriptor()
|
||||||
|
// profile.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
profile.DefaultCreatedAt = profileDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// profileDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
profileDescUpdatedAt := profileFields[2].Descriptor()
|
||||||
|
// profile.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
profile.DefaultUpdatedAt = profileDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// profile.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
profile.UpdateDefaultUpdatedAt = profileDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// profileDescID is the schema descriptor for id field.
|
||||||
|
profileDescID := profileFields[0].Descriptor()
|
||||||
|
// profile.DefaultID holds the default value on creation for the id field.
|
||||||
|
profile.DefaultID = profileDescID.Default.(func() uuid.UUID)
|
||||||
|
}
|
10
ent/runtime/runtime.go
Normal file
10
ent/runtime/runtime.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in code.icod.de/dalu/ka/ent/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.14.1" // Version of ent codegen.
|
||||||
|
Sum = "h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=" // Sum of ent codegen.
|
||||||
|
)
|
216
ent/tx.go
Normal file
216
ent/tx.go
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// Category is the client for interacting with the Category builders.
|
||||||
|
Category *CategoryClient
|
||||||
|
// Post is the client for interacting with the Post builders.
|
||||||
|
Post *PostClient
|
||||||
|
// Profile is the client for interacting with the Profile builders.
|
||||||
|
Profile *ProfileClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
txDriver.mu.Lock()
|
||||||
|
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||||
|
txDriver.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.Category = NewCategoryClient(tx.config)
|
||||||
|
tx.Post = NewPostClient(tx.config)
|
||||||
|
tx.Profile = NewProfileClient(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: Category.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
// completion hooks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, v any) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
40
go.mod
40
go.mod
@ -2,36 +2,40 @@ module code.icod.de/dalu/ka
|
|||||||
|
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require entgo.io/ent v0.14.1
|
require (
|
||||||
|
entgo.io/ent v0.14.1
|
||||||
|
github.com/99designs/gqlgen v0.17.55
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1
|
||||||
|
github.com/vektah/gqlparser/v2 v2.5.17
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208 // indirect
|
ariga.io/atlas v0.28.0 // indirect
|
||||||
github.com/99designs/gqlgen v0.17.48 // indirect
|
github.com/agext/levenshtein v1.2.3 // indirect
|
||||||
github.com/agext/levenshtein v1.2.1 // indirect
|
github.com/agnivade/levenshtein v1.2.0 // indirect
|
||||||
github.com/agnivade/levenshtein v1.1.1 // indirect
|
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
|
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||||
github.com/go-openapi/inflect v0.19.0 // indirect
|
github.com/bmatcuk/doublestar v1.3.4 // indirect
|
||||||
|
github.com/go-openapi/inflect v0.21.0 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
|
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/sosodev/duration v1.3.1 // indirect
|
github.com/sosodev/duration v1.3.1 // indirect
|
||||||
github.com/vektah/gqlparser/v2 v2.5.12 // indirect
|
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||||
github.com/zclconf/go-cty v1.14.4 // indirect
|
github.com/zclconf/go-cty v1.15.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 // indirect
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||||
golang.org/x/mod v0.20.0 // indirect
|
golang.org/x/mod v0.21.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/text v0.15.0 // indirect
|
golang.org/x/text v0.19.0 // indirect
|
||||||
golang.org/x/tools v0.24.0 // indirect
|
golang.org/x/tools v0.25.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
entgo.io/contrib v0.6.0
|
entgo.io/contrib v0.6.0
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/spf13/cobra v1.8.1 // indirect
|
github.com/spf13/cobra v1.8.1
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
)
|
)
|
||||||
|
106
go.sum
106
go.sum
@ -1,75 +1,95 @@
|
|||||||
ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208 h1:ixs1c/fAXGS3mTdalyKQrtvfkFjgChih/unX66YTzYk=
|
ariga.io/atlas v0.28.0 h1:qmn9tUyJypJkIw+X3ECUwDtkMTiFupgstHbjRN4xGH0=
|
||||||
ariga.io/atlas v0.25.1-0.20240717145915-af51d3945208/go.mod h1:KPLc7Zj+nzoXfWshrcY1RwlOh94dsATQEy4UPrF2RkM=
|
ariga.io/atlas v0.28.0/go.mod h1:LOOp18LCL9r+VifvVlJqgYJwYl271rrXD9/wIyzJ8sw=
|
||||||
entgo.io/contrib v0.6.0 h1:xfo4TbJE7sJZWx7BV7YrpSz7IPFvS8MzL3fnfzZjKvQ=
|
entgo.io/contrib v0.6.0 h1:xfo4TbJE7sJZWx7BV7YrpSz7IPFvS8MzL3fnfzZjKvQ=
|
||||||
entgo.io/contrib v0.6.0/go.mod h1:3qWIseJ/9Wx2Hu5zVh15FDzv7d/UvKNcYKdViywWCQg=
|
entgo.io/contrib v0.6.0/go.mod h1:3qWIseJ/9Wx2Hu5zVh15FDzv7d/UvKNcYKdViywWCQg=
|
||||||
entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=
|
entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=
|
||||||
entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco=
|
entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco=
|
||||||
github.com/99designs/gqlgen v0.17.48 h1:Wgk7n9PIdnmpsC1aJJV4eiZCGkAkoamKOtXAp/crpzQ=
|
github.com/99designs/gqlgen v0.17.55 h1:3vzrNWYyzSZjGDFo68e5j9sSauLxfKvLp+6ioRokVtM=
|
||||||
github.com/99designs/gqlgen v0.17.48/go.mod h1:hYeQ+ygPbcapbaHtHMbZ1DHMVNT+1tGU+fI+Hy4kqIo=
|
github.com/99designs/gqlgen v0.17.55/go.mod h1:3Bq768f8hgVPGZxL8aY9MaYmbxa6llPM/qu1IGH1EJo=
|
||||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||||
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
|
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
|
||||||
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
|
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
|
github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY=
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
github.com/agnivade/levenshtein v1.2.0/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
|
||||||
|
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
|
||||||
|
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
||||||
|
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
|
||||||
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
|
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
|
||||||
|
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
|
||||||
|
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
|
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo=
|
||||||
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
|
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
|
||||||
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
|
github.com/go-openapi/inflect v0.21.0 h1:FoBjBTQEcbg2cJUWX6uwL9OyIW8eqc9k4KhN4lfbeYk=
|
||||||
|
github.com/go-openapi/inflect v0.21.0/go.mod h1:INezMuUu7SJQc2AyR3WO0DqqYUJSj8Kb4hBd7WtjlAw=
|
||||||
|
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||||
|
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||||
|
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||||
|
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||||
|
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||||
|
github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M=
|
||||||
|
github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||||
|
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||||
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
|
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
|
||||||
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
|
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
|
||||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/vektah/gqlparser/v2 v2.5.12 h1:COMhVVnql6RoaF7+aTBWiTADdpLGyZWU3K/NwW0ph98=
|
github.com/vektah/gqlparser/v2 v2.5.17 h1:9At7WblLV7/36nulgekUgIaqHZWn5hxqluxrxGUhOmI=
|
||||||
github.com/vektah/gqlparser/v2 v2.5.12/go.mod h1:WQQjFc+I1YIzoPvZBhUQX7waZgg3pMLi0r8KymvAE2w=
|
github.com/vektah/gqlparser/v2 v2.5.17/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
|
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
|
||||||
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
|
||||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||||
github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8=
|
github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ=
|
||||||
github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
||||||
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 h1:m9O6OTJ627iFnN2JIWfdqlZCzneRO6EEBsHXI25P8ws=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
||||||
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
||||||
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||||
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
||||||
|
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||||
|
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
|
||||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
|
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
|
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# schema tells gqlgen when the GraphQL schema is located.
|
# schema tells gqlgen when the GraphQL schema is located.
|
||||||
schema:
|
schema:
|
||||||
- ent.graphql
|
- ent.graphql
|
||||||
- exyu.graphql
|
- ka.graphql
|
||||||
|
|
||||||
# Where should the generated server code go?
|
# Where should the generated server code go?
|
||||||
exec:
|
exec:
|
||||||
@ -14,7 +14,6 @@ resolver:
|
|||||||
layout: follow-schema
|
layout: follow-schema
|
||||||
dir: graph
|
dir: graph
|
||||||
package: graph
|
package: graph
|
||||||
filename_template: "{name}.resolvers.go"
|
|
||||||
|
|
||||||
# gqlgen will search for any type names in the schema in these go packages
|
# gqlgen will search for any type names in the schema in these go packages
|
||||||
# if they match it will use them, otherwise it will generate them.
|
# if they match it will use them, otherwise it will generate them.
|
||||||
@ -23,8 +22,8 @@ resolver:
|
|||||||
# provided package. If they match it will use them, otherwise it will generate new.
|
# provided package. If they match it will use them, otherwise it will generate new.
|
||||||
autobind:
|
autobind:
|
||||||
- code.icod.de/dalu/ka/ent
|
- code.icod.de/dalu/ka/ent
|
||||||
- code.icod.de/dalu/ka/ent/post
|
|
||||||
- code.icod.de/dalu/ka/ent/category
|
- code.icod.de/dalu/ka/ent/category
|
||||||
|
- code.icod.de/dalu/ka/ent/post
|
||||||
- code.icod.de/dalu/ka/ent/profile
|
- code.icod.de/dalu/ka/ent/profile
|
||||||
|
|
||||||
# This section declares type mapping between the GraphQL and Go type systems.
|
# This section declares type mapping between the GraphQL and Go type systems.
|
||||||
|
44
graph/ent.resolvers.go
Normal file
44
graph/ent.resolvers.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||||
|
// will be copied through when generating and any unknown code will be moved to the end.
|
||||||
|
// Code generated by github.com/99designs/gqlgen version v0.17.55
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/dalu/ka/ent"
|
||||||
|
"code.icod.de/dalu/ka/graph/generated"
|
||||||
|
"entgo.io/contrib/entgql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Node is the resolver for the node field.
|
||||||
|
func (r *queryResolver) Node(ctx context.Context, id uuid.UUID) (ent.Noder, error) {
|
||||||
|
return r.client.Noder(ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nodes is the resolver for the nodes field.
|
||||||
|
func (r *queryResolver) Nodes(ctx context.Context, ids []uuid.UUID) ([]ent.Noder, error) {
|
||||||
|
return r.client.Noders(ctx, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Categories is the resolver for the categories field.
|
||||||
|
func (r *queryResolver) Categories(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.CategoryOrder, where *ent.CategoryWhereInput) (*ent.CategoryConnection, error) {
|
||||||
|
return r.client.Category.Query().Paginate(ctx, after, first, before, last, ent.WithCategoryOrder(orderBy), ent.WithCategoryFilter(where.Filter))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posts is the resolver for the posts field.
|
||||||
|
func (r *queryResolver) Posts(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.PostOrder, where *ent.PostWhereInput) (*ent.PostConnection, error) {
|
||||||
|
return r.client.Post.Query().Paginate(ctx, after, first, before, last, ent.WithPostOrder(orderBy), ent.WithPostFilter(where.Filter))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Profiles is the resolver for the profiles field.
|
||||||
|
func (r *queryResolver) Profiles(ctx context.Context, after *entgql.Cursor[uuid.UUID], first *int, before *entgql.Cursor[uuid.UUID], last *int, orderBy *ent.ProfileOrder, where *ent.ProfileWhereInput) (*ent.ProfileConnection, error) {
|
||||||
|
return r.client.Profile.Query().Paginate(ctx, after, first, before, last, ent.WithProfileOrder(orderBy), ent.WithProfileFilter(where.Filter))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns generated.QueryResolver implementation.
|
||||||
|
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||||
|
|
||||||
|
type queryResolver struct{ *Resolver }
|
6749
graph/generated/ent.generated.go
Normal file
6749
graph/generated/ent.generated.go
Normal file
File diff suppressed because it is too large
Load Diff
2971
graph/generated/prelude.generated.go
Normal file
2971
graph/generated/prelude.generated.go
Normal file
File diff suppressed because it is too large
Load Diff
1390
graph/generated/root_.generated.go
Normal file
1390
graph/generated/root_.generated.go
Normal file
File diff suppressed because it is too large
Load Diff
21
graph/resolver.go
Normal file
21
graph/resolver.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.icod.de/dalu/ka/ent"
|
||||||
|
"code.icod.de/dalu/ka/graph/generated"
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This file will not be regenerated automatically.
|
||||||
|
//
|
||||||
|
// It serves as dependency injection for your app, add any dependencies you require here.
|
||||||
|
|
||||||
|
type Resolver struct {
|
||||||
|
client *ent.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSchema(client *ent.Client) graphql.ExecutableSchema {
|
||||||
|
return generated.NewExecutableSchema(generated.Config{
|
||||||
|
Resolvers: &Resolver{client},
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user