You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1179 lines
32 KiB
1179 lines
32 KiB
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/cloudreve/Cloudreve/v4/ent/file"
|
|
"github.com/cloudreve/Cloudreve/v4/ent/share"
|
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
|
)
|
|
|
|
// ShareCreate is the builder for creating a Share entity.
|
|
type ShareCreate struct {
|
|
config
|
|
mutation *ShareMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (sc *ShareCreate) SetCreatedAt(t time.Time) *ShareCreate {
|
|
sc.mutation.SetCreatedAt(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableCreatedAt(t *time.Time) *ShareCreate {
|
|
if t != nil {
|
|
sc.SetCreatedAt(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (sc *ShareCreate) SetUpdatedAt(t time.Time) *ShareCreate {
|
|
sc.mutation.SetUpdatedAt(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableUpdatedAt(t *time.Time) *ShareCreate {
|
|
if t != nil {
|
|
sc.SetUpdatedAt(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (sc *ShareCreate) SetDeletedAt(t time.Time) *ShareCreate {
|
|
sc.mutation.SetDeletedAt(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableDeletedAt(t *time.Time) *ShareCreate {
|
|
if t != nil {
|
|
sc.SetDeletedAt(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (sc *ShareCreate) SetPassword(s string) *ShareCreate {
|
|
sc.mutation.SetPassword(s)
|
|
return sc
|
|
}
|
|
|
|
// SetNillablePassword sets the "password" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillablePassword(s *string) *ShareCreate {
|
|
if s != nil {
|
|
sc.SetPassword(*s)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetViews sets the "views" field.
|
|
func (sc *ShareCreate) SetViews(i int) *ShareCreate {
|
|
sc.mutation.SetViews(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableViews sets the "views" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableViews(i *int) *ShareCreate {
|
|
if i != nil {
|
|
sc.SetViews(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetDownloads sets the "downloads" field.
|
|
func (sc *ShareCreate) SetDownloads(i int) *ShareCreate {
|
|
sc.mutation.SetDownloads(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableDownloads sets the "downloads" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableDownloads(i *int) *ShareCreate {
|
|
if i != nil {
|
|
sc.SetDownloads(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetExpires sets the "expires" field.
|
|
func (sc *ShareCreate) SetExpires(t time.Time) *ShareCreate {
|
|
sc.mutation.SetExpires(t)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableExpires sets the "expires" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableExpires(t *time.Time) *ShareCreate {
|
|
if t != nil {
|
|
sc.SetExpires(*t)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetRemainDownloads sets the "remain_downloads" field.
|
|
func (sc *ShareCreate) SetRemainDownloads(i int) *ShareCreate {
|
|
sc.mutation.SetRemainDownloads(i)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableRemainDownloads sets the "remain_downloads" field if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableRemainDownloads(i *int) *ShareCreate {
|
|
if i != nil {
|
|
sc.SetRemainDownloads(*i)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetProps sets the "props" field.
|
|
func (sc *ShareCreate) SetProps(tp *types.ShareProps) *ShareCreate {
|
|
sc.mutation.SetProps(tp)
|
|
return sc
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (sc *ShareCreate) SetUserID(id int) *ShareCreate {
|
|
sc.mutation.SetUserID(id)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableUserID(id *int) *ShareCreate {
|
|
if id != nil {
|
|
sc = sc.SetUserID(*id)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (sc *ShareCreate) SetUser(u *User) *ShareCreate {
|
|
return sc.SetUserID(u.ID)
|
|
}
|
|
|
|
// SetFileID sets the "file" edge to the File entity by ID.
|
|
func (sc *ShareCreate) SetFileID(id int) *ShareCreate {
|
|
sc.mutation.SetFileID(id)
|
|
return sc
|
|
}
|
|
|
|
// SetNillableFileID sets the "file" edge to the File entity by ID if the given value is not nil.
|
|
func (sc *ShareCreate) SetNillableFileID(id *int) *ShareCreate {
|
|
if id != nil {
|
|
sc = sc.SetFileID(*id)
|
|
}
|
|
return sc
|
|
}
|
|
|
|
// SetFile sets the "file" edge to the File entity.
|
|
func (sc *ShareCreate) SetFile(f *File) *ShareCreate {
|
|
return sc.SetFileID(f.ID)
|
|
}
|
|
|
|
// Mutation returns the ShareMutation object of the builder.
|
|
func (sc *ShareCreate) Mutation() *ShareMutation {
|
|
return sc.mutation
|
|
}
|
|
|
|
// Save creates the Share in the database.
|
|
func (sc *ShareCreate) Save(ctx context.Context) (*Share, error) {
|
|
if err := sc.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sc *ShareCreate) SaveX(ctx context.Context) *Share {
|
|
v, err := sc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sc *ShareCreate) Exec(ctx context.Context) error {
|
|
_, err := sc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sc *ShareCreate) ExecX(ctx context.Context) {
|
|
if err := sc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (sc *ShareCreate) defaults() error {
|
|
if _, ok := sc.mutation.CreatedAt(); !ok {
|
|
if share.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized share.DefaultCreatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := share.DefaultCreatedAt()
|
|
sc.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := sc.mutation.UpdatedAt(); !ok {
|
|
if share.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized share.DefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := share.DefaultUpdatedAt()
|
|
sc.mutation.SetUpdatedAt(v)
|
|
}
|
|
if _, ok := sc.mutation.Views(); !ok {
|
|
v := share.DefaultViews
|
|
sc.mutation.SetViews(v)
|
|
}
|
|
if _, ok := sc.mutation.Downloads(); !ok {
|
|
v := share.DefaultDownloads
|
|
sc.mutation.SetDownloads(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sc *ShareCreate) check() error {
|
|
if _, ok := sc.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Share.created_at"`)}
|
|
}
|
|
if _, ok := sc.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Share.updated_at"`)}
|
|
}
|
|
if _, ok := sc.mutation.Views(); !ok {
|
|
return &ValidationError{Name: "views", err: errors.New(`ent: missing required field "Share.views"`)}
|
|
}
|
|
if _, ok := sc.mutation.Downloads(); !ok {
|
|
return &ValidationError{Name: "downloads", err: errors.New(`ent: missing required field "Share.downloads"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sc *ShareCreate) sqlSave(ctx context.Context) (*Share, error) {
|
|
if err := sc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := sc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
sc.mutation.id = &_node.ID
|
|
sc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (sc *ShareCreate) createSpec() (*Share, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &Share{config: sc.config}
|
|
_spec = sqlgraph.NewCreateSpec(share.Table, sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt))
|
|
)
|
|
|
|
if id, ok := sc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
id64 := int64(id)
|
|
_spec.ID.Value = id64
|
|
}
|
|
|
|
_spec.OnConflict = sc.conflict
|
|
if value, ok := sc.mutation.CreatedAt(); ok {
|
|
_spec.SetField(share.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := sc.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(share.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := sc.mutation.DeletedAt(); ok {
|
|
_spec.SetField(share.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = &value
|
|
}
|
|
if value, ok := sc.mutation.Password(); ok {
|
|
_spec.SetField(share.FieldPassword, field.TypeString, value)
|
|
_node.Password = value
|
|
}
|
|
if value, ok := sc.mutation.Views(); ok {
|
|
_spec.SetField(share.FieldViews, field.TypeInt, value)
|
|
_node.Views = value
|
|
}
|
|
if value, ok := sc.mutation.Downloads(); ok {
|
|
_spec.SetField(share.FieldDownloads, field.TypeInt, value)
|
|
_node.Downloads = value
|
|
}
|
|
if value, ok := sc.mutation.Expires(); ok {
|
|
_spec.SetField(share.FieldExpires, field.TypeTime, value)
|
|
_node.Expires = &value
|
|
}
|
|
if value, ok := sc.mutation.RemainDownloads(); ok {
|
|
_spec.SetField(share.FieldRemainDownloads, field.TypeInt, value)
|
|
_node.RemainDownloads = &value
|
|
}
|
|
if value, ok := sc.mutation.Props(); ok {
|
|
_spec.SetField(share.FieldProps, field.TypeJSON, value)
|
|
_node.Props = value
|
|
}
|
|
if nodes := sc.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: share.UserTable,
|
|
Columns: []string{share.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.user_shares = &nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := sc.mutation.FileIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: share.FileTable,
|
|
Columns: []string{share.FileColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.file_shares = &nodes[0]
|
|
_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.Share.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.ShareUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (sc *ShareCreate) OnConflict(opts ...sql.ConflictOption) *ShareUpsertOne {
|
|
sc.conflict = opts
|
|
return &ShareUpsertOne{
|
|
create: sc,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (sc *ShareCreate) OnConflictColumns(columns ...string) *ShareUpsertOne {
|
|
sc.conflict = append(sc.conflict, sql.ConflictColumns(columns...))
|
|
return &ShareUpsertOne{
|
|
create: sc,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// ShareUpsertOne is the builder for "upsert"-ing
|
|
// one Share node.
|
|
ShareUpsertOne struct {
|
|
create *ShareCreate
|
|
}
|
|
|
|
// ShareUpsert is the "OnConflict" setter.
|
|
ShareUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ShareUpsert) SetUpdatedAt(v time.Time) *ShareUpsert {
|
|
u.Set(share.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateUpdatedAt() *ShareUpsert {
|
|
u.SetExcluded(share.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ShareUpsert) SetDeletedAt(v time.Time) *ShareUpsert {
|
|
u.Set(share.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateDeletedAt() *ShareUpsert {
|
|
u.SetExcluded(share.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ShareUpsert) ClearDeletedAt() *ShareUpsert {
|
|
u.SetNull(share.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (u *ShareUpsert) SetPassword(v string) *ShareUpsert {
|
|
u.Set(share.FieldPassword, v)
|
|
return u
|
|
}
|
|
|
|
// UpdatePassword sets the "password" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdatePassword() *ShareUpsert {
|
|
u.SetExcluded(share.FieldPassword)
|
|
return u
|
|
}
|
|
|
|
// ClearPassword clears the value of the "password" field.
|
|
func (u *ShareUpsert) ClearPassword() *ShareUpsert {
|
|
u.SetNull(share.FieldPassword)
|
|
return u
|
|
}
|
|
|
|
// SetViews sets the "views" field.
|
|
func (u *ShareUpsert) SetViews(v int) *ShareUpsert {
|
|
u.Set(share.FieldViews, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateViews sets the "views" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateViews() *ShareUpsert {
|
|
u.SetExcluded(share.FieldViews)
|
|
return u
|
|
}
|
|
|
|
// AddViews adds v to the "views" field.
|
|
func (u *ShareUpsert) AddViews(v int) *ShareUpsert {
|
|
u.Add(share.FieldViews, v)
|
|
return u
|
|
}
|
|
|
|
// SetDownloads sets the "downloads" field.
|
|
func (u *ShareUpsert) SetDownloads(v int) *ShareUpsert {
|
|
u.Set(share.FieldDownloads, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDownloads sets the "downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateDownloads() *ShareUpsert {
|
|
u.SetExcluded(share.FieldDownloads)
|
|
return u
|
|
}
|
|
|
|
// AddDownloads adds v to the "downloads" field.
|
|
func (u *ShareUpsert) AddDownloads(v int) *ShareUpsert {
|
|
u.Add(share.FieldDownloads, v)
|
|
return u
|
|
}
|
|
|
|
// SetExpires sets the "expires" field.
|
|
func (u *ShareUpsert) SetExpires(v time.Time) *ShareUpsert {
|
|
u.Set(share.FieldExpires, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateExpires sets the "expires" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateExpires() *ShareUpsert {
|
|
u.SetExcluded(share.FieldExpires)
|
|
return u
|
|
}
|
|
|
|
// ClearExpires clears the value of the "expires" field.
|
|
func (u *ShareUpsert) ClearExpires() *ShareUpsert {
|
|
u.SetNull(share.FieldExpires)
|
|
return u
|
|
}
|
|
|
|
// SetRemainDownloads sets the "remain_downloads" field.
|
|
func (u *ShareUpsert) SetRemainDownloads(v int) *ShareUpsert {
|
|
u.Set(share.FieldRemainDownloads, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateRemainDownloads sets the "remain_downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateRemainDownloads() *ShareUpsert {
|
|
u.SetExcluded(share.FieldRemainDownloads)
|
|
return u
|
|
}
|
|
|
|
// AddRemainDownloads adds v to the "remain_downloads" field.
|
|
func (u *ShareUpsert) AddRemainDownloads(v int) *ShareUpsert {
|
|
u.Add(share.FieldRemainDownloads, v)
|
|
return u
|
|
}
|
|
|
|
// ClearRemainDownloads clears the value of the "remain_downloads" field.
|
|
func (u *ShareUpsert) ClearRemainDownloads() *ShareUpsert {
|
|
u.SetNull(share.FieldRemainDownloads)
|
|
return u
|
|
}
|
|
|
|
// SetProps sets the "props" field.
|
|
func (u *ShareUpsert) SetProps(v *types.ShareProps) *ShareUpsert {
|
|
u.Set(share.FieldProps, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateProps sets the "props" field to the value that was provided on create.
|
|
func (u *ShareUpsert) UpdateProps() *ShareUpsert {
|
|
u.SetExcluded(share.FieldProps)
|
|
return u
|
|
}
|
|
|
|
// ClearProps clears the value of the "props" field.
|
|
func (u *ShareUpsert) ClearProps() *ShareUpsert {
|
|
u.SetNull(share.FieldProps)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ShareUpsertOne) UpdateNewValues() *ShareUpsertOne {
|
|
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.CreatedAt(); exists {
|
|
s.SetIgnore(share.FieldCreatedAt)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ShareUpsertOne) Ignore() *ShareUpsertOne {
|
|
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 *ShareUpsertOne) DoNothing() *ShareUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ShareCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *ShareUpsertOne) Update(set func(*ShareUpsert)) *ShareUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ShareUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ShareUpsertOne) SetUpdatedAt(v time.Time) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateUpdatedAt() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ShareUpsertOne) SetDeletedAt(v time.Time) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateDeletedAt() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ShareUpsertOne) ClearDeletedAt() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (u *ShareUpsertOne) SetPassword(v string) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetPassword(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePassword sets the "password" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdatePassword() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdatePassword()
|
|
})
|
|
}
|
|
|
|
// ClearPassword clears the value of the "password" field.
|
|
func (u *ShareUpsertOne) ClearPassword() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearPassword()
|
|
})
|
|
}
|
|
|
|
// SetViews sets the "views" field.
|
|
func (u *ShareUpsertOne) SetViews(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetViews(v)
|
|
})
|
|
}
|
|
|
|
// AddViews adds v to the "views" field.
|
|
func (u *ShareUpsertOne) AddViews(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddViews(v)
|
|
})
|
|
}
|
|
|
|
// UpdateViews sets the "views" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateViews() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateViews()
|
|
})
|
|
}
|
|
|
|
// SetDownloads sets the "downloads" field.
|
|
func (u *ShareUpsertOne) SetDownloads(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetDownloads(v)
|
|
})
|
|
}
|
|
|
|
// AddDownloads adds v to the "downloads" field.
|
|
func (u *ShareUpsertOne) AddDownloads(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddDownloads(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDownloads sets the "downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateDownloads() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateDownloads()
|
|
})
|
|
}
|
|
|
|
// SetExpires sets the "expires" field.
|
|
func (u *ShareUpsertOne) SetExpires(v time.Time) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetExpires(v)
|
|
})
|
|
}
|
|
|
|
// UpdateExpires sets the "expires" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateExpires() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateExpires()
|
|
})
|
|
}
|
|
|
|
// ClearExpires clears the value of the "expires" field.
|
|
func (u *ShareUpsertOne) ClearExpires() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearExpires()
|
|
})
|
|
}
|
|
|
|
// SetRemainDownloads sets the "remain_downloads" field.
|
|
func (u *ShareUpsertOne) SetRemainDownloads(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetRemainDownloads(v)
|
|
})
|
|
}
|
|
|
|
// AddRemainDownloads adds v to the "remain_downloads" field.
|
|
func (u *ShareUpsertOne) AddRemainDownloads(v int) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddRemainDownloads(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemainDownloads sets the "remain_downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateRemainDownloads() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateRemainDownloads()
|
|
})
|
|
}
|
|
|
|
// ClearRemainDownloads clears the value of the "remain_downloads" field.
|
|
func (u *ShareUpsertOne) ClearRemainDownloads() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearRemainDownloads()
|
|
})
|
|
}
|
|
|
|
// SetProps sets the "props" field.
|
|
func (u *ShareUpsertOne) SetProps(v *types.ShareProps) *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetProps(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProps sets the "props" field to the value that was provided on create.
|
|
func (u *ShareUpsertOne) UpdateProps() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateProps()
|
|
})
|
|
}
|
|
|
|
// ClearProps clears the value of the "props" field.
|
|
func (u *ShareUpsertOne) ClearProps() *ShareUpsertOne {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearProps()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ShareUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for ShareCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ShareUpsertOne) 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 *ShareUpsertOne) ID(ctx context.Context) (id int, err error) {
|
|
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 *ShareUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
func (m *ShareCreate) SetRawID(t int) *ShareCreate {
|
|
m.mutation.SetRawID(t)
|
|
return m
|
|
}
|
|
|
|
// ShareCreateBulk is the builder for creating many Share entities in bulk.
|
|
type ShareCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ShareCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the Share entities in the database.
|
|
func (scb *ShareCreateBulk) Save(ctx context.Context) ([]*Share, error) {
|
|
if scb.err != nil {
|
|
return nil, scb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
|
nodes := make([]*Share, len(scb.builders))
|
|
mutators := make([]Mutator, len(scb.builders))
|
|
for i := range scb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := scb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ShareMutation)
|
|
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, scb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = scb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, scb.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
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(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, scb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (scb *ShareCreateBulk) SaveX(ctx context.Context) []*Share {
|
|
v, err := scb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (scb *ShareCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := scb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (scb *ShareCreateBulk) ExecX(ctx context.Context) {
|
|
if err := scb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.Share.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.ShareUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (scb *ShareCreateBulk) OnConflict(opts ...sql.ConflictOption) *ShareUpsertBulk {
|
|
scb.conflict = opts
|
|
return &ShareUpsertBulk{
|
|
create: scb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (scb *ShareCreateBulk) OnConflictColumns(columns ...string) *ShareUpsertBulk {
|
|
scb.conflict = append(scb.conflict, sql.ConflictColumns(columns...))
|
|
return &ShareUpsertBulk{
|
|
create: scb,
|
|
}
|
|
}
|
|
|
|
// ShareUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of Share nodes.
|
|
type ShareUpsertBulk struct {
|
|
create *ShareCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *ShareUpsertBulk) UpdateNewValues() *ShareUpsertBulk {
|
|
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.CreatedAt(); exists {
|
|
s.SetIgnore(share.FieldCreatedAt)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.Share.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *ShareUpsertBulk) Ignore() *ShareUpsertBulk {
|
|
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 *ShareUpsertBulk) DoNothing() *ShareUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the ShareCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *ShareUpsertBulk) Update(set func(*ShareUpsert)) *ShareUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&ShareUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *ShareUpsertBulk) SetUpdatedAt(v time.Time) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateUpdatedAt() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *ShareUpsertBulk) SetDeletedAt(v time.Time) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateDeletedAt() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *ShareUpsertBulk) ClearDeletedAt() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetPassword sets the "password" field.
|
|
func (u *ShareUpsertBulk) SetPassword(v string) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetPassword(v)
|
|
})
|
|
}
|
|
|
|
// UpdatePassword sets the "password" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdatePassword() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdatePassword()
|
|
})
|
|
}
|
|
|
|
// ClearPassword clears the value of the "password" field.
|
|
func (u *ShareUpsertBulk) ClearPassword() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearPassword()
|
|
})
|
|
}
|
|
|
|
// SetViews sets the "views" field.
|
|
func (u *ShareUpsertBulk) SetViews(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetViews(v)
|
|
})
|
|
}
|
|
|
|
// AddViews adds v to the "views" field.
|
|
func (u *ShareUpsertBulk) AddViews(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddViews(v)
|
|
})
|
|
}
|
|
|
|
// UpdateViews sets the "views" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateViews() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateViews()
|
|
})
|
|
}
|
|
|
|
// SetDownloads sets the "downloads" field.
|
|
func (u *ShareUpsertBulk) SetDownloads(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetDownloads(v)
|
|
})
|
|
}
|
|
|
|
// AddDownloads adds v to the "downloads" field.
|
|
func (u *ShareUpsertBulk) AddDownloads(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddDownloads(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDownloads sets the "downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateDownloads() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateDownloads()
|
|
})
|
|
}
|
|
|
|
// SetExpires sets the "expires" field.
|
|
func (u *ShareUpsertBulk) SetExpires(v time.Time) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetExpires(v)
|
|
})
|
|
}
|
|
|
|
// UpdateExpires sets the "expires" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateExpires() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateExpires()
|
|
})
|
|
}
|
|
|
|
// ClearExpires clears the value of the "expires" field.
|
|
func (u *ShareUpsertBulk) ClearExpires() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearExpires()
|
|
})
|
|
}
|
|
|
|
// SetRemainDownloads sets the "remain_downloads" field.
|
|
func (u *ShareUpsertBulk) SetRemainDownloads(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetRemainDownloads(v)
|
|
})
|
|
}
|
|
|
|
// AddRemainDownloads adds v to the "remain_downloads" field.
|
|
func (u *ShareUpsertBulk) AddRemainDownloads(v int) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.AddRemainDownloads(v)
|
|
})
|
|
}
|
|
|
|
// UpdateRemainDownloads sets the "remain_downloads" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateRemainDownloads() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateRemainDownloads()
|
|
})
|
|
}
|
|
|
|
// ClearRemainDownloads clears the value of the "remain_downloads" field.
|
|
func (u *ShareUpsertBulk) ClearRemainDownloads() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearRemainDownloads()
|
|
})
|
|
}
|
|
|
|
// SetProps sets the "props" field.
|
|
func (u *ShareUpsertBulk) SetProps(v *types.ShareProps) *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.SetProps(v)
|
|
})
|
|
}
|
|
|
|
// UpdateProps sets the "props" field to the value that was provided on create.
|
|
func (u *ShareUpsertBulk) UpdateProps() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.UpdateProps()
|
|
})
|
|
}
|
|
|
|
// ClearProps clears the value of the "props" field.
|
|
func (u *ShareUpsertBulk) ClearProps() *ShareUpsertBulk {
|
|
return u.Update(func(s *ShareUpsert) {
|
|
s.ClearProps()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *ShareUpsertBulk) 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 ShareCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for ShareCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *ShareUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|