post_create.go•60 kB
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/asset"
"github.com/Southclaws/storyden/internal/ent/category"
"github.com/Southclaws/storyden/internal/ent/collection"
"github.com/Southclaws/storyden/internal/ent/event"
"github.com/Southclaws/storyden/internal/ent/likepost"
"github.com/Southclaws/storyden/internal/ent/link"
"github.com/Southclaws/storyden/internal/ent/mentionprofile"
"github.com/Southclaws/storyden/internal/ent/post"
"github.com/Southclaws/storyden/internal/ent/postread"
"github.com/Southclaws/storyden/internal/ent/react"
"github.com/Southclaws/storyden/internal/ent/tag"
"github.com/rs/xid"
)
// PostCreate is the builder for creating a Post entity.
type PostCreate struct {
config
mutation *PostMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *PostCreate) SetCreatedAt(v time.Time) *PostCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *PostCreate) SetNillableCreatedAt(v *time.Time) *PostCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *PostCreate) SetUpdatedAt(v time.Time) *PostCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetDeletedAt sets the "deleted_at" field.
func (_c *PostCreate) SetDeletedAt(v time.Time) *PostCreate {
_c.mutation.SetDeletedAt(v)
return _c
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *PostCreate) SetNillableDeletedAt(v *time.Time) *PostCreate {
if v != nil {
_c.SetDeletedAt(*v)
}
return _c
}
// SetIndexedAt sets the "indexed_at" field.
func (_c *PostCreate) SetIndexedAt(v time.Time) *PostCreate {
_c.mutation.SetIndexedAt(v)
return _c
}
// SetNillableIndexedAt sets the "indexed_at" field if the given value is not nil.
func (_c *PostCreate) SetNillableIndexedAt(v *time.Time) *PostCreate {
if v != nil {
_c.SetIndexedAt(*v)
}
return _c
}
// SetFirst sets the "first" field.
func (_c *PostCreate) SetFirst(v bool) *PostCreate {
_c.mutation.SetFirst(v)
return _c
}
// SetTitle sets the "title" field.
func (_c *PostCreate) SetTitle(v string) *PostCreate {
_c.mutation.SetTitle(v)
return _c
}
// SetNillableTitle sets the "title" field if the given value is not nil.
func (_c *PostCreate) SetNillableTitle(v *string) *PostCreate {
if v != nil {
_c.SetTitle(*v)
}
return _c
}
// SetSlug sets the "slug" field.
func (_c *PostCreate) SetSlug(v string) *PostCreate {
_c.mutation.SetSlug(v)
return _c
}
// SetNillableSlug sets the "slug" field if the given value is not nil.
func (_c *PostCreate) SetNillableSlug(v *string) *PostCreate {
if v != nil {
_c.SetSlug(*v)
}
return _c
}
// SetPinned sets the "pinned" field.
func (_c *PostCreate) SetPinned(v bool) *PostCreate {
_c.mutation.SetPinned(v)
return _c
}
// SetNillablePinned sets the "pinned" field if the given value is not nil.
func (_c *PostCreate) SetNillablePinned(v *bool) *PostCreate {
if v != nil {
_c.SetPinned(*v)
}
return _c
}
// SetLastReplyAt sets the "last_reply_at" field.
func (_c *PostCreate) SetLastReplyAt(v time.Time) *PostCreate {
_c.mutation.SetLastReplyAt(v)
return _c
}
// SetNillableLastReplyAt sets the "last_reply_at" field if the given value is not nil.
func (_c *PostCreate) SetNillableLastReplyAt(v *time.Time) *PostCreate {
if v != nil {
_c.SetLastReplyAt(*v)
}
return _c
}
// SetRootPostID sets the "root_post_id" field.
func (_c *PostCreate) SetRootPostID(v xid.ID) *PostCreate {
_c.mutation.SetRootPostID(v)
return _c
}
// SetNillableRootPostID sets the "root_post_id" field if the given value is not nil.
func (_c *PostCreate) SetNillableRootPostID(v *xid.ID) *PostCreate {
if v != nil {
_c.SetRootPostID(*v)
}
return _c
}
// SetReplyToPostID sets the "reply_to_post_id" field.
func (_c *PostCreate) SetReplyToPostID(v xid.ID) *PostCreate {
_c.mutation.SetReplyToPostID(v)
return _c
}
// SetNillableReplyToPostID sets the "reply_to_post_id" field if the given value is not nil.
func (_c *PostCreate) SetNillableReplyToPostID(v *xid.ID) *PostCreate {
if v != nil {
_c.SetReplyToPostID(*v)
}
return _c
}
// SetBody sets the "body" field.
func (_c *PostCreate) SetBody(v string) *PostCreate {
_c.mutation.SetBody(v)
return _c
}
// SetShort sets the "short" field.
func (_c *PostCreate) SetShort(v string) *PostCreate {
_c.mutation.SetShort(v)
return _c
}
// SetMetadata sets the "metadata" field.
func (_c *PostCreate) SetMetadata(v map[string]interface{}) *PostCreate {
_c.mutation.SetMetadata(v)
return _c
}
// SetVisibility sets the "visibility" field.
func (_c *PostCreate) SetVisibility(v post.Visibility) *PostCreate {
_c.mutation.SetVisibility(v)
return _c
}
// SetNillableVisibility sets the "visibility" field if the given value is not nil.
func (_c *PostCreate) SetNillableVisibility(v *post.Visibility) *PostCreate {
if v != nil {
_c.SetVisibility(*v)
}
return _c
}
// SetAccountPosts sets the "account_posts" field.
func (_c *PostCreate) SetAccountPosts(v xid.ID) *PostCreate {
_c.mutation.SetAccountPosts(v)
return _c
}
// SetCategoryID sets the "category_id" field.
func (_c *PostCreate) SetCategoryID(v xid.ID) *PostCreate {
_c.mutation.SetCategoryID(v)
return _c
}
// SetNillableCategoryID sets the "category_id" field if the given value is not nil.
func (_c *PostCreate) SetNillableCategoryID(v *xid.ID) *PostCreate {
if v != nil {
_c.SetCategoryID(*v)
}
return _c
}
// SetLinkID sets the "link_id" field.
func (_c *PostCreate) SetLinkID(v xid.ID) *PostCreate {
_c.mutation.SetLinkID(v)
return _c
}
// SetNillableLinkID sets the "link_id" field if the given value is not nil.
func (_c *PostCreate) SetNillableLinkID(v *xid.ID) *PostCreate {
if v != nil {
_c.SetLinkID(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *PostCreate) SetID(v xid.ID) *PostCreate {
_c.mutation.SetID(v)
return _c
}
// SetNillableID sets the "id" field if the given value is not nil.
func (_c *PostCreate) SetNillableID(v *xid.ID) *PostCreate {
if v != nil {
_c.SetID(*v)
}
return _c
}
// SetAuthorID sets the "author" edge to the Account entity by ID.
func (_c *PostCreate) SetAuthorID(id xid.ID) *PostCreate {
_c.mutation.SetAuthorID(id)
return _c
}
// SetAuthor sets the "author" edge to the Account entity.
func (_c *PostCreate) SetAuthor(v *Account) *PostCreate {
return _c.SetAuthorID(v.ID)
}
// SetCategory sets the "category" edge to the Category entity.
func (_c *PostCreate) SetCategory(v *Category) *PostCreate {
return _c.SetCategoryID(v.ID)
}
// AddTagIDs adds the "tags" edge to the Tag entity by IDs.
func (_c *PostCreate) AddTagIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddTagIDs(ids...)
return _c
}
// AddTags adds the "tags" edges to the Tag entity.
func (_c *PostCreate) AddTags(v ...*Tag) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddTagIDs(ids...)
}
// SetRootID sets the "root" edge to the Post entity by ID.
func (_c *PostCreate) SetRootID(id xid.ID) *PostCreate {
_c.mutation.SetRootID(id)
return _c
}
// SetNillableRootID sets the "root" edge to the Post entity by ID if the given value is not nil.
func (_c *PostCreate) SetNillableRootID(id *xid.ID) *PostCreate {
if id != nil {
_c = _c.SetRootID(*id)
}
return _c
}
// SetRoot sets the "root" edge to the Post entity.
func (_c *PostCreate) SetRoot(v *Post) *PostCreate {
return _c.SetRootID(v.ID)
}
// AddPostIDs adds the "posts" edge to the Post entity by IDs.
func (_c *PostCreate) AddPostIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddPostIDs(ids...)
return _c
}
// AddPosts adds the "posts" edges to the Post entity.
func (_c *PostCreate) AddPosts(v ...*Post) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddPostIDs(ids...)
}
// SetReplyToID sets the "replyTo" edge to the Post entity by ID.
func (_c *PostCreate) SetReplyToID(id xid.ID) *PostCreate {
_c.mutation.SetReplyToID(id)
return _c
}
// SetNillableReplyToID sets the "replyTo" edge to the Post entity by ID if the given value is not nil.
func (_c *PostCreate) SetNillableReplyToID(id *xid.ID) *PostCreate {
if id != nil {
_c = _c.SetReplyToID(*id)
}
return _c
}
// SetReplyTo sets the "replyTo" edge to the Post entity.
func (_c *PostCreate) SetReplyTo(v *Post) *PostCreate {
return _c.SetReplyToID(v.ID)
}
// AddReplyIDs adds the "replies" edge to the Post entity by IDs.
func (_c *PostCreate) AddReplyIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddReplyIDs(ids...)
return _c
}
// AddReplies adds the "replies" edges to the Post entity.
func (_c *PostCreate) AddReplies(v ...*Post) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddReplyIDs(ids...)
}
// AddReactIDs adds the "reacts" edge to the React entity by IDs.
func (_c *PostCreate) AddReactIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddReactIDs(ids...)
return _c
}
// AddReacts adds the "reacts" edges to the React entity.
func (_c *PostCreate) AddReacts(v ...*React) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddReactIDs(ids...)
}
// AddLikeIDs adds the "likes" edge to the LikePost entity by IDs.
func (_c *PostCreate) AddLikeIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddLikeIDs(ids...)
return _c
}
// AddLikes adds the "likes" edges to the LikePost entity.
func (_c *PostCreate) AddLikes(v ...*LikePost) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddLikeIDs(ids...)
}
// AddMentionIDs adds the "mentions" edge to the MentionProfile entity by IDs.
func (_c *PostCreate) AddMentionIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddMentionIDs(ids...)
return _c
}
// AddMentions adds the "mentions" edges to the MentionProfile entity.
func (_c *PostCreate) AddMentions(v ...*MentionProfile) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddMentionIDs(ids...)
}
// AddAssetIDs adds the "assets" edge to the Asset entity by IDs.
func (_c *PostCreate) AddAssetIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddAssetIDs(ids...)
return _c
}
// AddAssets adds the "assets" edges to the Asset entity.
func (_c *PostCreate) AddAssets(v ...*Asset) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddAssetIDs(ids...)
}
// AddCollectionIDs adds the "collections" edge to the Collection entity by IDs.
func (_c *PostCreate) AddCollectionIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddCollectionIDs(ids...)
return _c
}
// AddCollections adds the "collections" edges to the Collection entity.
func (_c *PostCreate) AddCollections(v ...*Collection) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddCollectionIDs(ids...)
}
// SetLink sets the "link" edge to the Link entity.
func (_c *PostCreate) SetLink(v *Link) *PostCreate {
return _c.SetLinkID(v.ID)
}
// AddContentLinkIDs adds the "content_links" edge to the Link entity by IDs.
func (_c *PostCreate) AddContentLinkIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddContentLinkIDs(ids...)
return _c
}
// AddContentLinks adds the "content_links" edges to the Link entity.
func (_c *PostCreate) AddContentLinks(v ...*Link) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddContentLinkIDs(ids...)
}
// AddEventIDs adds the "event" edge to the Event entity by IDs.
func (_c *PostCreate) AddEventIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddEventIDs(ids...)
return _c
}
// AddEvent adds the "event" edges to the Event entity.
func (_c *PostCreate) AddEvent(v ...*Event) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddEventIDs(ids...)
}
// AddPostReadIDs adds the "post_reads" edge to the PostRead entity by IDs.
func (_c *PostCreate) AddPostReadIDs(ids ...xid.ID) *PostCreate {
_c.mutation.AddPostReadIDs(ids...)
return _c
}
// AddPostReads adds the "post_reads" edges to the PostRead entity.
func (_c *PostCreate) AddPostReads(v ...*PostRead) *PostCreate {
ids := make([]xid.ID, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddPostReadIDs(ids...)
}
// Mutation returns the PostMutation object of the builder.
func (_c *PostCreate) Mutation() *PostMutation {
return _c.mutation
}
// Save creates the Post in the database.
func (_c *PostCreate) Save(ctx context.Context) (*Post, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *PostCreate) SaveX(ctx context.Context) *Post {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *PostCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *PostCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *PostCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := post.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.Pinned(); !ok {
v := post.DefaultPinned
_c.mutation.SetPinned(v)
}
if _, ok := _c.mutation.Visibility(); !ok {
v := post.DefaultVisibility
_c.mutation.SetVisibility(v)
}
if _, ok := _c.mutation.ID(); !ok {
v := post.DefaultID()
_c.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *PostCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Post.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Post.updated_at"`)}
}
if _, ok := _c.mutation.First(); !ok {
return &ValidationError{Name: "first", err: errors.New(`ent: missing required field "Post.first"`)}
}
if _, ok := _c.mutation.Pinned(); !ok {
return &ValidationError{Name: "pinned", err: errors.New(`ent: missing required field "Post.pinned"`)}
}
if _, ok := _c.mutation.Body(); !ok {
return &ValidationError{Name: "body", err: errors.New(`ent: missing required field "Post.body"`)}
}
if _, ok := _c.mutation.Short(); !ok {
return &ValidationError{Name: "short", err: errors.New(`ent: missing required field "Post.short"`)}
}
if _, ok := _c.mutation.Visibility(); !ok {
return &ValidationError{Name: "visibility", err: errors.New(`ent: missing required field "Post.visibility"`)}
}
if v, ok := _c.mutation.Visibility(); ok {
if err := post.VisibilityValidator(v); err != nil {
return &ValidationError{Name: "visibility", err: fmt.Errorf(`ent: validator failed for field "Post.visibility": %w`, err)}
}
}
if _, ok := _c.mutation.AccountPosts(); !ok {
return &ValidationError{Name: "account_posts", err: errors.New(`ent: missing required field "Post.account_posts"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := post.IDValidator(v.String()); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Post.id": %w`, err)}
}
}
if len(_c.mutation.AuthorIDs()) == 0 {
return &ValidationError{Name: "author", err: errors.New(`ent: missing required edge "Post.author"`)}
}
return nil
}
func (_c *PostCreate) sqlSave(ctx context.Context) (*Post, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.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.(*xid.ID); ok {
_node.ID = *id
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
return nil, err
}
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *PostCreate) createSpec() (*Post, *sqlgraph.CreateSpec) {
var (
_node = &Post{config: _c.config}
_spec = sqlgraph.NewCreateSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeString))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(post.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(post.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.DeletedAt(); ok {
_spec.SetField(post.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = &value
}
if value, ok := _c.mutation.IndexedAt(); ok {
_spec.SetField(post.FieldIndexedAt, field.TypeTime, value)
_node.IndexedAt = &value
}
if value, ok := _c.mutation.First(); ok {
_spec.SetField(post.FieldFirst, field.TypeBool, value)
_node.First = value
}
if value, ok := _c.mutation.Title(); ok {
_spec.SetField(post.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := _c.mutation.Slug(); ok {
_spec.SetField(post.FieldSlug, field.TypeString, value)
_node.Slug = value
}
if value, ok := _c.mutation.Pinned(); ok {
_spec.SetField(post.FieldPinned, field.TypeBool, value)
_node.Pinned = value
}
if value, ok := _c.mutation.LastReplyAt(); ok {
_spec.SetField(post.FieldLastReplyAt, field.TypeTime, value)
_node.LastReplyAt = &value
}
if value, ok := _c.mutation.Body(); ok {
_spec.SetField(post.FieldBody, field.TypeString, value)
_node.Body = value
}
if value, ok := _c.mutation.Short(); ok {
_spec.SetField(post.FieldShort, field.TypeString, value)
_node.Short = value
}
if value, ok := _c.mutation.Metadata(); ok {
_spec.SetField(post.FieldMetadata, field.TypeJSON, value)
_node.Metadata = value
}
if value, ok := _c.mutation.Visibility(); ok {
_spec.SetField(post.FieldVisibility, field.TypeEnum, value)
_node.Visibility = value
}
if nodes := _c.mutation.AuthorIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: post.AuthorTable,
Columns: []string{post.AuthorColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.AccountPosts = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.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.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.CategoryID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.TagsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: post.TagsTable,
Columns: post.TagsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.RootIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: post.RootTable,
Columns: []string{post.RootColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.RootPostID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.PostsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.PostsTable,
Columns: []string{post.PostsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ReplyToIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: post.ReplyToTable,
Columns: []string{post.ReplyToColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.ReplyToPostID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.RepliesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.RepliesTable,
Columns: []string{post.RepliesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(post.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ReactsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.ReactsTable,
Columns: []string{post.ReactsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(react.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.LikesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.LikesTable,
Columns: []string{post.LikesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(likepost.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.MentionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.MentionsTable,
Columns: []string{post.MentionsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(mentionprofile.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.AssetsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: post.AssetsTable,
Columns: post.AssetsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(asset.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.CollectionsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: post.CollectionsTable,
Columns: post.CollectionsPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(collection.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.LinkIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: post.LinkTable,
Columns: []string{post.LinkColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.LinkID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.ContentLinksIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: true,
Table: post.ContentLinksTable,
Columns: post.ContentLinksPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.EventIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.EventTable,
Columns: []string{post.EventColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(event.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.PostReadsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: post.PostReadsTable,
Columns: []string{post.PostReadsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(postread.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Post.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.PostUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *PostCreate) OnConflict(opts ...sql.ConflictOption) *PostUpsertOne {
_c.conflict = opts
return &PostUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *PostCreate) OnConflictColumns(columns ...string) *PostUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &PostUpsertOne{
create: _c,
}
}
type (
// PostUpsertOne is the builder for "upsert"-ing
// one Post node.
PostUpsertOne struct {
create *PostCreate
}
// PostUpsert is the "OnConflict" setter.
PostUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *PostUpsert) SetUpdatedAt(v time.Time) *PostUpsert {
u.Set(post.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *PostUpsert) UpdateUpdatedAt() *PostUpsert {
u.SetExcluded(post.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *PostUpsert) SetDeletedAt(v time.Time) *PostUpsert {
u.Set(post.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PostUpsert) UpdateDeletedAt() *PostUpsert {
u.SetExcluded(post.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PostUpsert) ClearDeletedAt() *PostUpsert {
u.SetNull(post.FieldDeletedAt)
return u
}
// SetIndexedAt sets the "indexed_at" field.
func (u *PostUpsert) SetIndexedAt(v time.Time) *PostUpsert {
u.Set(post.FieldIndexedAt, v)
return u
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *PostUpsert) UpdateIndexedAt() *PostUpsert {
u.SetExcluded(post.FieldIndexedAt)
return u
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *PostUpsert) ClearIndexedAt() *PostUpsert {
u.SetNull(post.FieldIndexedAt)
return u
}
// SetFirst sets the "first" field.
func (u *PostUpsert) SetFirst(v bool) *PostUpsert {
u.Set(post.FieldFirst, v)
return u
}
// UpdateFirst sets the "first" field to the value that was provided on create.
func (u *PostUpsert) UpdateFirst() *PostUpsert {
u.SetExcluded(post.FieldFirst)
return u
}
// SetTitle sets the "title" field.
func (u *PostUpsert) SetTitle(v string) *PostUpsert {
u.Set(post.FieldTitle, v)
return u
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PostUpsert) UpdateTitle() *PostUpsert {
u.SetExcluded(post.FieldTitle)
return u
}
// ClearTitle clears the value of the "title" field.
func (u *PostUpsert) ClearTitle() *PostUpsert {
u.SetNull(post.FieldTitle)
return u
}
// SetSlug sets the "slug" field.
func (u *PostUpsert) SetSlug(v string) *PostUpsert {
u.Set(post.FieldSlug, v)
return u
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *PostUpsert) UpdateSlug() *PostUpsert {
u.SetExcluded(post.FieldSlug)
return u
}
// ClearSlug clears the value of the "slug" field.
func (u *PostUpsert) ClearSlug() *PostUpsert {
u.SetNull(post.FieldSlug)
return u
}
// SetPinned sets the "pinned" field.
func (u *PostUpsert) SetPinned(v bool) *PostUpsert {
u.Set(post.FieldPinned, v)
return u
}
// UpdatePinned sets the "pinned" field to the value that was provided on create.
func (u *PostUpsert) UpdatePinned() *PostUpsert {
u.SetExcluded(post.FieldPinned)
return u
}
// SetLastReplyAt sets the "last_reply_at" field.
func (u *PostUpsert) SetLastReplyAt(v time.Time) *PostUpsert {
u.Set(post.FieldLastReplyAt, v)
return u
}
// UpdateLastReplyAt sets the "last_reply_at" field to the value that was provided on create.
func (u *PostUpsert) UpdateLastReplyAt() *PostUpsert {
u.SetExcluded(post.FieldLastReplyAt)
return u
}
// ClearLastReplyAt clears the value of the "last_reply_at" field.
func (u *PostUpsert) ClearLastReplyAt() *PostUpsert {
u.SetNull(post.FieldLastReplyAt)
return u
}
// SetRootPostID sets the "root_post_id" field.
func (u *PostUpsert) SetRootPostID(v xid.ID) *PostUpsert {
u.Set(post.FieldRootPostID, v)
return u
}
// UpdateRootPostID sets the "root_post_id" field to the value that was provided on create.
func (u *PostUpsert) UpdateRootPostID() *PostUpsert {
u.SetExcluded(post.FieldRootPostID)
return u
}
// ClearRootPostID clears the value of the "root_post_id" field.
func (u *PostUpsert) ClearRootPostID() *PostUpsert {
u.SetNull(post.FieldRootPostID)
return u
}
// SetReplyToPostID sets the "reply_to_post_id" field.
func (u *PostUpsert) SetReplyToPostID(v xid.ID) *PostUpsert {
u.Set(post.FieldReplyToPostID, v)
return u
}
// UpdateReplyToPostID sets the "reply_to_post_id" field to the value that was provided on create.
func (u *PostUpsert) UpdateReplyToPostID() *PostUpsert {
u.SetExcluded(post.FieldReplyToPostID)
return u
}
// ClearReplyToPostID clears the value of the "reply_to_post_id" field.
func (u *PostUpsert) ClearReplyToPostID() *PostUpsert {
u.SetNull(post.FieldReplyToPostID)
return u
}
// SetBody sets the "body" field.
func (u *PostUpsert) SetBody(v string) *PostUpsert {
u.Set(post.FieldBody, v)
return u
}
// UpdateBody sets the "body" field to the value that was provided on create.
func (u *PostUpsert) UpdateBody() *PostUpsert {
u.SetExcluded(post.FieldBody)
return u
}
// SetShort sets the "short" field.
func (u *PostUpsert) SetShort(v string) *PostUpsert {
u.Set(post.FieldShort, v)
return u
}
// UpdateShort sets the "short" field to the value that was provided on create.
func (u *PostUpsert) UpdateShort() *PostUpsert {
u.SetExcluded(post.FieldShort)
return u
}
// SetMetadata sets the "metadata" field.
func (u *PostUpsert) SetMetadata(v map[string]interface{}) *PostUpsert {
u.Set(post.FieldMetadata, v)
return u
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *PostUpsert) UpdateMetadata() *PostUpsert {
u.SetExcluded(post.FieldMetadata)
return u
}
// ClearMetadata clears the value of the "metadata" field.
func (u *PostUpsert) ClearMetadata() *PostUpsert {
u.SetNull(post.FieldMetadata)
return u
}
// SetVisibility sets the "visibility" field.
func (u *PostUpsert) SetVisibility(v post.Visibility) *PostUpsert {
u.Set(post.FieldVisibility, v)
return u
}
// UpdateVisibility sets the "visibility" field to the value that was provided on create.
func (u *PostUpsert) UpdateVisibility() *PostUpsert {
u.SetExcluded(post.FieldVisibility)
return u
}
// SetAccountPosts sets the "account_posts" field.
func (u *PostUpsert) SetAccountPosts(v xid.ID) *PostUpsert {
u.Set(post.FieldAccountPosts, v)
return u
}
// UpdateAccountPosts sets the "account_posts" field to the value that was provided on create.
func (u *PostUpsert) UpdateAccountPosts() *PostUpsert {
u.SetExcluded(post.FieldAccountPosts)
return u
}
// SetCategoryID sets the "category_id" field.
func (u *PostUpsert) SetCategoryID(v xid.ID) *PostUpsert {
u.Set(post.FieldCategoryID, v)
return u
}
// UpdateCategoryID sets the "category_id" field to the value that was provided on create.
func (u *PostUpsert) UpdateCategoryID() *PostUpsert {
u.SetExcluded(post.FieldCategoryID)
return u
}
// ClearCategoryID clears the value of the "category_id" field.
func (u *PostUpsert) ClearCategoryID() *PostUpsert {
u.SetNull(post.FieldCategoryID)
return u
}
// SetLinkID sets the "link_id" field.
func (u *PostUpsert) SetLinkID(v xid.ID) *PostUpsert {
u.Set(post.FieldLinkID, v)
return u
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *PostUpsert) UpdateLinkID() *PostUpsert {
u.SetExcluded(post.FieldLinkID)
return u
}
// ClearLinkID clears the value of the "link_id" field.
func (u *PostUpsert) ClearLinkID() *PostUpsert {
u.SetNull(post.FieldLinkID)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(post.FieldID)
// }),
// ).
// Exec(ctx)
func (u *PostUpsertOne) UpdateNewValues() *PostUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(post.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(post.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *PostUpsertOne) Ignore() *PostUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *PostUpsertOne) DoNothing() *PostUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the PostCreate.OnConflict
// documentation for more info.
func (u *PostUpsertOne) Update(set func(*PostUpsert)) *PostUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&PostUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *PostUpsertOne) SetUpdatedAt(v time.Time) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateUpdatedAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *PostUpsertOne) SetDeletedAt(v time.Time) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateDeletedAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PostUpsertOne) ClearDeletedAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearDeletedAt()
})
}
// SetIndexedAt sets the "indexed_at" field.
func (u *PostUpsertOne) SetIndexedAt(v time.Time) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetIndexedAt(v)
})
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateIndexedAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateIndexedAt()
})
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *PostUpsertOne) ClearIndexedAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearIndexedAt()
})
}
// SetFirst sets the "first" field.
func (u *PostUpsertOne) SetFirst(v bool) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetFirst(v)
})
}
// UpdateFirst sets the "first" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateFirst() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateFirst()
})
}
// SetTitle sets the "title" field.
func (u *PostUpsertOne) SetTitle(v string) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateTitle() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateTitle()
})
}
// ClearTitle clears the value of the "title" field.
func (u *PostUpsertOne) ClearTitle() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearTitle()
})
}
// SetSlug sets the "slug" field.
func (u *PostUpsertOne) SetSlug(v string) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetSlug(v)
})
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateSlug() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateSlug()
})
}
// ClearSlug clears the value of the "slug" field.
func (u *PostUpsertOne) ClearSlug() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearSlug()
})
}
// SetPinned sets the "pinned" field.
func (u *PostUpsertOne) SetPinned(v bool) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetPinned(v)
})
}
// UpdatePinned sets the "pinned" field to the value that was provided on create.
func (u *PostUpsertOne) UpdatePinned() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdatePinned()
})
}
// SetLastReplyAt sets the "last_reply_at" field.
func (u *PostUpsertOne) SetLastReplyAt(v time.Time) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetLastReplyAt(v)
})
}
// UpdateLastReplyAt sets the "last_reply_at" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateLastReplyAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateLastReplyAt()
})
}
// ClearLastReplyAt clears the value of the "last_reply_at" field.
func (u *PostUpsertOne) ClearLastReplyAt() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearLastReplyAt()
})
}
// SetRootPostID sets the "root_post_id" field.
func (u *PostUpsertOne) SetRootPostID(v xid.ID) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetRootPostID(v)
})
}
// UpdateRootPostID sets the "root_post_id" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateRootPostID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateRootPostID()
})
}
// ClearRootPostID clears the value of the "root_post_id" field.
func (u *PostUpsertOne) ClearRootPostID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearRootPostID()
})
}
// SetReplyToPostID sets the "reply_to_post_id" field.
func (u *PostUpsertOne) SetReplyToPostID(v xid.ID) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetReplyToPostID(v)
})
}
// UpdateReplyToPostID sets the "reply_to_post_id" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateReplyToPostID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateReplyToPostID()
})
}
// ClearReplyToPostID clears the value of the "reply_to_post_id" field.
func (u *PostUpsertOne) ClearReplyToPostID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearReplyToPostID()
})
}
// SetBody sets the "body" field.
func (u *PostUpsertOne) SetBody(v string) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetBody(v)
})
}
// UpdateBody sets the "body" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateBody() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateBody()
})
}
// SetShort sets the "short" field.
func (u *PostUpsertOne) SetShort(v string) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetShort(v)
})
}
// UpdateShort sets the "short" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateShort() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateShort()
})
}
// SetMetadata sets the "metadata" field.
func (u *PostUpsertOne) SetMetadata(v map[string]interface{}) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateMetadata() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *PostUpsertOne) ClearMetadata() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearMetadata()
})
}
// SetVisibility sets the "visibility" field.
func (u *PostUpsertOne) SetVisibility(v post.Visibility) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetVisibility(v)
})
}
// UpdateVisibility sets the "visibility" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateVisibility() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateVisibility()
})
}
// SetAccountPosts sets the "account_posts" field.
func (u *PostUpsertOne) SetAccountPosts(v xid.ID) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetAccountPosts(v)
})
}
// UpdateAccountPosts sets the "account_posts" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateAccountPosts() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateAccountPosts()
})
}
// SetCategoryID sets the "category_id" field.
func (u *PostUpsertOne) SetCategoryID(v xid.ID) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetCategoryID(v)
})
}
// UpdateCategoryID sets the "category_id" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateCategoryID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateCategoryID()
})
}
// ClearCategoryID clears the value of the "category_id" field.
func (u *PostUpsertOne) ClearCategoryID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearCategoryID()
})
}
// SetLinkID sets the "link_id" field.
func (u *PostUpsertOne) SetLinkID(v xid.ID) *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.SetLinkID(v)
})
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *PostUpsertOne) UpdateLinkID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.UpdateLinkID()
})
}
// ClearLinkID clears the value of the "link_id" field.
func (u *PostUpsertOne) ClearLinkID() *PostUpsertOne {
return u.Update(func(s *PostUpsert) {
s.ClearLinkID()
})
}
// Exec executes the query.
func (u *PostUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for PostCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *PostUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *PostUpsertOne) ID(ctx context.Context) (id xid.ID, err error) {
if u.create.driver.Dialect() == dialect.MySQL {
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
// fields from the database since MySQL does not support the RETURNING clause.
return id, errors.New("ent: PostUpsertOne.ID is not supported by MySQL driver. Use PostUpsertOne.Exec instead")
}
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *PostUpsertOne) IDX(ctx context.Context) xid.ID {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// PostCreateBulk is the builder for creating many Post entities in bulk.
type PostCreateBulk struct {
config
err error
builders []*PostCreate
conflict []sql.ConflictOption
}
// Save creates the Post entities in the database.
func (_c *PostCreateBulk) Save(ctx context.Context) ([]*Post, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Post, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.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, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = _c.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.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, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *PostCreateBulk) SaveX(ctx context.Context) []*Post {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *PostCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *PostCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Post.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.PostUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *PostCreateBulk) OnConflict(opts ...sql.ConflictOption) *PostUpsertBulk {
_c.conflict = opts
return &PostUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *PostCreateBulk) OnConflictColumns(columns ...string) *PostUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &PostUpsertBulk{
create: _c,
}
}
// PostUpsertBulk is the builder for "upsert"-ing
// a bulk of Post nodes.
type PostUpsertBulk struct {
create *PostCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(post.FieldID)
// }),
// ).
// Exec(ctx)
func (u *PostUpsertBulk) UpdateNewValues() *PostUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(post.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(post.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Post.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *PostUpsertBulk) Ignore() *PostUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *PostUpsertBulk) DoNothing() *PostUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the PostCreateBulk.OnConflict
// documentation for more info.
func (u *PostUpsertBulk) Update(set func(*PostUpsert)) *PostUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&PostUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *PostUpsertBulk) SetUpdatedAt(v time.Time) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateUpdatedAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *PostUpsertBulk) SetDeletedAt(v time.Time) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateDeletedAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *PostUpsertBulk) ClearDeletedAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearDeletedAt()
})
}
// SetIndexedAt sets the "indexed_at" field.
func (u *PostUpsertBulk) SetIndexedAt(v time.Time) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetIndexedAt(v)
})
}
// UpdateIndexedAt sets the "indexed_at" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateIndexedAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateIndexedAt()
})
}
// ClearIndexedAt clears the value of the "indexed_at" field.
func (u *PostUpsertBulk) ClearIndexedAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearIndexedAt()
})
}
// SetFirst sets the "first" field.
func (u *PostUpsertBulk) SetFirst(v bool) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetFirst(v)
})
}
// UpdateFirst sets the "first" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateFirst() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateFirst()
})
}
// SetTitle sets the "title" field.
func (u *PostUpsertBulk) SetTitle(v string) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateTitle() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateTitle()
})
}
// ClearTitle clears the value of the "title" field.
func (u *PostUpsertBulk) ClearTitle() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearTitle()
})
}
// SetSlug sets the "slug" field.
func (u *PostUpsertBulk) SetSlug(v string) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetSlug(v)
})
}
// UpdateSlug sets the "slug" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateSlug() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateSlug()
})
}
// ClearSlug clears the value of the "slug" field.
func (u *PostUpsertBulk) ClearSlug() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearSlug()
})
}
// SetPinned sets the "pinned" field.
func (u *PostUpsertBulk) SetPinned(v bool) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetPinned(v)
})
}
// UpdatePinned sets the "pinned" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdatePinned() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdatePinned()
})
}
// SetLastReplyAt sets the "last_reply_at" field.
func (u *PostUpsertBulk) SetLastReplyAt(v time.Time) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetLastReplyAt(v)
})
}
// UpdateLastReplyAt sets the "last_reply_at" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateLastReplyAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateLastReplyAt()
})
}
// ClearLastReplyAt clears the value of the "last_reply_at" field.
func (u *PostUpsertBulk) ClearLastReplyAt() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearLastReplyAt()
})
}
// SetRootPostID sets the "root_post_id" field.
func (u *PostUpsertBulk) SetRootPostID(v xid.ID) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetRootPostID(v)
})
}
// UpdateRootPostID sets the "root_post_id" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateRootPostID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateRootPostID()
})
}
// ClearRootPostID clears the value of the "root_post_id" field.
func (u *PostUpsertBulk) ClearRootPostID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearRootPostID()
})
}
// SetReplyToPostID sets the "reply_to_post_id" field.
func (u *PostUpsertBulk) SetReplyToPostID(v xid.ID) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetReplyToPostID(v)
})
}
// UpdateReplyToPostID sets the "reply_to_post_id" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateReplyToPostID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateReplyToPostID()
})
}
// ClearReplyToPostID clears the value of the "reply_to_post_id" field.
func (u *PostUpsertBulk) ClearReplyToPostID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearReplyToPostID()
})
}
// SetBody sets the "body" field.
func (u *PostUpsertBulk) SetBody(v string) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetBody(v)
})
}
// UpdateBody sets the "body" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateBody() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateBody()
})
}
// SetShort sets the "short" field.
func (u *PostUpsertBulk) SetShort(v string) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetShort(v)
})
}
// UpdateShort sets the "short" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateShort() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateShort()
})
}
// SetMetadata sets the "metadata" field.
func (u *PostUpsertBulk) SetMetadata(v map[string]interface{}) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetMetadata(v)
})
}
// UpdateMetadata sets the "metadata" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateMetadata() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateMetadata()
})
}
// ClearMetadata clears the value of the "metadata" field.
func (u *PostUpsertBulk) ClearMetadata() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearMetadata()
})
}
// SetVisibility sets the "visibility" field.
func (u *PostUpsertBulk) SetVisibility(v post.Visibility) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetVisibility(v)
})
}
// UpdateVisibility sets the "visibility" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateVisibility() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateVisibility()
})
}
// SetAccountPosts sets the "account_posts" field.
func (u *PostUpsertBulk) SetAccountPosts(v xid.ID) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetAccountPosts(v)
})
}
// UpdateAccountPosts sets the "account_posts" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateAccountPosts() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateAccountPosts()
})
}
// SetCategoryID sets the "category_id" field.
func (u *PostUpsertBulk) SetCategoryID(v xid.ID) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetCategoryID(v)
})
}
// UpdateCategoryID sets the "category_id" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateCategoryID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateCategoryID()
})
}
// ClearCategoryID clears the value of the "category_id" field.
func (u *PostUpsertBulk) ClearCategoryID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearCategoryID()
})
}
// SetLinkID sets the "link_id" field.
func (u *PostUpsertBulk) SetLinkID(v xid.ID) *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.SetLinkID(v)
})
}
// UpdateLinkID sets the "link_id" field to the value that was provided on create.
func (u *PostUpsertBulk) UpdateLinkID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.UpdateLinkID()
})
}
// ClearLinkID clears the value of the "link_id" field.
func (u *PostUpsertBulk) ClearLinkID() *PostUpsertBulk {
return u.Update(func(s *PostUpsert) {
s.ClearLinkID()
})
}
// Exec executes the query.
func (u *PostUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the PostCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for PostCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *PostUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}