Merge pull request #188 from Dvorinka/feat/paid-shares
feat: paid share links with credit purchase and resume ticketspull/3587/head
commit
a717ed5c6d
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@
|
|||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"entgo.io/ent/schema/index"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchase records a points purchase of a paid share. One row per
|
||||||
|
// (share, buyer); the ticket acts as a bearer credential to restore access
|
||||||
|
// after session loss.
|
||||||
|
type SharePurchase struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fields of the SharePurchase.
|
||||||
|
func (SharePurchase) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.Int("share_id"),
|
||||||
|
field.Int("buyer_id"),
|
||||||
|
field.Int("points"),
|
||||||
|
field.String("ticket").
|
||||||
|
Unique().
|
||||||
|
NotEmpty(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the SharePurchase.
|
||||||
|
func (SharePurchase) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("share", Share.Type).
|
||||||
|
Ref("purchases").
|
||||||
|
Field("share_id").
|
||||||
|
Unique().
|
||||||
|
Required(),
|
||||||
|
edge.From("buyer", User.Type).
|
||||||
|
Ref("share_purchases").
|
||||||
|
Field("buyer_id").
|
||||||
|
Unique().
|
||||||
|
Required(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SharePurchase) Indexes() []ent.Index {
|
||||||
|
return []ent.Index{
|
||||||
|
index.Fields("share_id", "buyer_id").
|
||||||
|
Unique(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SharePurchase) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
CommonMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,239 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/share"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/sharepurchase"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchase is the model entity for the SharePurchase schema.
|
||||||
|
type SharePurchase struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// DeletedAt holds the value of the "deleted_at" field.
|
||||||
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||||
|
// ShareID holds the value of the "share_id" field.
|
||||||
|
ShareID int `json:"share_id,omitempty"`
|
||||||
|
// BuyerID holds the value of the "buyer_id" field.
|
||||||
|
BuyerID int `json:"buyer_id,omitempty"`
|
||||||
|
// Points holds the value of the "points" field.
|
||||||
|
Points int `json:"points,omitempty"`
|
||||||
|
// Ticket holds the value of the "ticket" field.
|
||||||
|
Ticket string `json:"ticket,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the SharePurchaseQuery when eager-loading is set.
|
||||||
|
Edges SharePurchaseEdges `json:"edges"`
|
||||||
|
selectValues sql.SelectValues
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type SharePurchaseEdges struct {
|
||||||
|
// Share holds the value of the share edge.
|
||||||
|
Share *Share `json:"share,omitempty"`
|
||||||
|
// Buyer holds the value of the buyer edge.
|
||||||
|
Buyer *User `json:"buyer,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareOrErr returns the Share value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e SharePurchaseEdges) ShareOrErr() (*Share, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.Share == nil {
|
||||||
|
// Edge was loaded but was not found.
|
||||||
|
return nil, &NotFoundError{label: share.Label}
|
||||||
|
}
|
||||||
|
return e.Share, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "share"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerOrErr returns the Buyer value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e SharePurchaseEdges) BuyerOrErr() (*User, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
if e.Buyer == nil {
|
||||||
|
// Edge was loaded but was not found.
|
||||||
|
return nil, &NotFoundError{label: user.Label}
|
||||||
|
}
|
||||||
|
return e.Buyer, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "buyer"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*SharePurchase) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case sharepurchase.FieldID, sharepurchase.FieldShareID, sharepurchase.FieldBuyerID, sharepurchase.FieldPoints:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case sharepurchase.FieldTicket:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case sharepurchase.FieldCreatedAt, sharepurchase.FieldUpdatedAt, sharepurchase.FieldDeletedAt:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
values[i] = new(sql.UnknownType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the SharePurchase fields.
|
||||||
|
func (sp *SharePurchase) assignValues(columns []string, values []any) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case sharepurchase.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
sp.ID = int(value.Int64)
|
||||||
|
case sharepurchase.FieldCreatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldDeletedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.DeletedAt = new(time.Time)
|
||||||
|
*sp.DeletedAt = value.Time
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldShareID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field share_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.ShareID = int(value.Int64)
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldBuyerID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field buyer_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.BuyerID = int(value.Int64)
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldPoints:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field points", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.Points = int(value.Int64)
|
||||||
|
}
|
||||||
|
case sharepurchase.FieldTicket:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field ticket", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
sp.Ticket = value.String
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
sp.selectValues.Set(columns[i], values[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the SharePurchase.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (sp *SharePurchase) Value(name string) (ent.Value, error) {
|
||||||
|
return sp.selectValues.Get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryShare queries the "share" edge of the SharePurchase entity.
|
||||||
|
func (sp *SharePurchase) QueryShare() *ShareQuery {
|
||||||
|
return NewSharePurchaseClient(sp.config).QueryShare(sp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBuyer queries the "buyer" edge of the SharePurchase entity.
|
||||||
|
func (sp *SharePurchase) QueryBuyer() *UserQuery {
|
||||||
|
return NewSharePurchaseClient(sp.config).QueryBuyer(sp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this SharePurchase.
|
||||||
|
// Note that you need to call SharePurchase.Unwrap() before calling this method if this SharePurchase
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (sp *SharePurchase) Update() *SharePurchaseUpdateOne {
|
||||||
|
return NewSharePurchaseClient(sp.config).UpdateOne(sp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the SharePurchase entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (sp *SharePurchase) Unwrap() *SharePurchase {
|
||||||
|
_tx, ok := sp.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: SharePurchase is not a transactional entity")
|
||||||
|
}
|
||||||
|
sp.config.driver = _tx.drv
|
||||||
|
return sp
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (sp *SharePurchase) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("SharePurchase(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", sp.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(sp.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(sp.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
if v := sp.DeletedAt; v != nil {
|
||||||
|
builder.WriteString("deleted_at=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("share_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", sp.ShareID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("buyer_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", sp.BuyerID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("points=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", sp.Points))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("ticket=")
|
||||||
|
builder.WriteString(sp.Ticket)
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShare manually set the edge as loaded state.
|
||||||
|
func (e *SharePurchase) SetShare(v *Share) {
|
||||||
|
e.Edges.Share = v
|
||||||
|
e.Edges.loadedTypes[0] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyer manually set the edge as loaded state.
|
||||||
|
func (e *SharePurchase) SetBuyer(v *User) {
|
||||||
|
e.Edges.Buyer = v
|
||||||
|
e.Edges.loadedTypes[1] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchases is a parsable slice of SharePurchase.
|
||||||
|
type SharePurchases []*SharePurchase
|
||||||
@ -0,0 +1,163 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package sharepurchase
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the sharepurchase type in the database.
|
||||||
|
Label = "share_purchase"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
||||||
|
FieldDeletedAt = "deleted_at"
|
||||||
|
// FieldShareID holds the string denoting the share_id field in the database.
|
||||||
|
FieldShareID = "share_id"
|
||||||
|
// FieldBuyerID holds the string denoting the buyer_id field in the database.
|
||||||
|
FieldBuyerID = "buyer_id"
|
||||||
|
// FieldPoints holds the string denoting the points field in the database.
|
||||||
|
FieldPoints = "points"
|
||||||
|
// FieldTicket holds the string denoting the ticket field in the database.
|
||||||
|
FieldTicket = "ticket"
|
||||||
|
// EdgeShare holds the string denoting the share edge name in mutations.
|
||||||
|
EdgeShare = "share"
|
||||||
|
// EdgeBuyer holds the string denoting the buyer edge name in mutations.
|
||||||
|
EdgeBuyer = "buyer"
|
||||||
|
// Table holds the table name of the sharepurchase in the database.
|
||||||
|
Table = "share_purchases"
|
||||||
|
// ShareTable is the table that holds the share relation/edge.
|
||||||
|
ShareTable = "share_purchases"
|
||||||
|
// ShareInverseTable is the table name for the Share entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "share" package.
|
||||||
|
ShareInverseTable = "shares"
|
||||||
|
// ShareColumn is the table column denoting the share relation/edge.
|
||||||
|
ShareColumn = "share_id"
|
||||||
|
// BuyerTable is the table that holds the buyer relation/edge.
|
||||||
|
BuyerTable = "share_purchases"
|
||||||
|
// BuyerInverseTable is the table name for the User entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||||
|
BuyerInverseTable = "users"
|
||||||
|
// BuyerColumn is the table column denoting the buyer relation/edge.
|
||||||
|
BuyerColumn = "buyer_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for sharepurchase fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldDeletedAt,
|
||||||
|
FieldShareID,
|
||||||
|
FieldBuyerID,
|
||||||
|
FieldPoints,
|
||||||
|
FieldTicket,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that the variables below are initialized by the runtime
|
||||||
|
// package on the initialization of the application. Therefore,
|
||||||
|
// it should be imported in the main as follows:
|
||||||
|
//
|
||||||
|
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
||||||
|
var (
|
||||||
|
Hooks [1]ent.Hook
|
||||||
|
Interceptors [1]ent.Interceptor
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// TicketValidator is a validator for the "ticket" field. It is called by the builders before save.
|
||||||
|
TicketValidator func(string) error
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the SharePurchase queries.
|
||||||
|
type OrderOption func(*sql.Selector)
|
||||||
|
|
||||||
|
// ByID orders the results by the id field.
|
||||||
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByCreatedAt orders the results by the created_at field.
|
||||||
|
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByUpdatedAt orders the results by the updated_at field.
|
||||||
|
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByDeletedAt orders the results by the deleted_at field.
|
||||||
|
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByShareID orders the results by the share_id field.
|
||||||
|
func ByShareID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldShareID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBuyerID orders the results by the buyer_id field.
|
||||||
|
func ByBuyerID(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldBuyerID, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByPoints orders the results by the points field.
|
||||||
|
func ByPoints(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldPoints, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByTicket orders the results by the ticket field.
|
||||||
|
func ByTicket(opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return sql.OrderByField(FieldTicket, opts...).ToFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByShareField orders the results by share field.
|
||||||
|
func ByShareField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newShareStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ByBuyerField orders the results by buyer field.
|
||||||
|
func ByBuyerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
sqlgraph.OrderByNeighborTerms(s, newBuyerStep(), sql.OrderByField(field, opts...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func newShareStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ShareInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ShareTable, ShareColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
func newBuyerStep() *sqlgraph.Step {
|
||||||
|
return sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(BuyerInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, BuyerTable, BuyerColumn),
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,427 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package sharepurchase
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldID, ids...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldID, id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
|
||||||
|
func DeletedAt(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareID applies equality check predicate on the "share_id" field. It's identical to ShareIDEQ.
|
||||||
|
func ShareID(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldShareID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerID applies equality check predicate on the "buyer_id" field. It's identical to BuyerIDEQ.
|
||||||
|
func BuyerID(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldBuyerID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Points applies equality check predicate on the "points" field. It's identical to PointsEQ.
|
||||||
|
func Points(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ticket applies equality check predicate on the "ticket" field. It's identical to TicketEQ.
|
||||||
|
func Ticket(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldCreatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldUpdatedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtNEQ(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtIn applies the In predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldDeletedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtNotIn(vs ...time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldDeletedAt, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtGT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtGTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtLT(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtLTE(v time.Time) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldDeletedAt, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtIsNil() predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIsNull(FieldDeletedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
|
||||||
|
func DeletedAtNotNil() predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotNull(FieldDeletedAt))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareIDEQ applies the EQ predicate on the "share_id" field.
|
||||||
|
func ShareIDEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldShareID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareIDNEQ applies the NEQ predicate on the "share_id" field.
|
||||||
|
func ShareIDNEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldShareID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareIDIn applies the In predicate on the "share_id" field.
|
||||||
|
func ShareIDIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldShareID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShareIDNotIn applies the NotIn predicate on the "share_id" field.
|
||||||
|
func ShareIDNotIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldShareID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerIDEQ applies the EQ predicate on the "buyer_id" field.
|
||||||
|
func BuyerIDEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldBuyerID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerIDNEQ applies the NEQ predicate on the "buyer_id" field.
|
||||||
|
func BuyerIDNEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldBuyerID, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerIDIn applies the In predicate on the "buyer_id" field.
|
||||||
|
func BuyerIDIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldBuyerID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuyerIDNotIn applies the NotIn predicate on the "buyer_id" field.
|
||||||
|
func BuyerIDNotIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldBuyerID, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsEQ applies the EQ predicate on the "points" field.
|
||||||
|
func PointsEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsNEQ applies the NEQ predicate on the "points" field.
|
||||||
|
func PointsNEQ(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsIn applies the In predicate on the "points" field.
|
||||||
|
func PointsIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldPoints, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsNotIn applies the NotIn predicate on the "points" field.
|
||||||
|
func PointsNotIn(vs ...int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldPoints, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsGT applies the GT predicate on the "points" field.
|
||||||
|
func PointsGT(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsGTE applies the GTE predicate on the "points" field.
|
||||||
|
func PointsGTE(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsLT applies the LT predicate on the "points" field.
|
||||||
|
func PointsLT(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// PointsLTE applies the LTE predicate on the "points" field.
|
||||||
|
func PointsLTE(v int) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldPoints, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketEQ applies the EQ predicate on the "ticket" field.
|
||||||
|
func TicketEQ(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEQ(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketNEQ applies the NEQ predicate on the "ticket" field.
|
||||||
|
func TicketNEQ(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNEQ(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketIn applies the In predicate on the "ticket" field.
|
||||||
|
func TicketIn(vs ...string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldIn(FieldTicket, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketNotIn applies the NotIn predicate on the "ticket" field.
|
||||||
|
func TicketNotIn(vs ...string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldNotIn(FieldTicket, vs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketGT applies the GT predicate on the "ticket" field.
|
||||||
|
func TicketGT(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGT(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketGTE applies the GTE predicate on the "ticket" field.
|
||||||
|
func TicketGTE(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldGTE(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketLT applies the LT predicate on the "ticket" field.
|
||||||
|
func TicketLT(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLT(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketLTE applies the LTE predicate on the "ticket" field.
|
||||||
|
func TicketLTE(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldLTE(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketContains applies the Contains predicate on the "ticket" field.
|
||||||
|
func TicketContains(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldContains(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketHasPrefix applies the HasPrefix predicate on the "ticket" field.
|
||||||
|
func TicketHasPrefix(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldHasPrefix(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketHasSuffix applies the HasSuffix predicate on the "ticket" field.
|
||||||
|
func TicketHasSuffix(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldHasSuffix(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketEqualFold applies the EqualFold predicate on the "ticket" field.
|
||||||
|
func TicketEqualFold(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldEqualFold(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TicketContainsFold applies the ContainsFold predicate on the "ticket" field.
|
||||||
|
func TicketContainsFold(v string) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.FieldContainsFold(FieldTicket, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasShare applies the HasEdge predicate on the "share" edge.
|
||||||
|
func HasShare() predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ShareTable, ShareColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasShareWith applies the HasEdge predicate on the "share" edge with a given conditions (other predicates).
|
||||||
|
func HasShareWith(preds ...predicate.Share) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(func(s *sql.Selector) {
|
||||||
|
step := newShareStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBuyer applies the HasEdge predicate on the "buyer" edge.
|
||||||
|
func HasBuyer() predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, BuyerTable, BuyerColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBuyerWith applies the HasEdge predicate on the "buyer" edge with a given conditions (other predicates).
|
||||||
|
func HasBuyerWith(preds ...predicate.User) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(func(s *sql.Selector) {
|
||||||
|
step := newBuyerStep()
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.SharePurchase) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.AndPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.SharePurchase) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.OrPredicates(predicates...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.SharePurchase) predicate.SharePurchase {
|
||||||
|
return predicate.SharePurchase(sql.NotPredicates(p))
|
||||||
|
}
|
||||||
@ -0,0 +1,890 @@
|
|||||||
|
// 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/share"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/sharepurchase"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchaseCreate is the builder for creating a SharePurchase entity.
|
||||||
|
type SharePurchaseCreate struct {
|
||||||
|
config
|
||||||
|
mutation *SharePurchaseMutation
|
||||||
|
hooks []Hook
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetCreatedAt(t time.Time) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetCreatedAt(t)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (spc *SharePurchaseCreate) SetNillableCreatedAt(t *time.Time) *SharePurchaseCreate {
|
||||||
|
if t != nil {
|
||||||
|
spc.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetUpdatedAt(t time.Time) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetUpdatedAt(t)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (spc *SharePurchaseCreate) SetNillableUpdatedAt(t *time.Time) *SharePurchaseCreate {
|
||||||
|
if t != nil {
|
||||||
|
spc.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetDeletedAt(t time.Time) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetDeletedAt(t)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||||
|
func (spc *SharePurchaseCreate) SetNillableDeletedAt(t *time.Time) *SharePurchaseCreate {
|
||||||
|
if t != nil {
|
||||||
|
spc.SetDeletedAt(*t)
|
||||||
|
}
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetShareID(i int) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetShareID(i)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetBuyerID(i int) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetBuyerID(i)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetPoints(i int) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetPoints(i)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (spc *SharePurchaseCreate) SetTicket(s string) *SharePurchaseCreate {
|
||||||
|
spc.mutation.SetTicket(s)
|
||||||
|
return spc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShare sets the "share" edge to the Share entity.
|
||||||
|
func (spc *SharePurchaseCreate) SetShare(s *Share) *SharePurchaseCreate {
|
||||||
|
return spc.SetShareID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyer sets the "buyer" edge to the User entity.
|
||||||
|
func (spc *SharePurchaseCreate) SetBuyer(u *User) *SharePurchaseCreate {
|
||||||
|
return spc.SetBuyerID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the SharePurchaseMutation object of the builder.
|
||||||
|
func (spc *SharePurchaseCreate) Mutation() *SharePurchaseMutation {
|
||||||
|
return spc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the SharePurchase in the database.
|
||||||
|
func (spc *SharePurchaseCreate) Save(ctx context.Context) (*SharePurchase, error) {
|
||||||
|
if err := spc.defaults(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return withHooks(ctx, spc.sqlSave, spc.mutation, spc.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (spc *SharePurchaseCreate) SaveX(ctx context.Context) *SharePurchase {
|
||||||
|
v, err := spc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (spc *SharePurchaseCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := spc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spc *SharePurchaseCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := spc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (spc *SharePurchaseCreate) defaults() error {
|
||||||
|
if _, ok := spc.mutation.CreatedAt(); !ok {
|
||||||
|
if sharepurchase.DefaultCreatedAt == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized sharepurchase.DefaultCreatedAt (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
v := sharepurchase.DefaultCreatedAt()
|
||||||
|
spc.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.UpdatedAt(); !ok {
|
||||||
|
if sharepurchase.DefaultUpdatedAt == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized sharepurchase.DefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
v := sharepurchase.DefaultUpdatedAt()
|
||||||
|
spc.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (spc *SharePurchaseCreate) check() error {
|
||||||
|
if _, ok := spc.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SharePurchase.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SharePurchase.updated_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.ShareID(); !ok {
|
||||||
|
return &ValidationError{Name: "share_id", err: errors.New(`ent: missing required field "SharePurchase.share_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.BuyerID(); !ok {
|
||||||
|
return &ValidationError{Name: "buyer_id", err: errors.New(`ent: missing required field "SharePurchase.buyer_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.Points(); !ok {
|
||||||
|
return &ValidationError{Name: "points", err: errors.New(`ent: missing required field "SharePurchase.points"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.Ticket(); !ok {
|
||||||
|
return &ValidationError{Name: "ticket", err: errors.New(`ent: missing required field "SharePurchase.ticket"`)}
|
||||||
|
}
|
||||||
|
if v, ok := spc.mutation.Ticket(); ok {
|
||||||
|
if err := sharepurchase.TicketValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "ticket", err: fmt.Errorf(`ent: validator failed for field "SharePurchase.ticket": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.ShareID(); !ok {
|
||||||
|
return &ValidationError{Name: "share", err: errors.New(`ent: missing required edge "SharePurchase.share"`)}
|
||||||
|
}
|
||||||
|
if _, ok := spc.mutation.BuyerID(); !ok {
|
||||||
|
return &ValidationError{Name: "buyer", err: errors.New(`ent: missing required edge "SharePurchase.buyer"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spc *SharePurchaseCreate) sqlSave(ctx context.Context) (*SharePurchase, error) {
|
||||||
|
if err := spc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_node, _spec := spc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, spc.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)
|
||||||
|
spc.mutation.id = &_node.ID
|
||||||
|
spc.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spc *SharePurchaseCreate) createSpec() (*SharePurchase, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &SharePurchase{config: spc.config}
|
||||||
|
_spec = sqlgraph.NewCreateSpec(sharepurchase.Table, sqlgraph.NewFieldSpec(sharepurchase.FieldID, field.TypeInt))
|
||||||
|
)
|
||||||
|
|
||||||
|
if id, ok := spc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
id64 := int64(id)
|
||||||
|
_spec.ID.Value = id64
|
||||||
|
}
|
||||||
|
|
||||||
|
_spec.OnConflict = spc.conflict
|
||||||
|
if value, ok := spc.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := spc.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := spc.mutation.DeletedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldDeletedAt, field.TypeTime, value)
|
||||||
|
_node.DeletedAt = &value
|
||||||
|
}
|
||||||
|
if value, ok := spc.mutation.Points(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldPoints, field.TypeInt, value)
|
||||||
|
_node.Points = value
|
||||||
|
}
|
||||||
|
if value, ok := spc.mutation.Ticket(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldTicket, field.TypeString, value)
|
||||||
|
_node.Ticket = value
|
||||||
|
}
|
||||||
|
if nodes := spc.mutation.ShareIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.ShareTable,
|
||||||
|
Columns: []string{sharepurchase.ShareColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.ShareID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := spc.mutation.BuyerIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.BuyerTable,
|
||||||
|
Columns: []string{sharepurchase.BuyerColumn},
|
||||||
|
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.BuyerID = 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.SharePurchase.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.SharePurchaseUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (spc *SharePurchaseCreate) OnConflict(opts ...sql.ConflictOption) *SharePurchaseUpsertOne {
|
||||||
|
spc.conflict = opts
|
||||||
|
return &SharePurchaseUpsertOne{
|
||||||
|
create: spc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (spc *SharePurchaseCreate) OnConflictColumns(columns ...string) *SharePurchaseUpsertOne {
|
||||||
|
spc.conflict = append(spc.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &SharePurchaseUpsertOne{
|
||||||
|
create: spc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SharePurchaseUpsertOne is the builder for "upsert"-ing
|
||||||
|
// one SharePurchase node.
|
||||||
|
SharePurchaseUpsertOne struct {
|
||||||
|
create *SharePurchaseCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseUpsert is the "OnConflict" setter.
|
||||||
|
SharePurchaseUpsert struct {
|
||||||
|
*sql.UpdateSet
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetUpdatedAt(v time.Time) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldUpdatedAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdateUpdatedAt() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldUpdatedAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetDeletedAt(v time.Time) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldDeletedAt, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdateDeletedAt() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldDeletedAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsert) ClearDeletedAt() *SharePurchaseUpsert {
|
||||||
|
u.SetNull(sharepurchase.FieldDeletedAt)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetShareID(v int) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldShareID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateShareID sets the "share_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdateShareID() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldShareID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetBuyerID(v int) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldBuyerID, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateBuyerID sets the "buyer_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdateBuyerID() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldBuyerID)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetPoints(v int) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldPoints, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePoints sets the "points" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdatePoints() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldPoints)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPoints adds v to the "points" field.
|
||||||
|
func (u *SharePurchaseUpsert) AddPoints(v int) *SharePurchaseUpsert {
|
||||||
|
u.Add(sharepurchase.FieldPoints, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (u *SharePurchaseUpsert) SetTicket(v string) *SharePurchaseUpsert {
|
||||||
|
u.Set(sharepurchase.FieldTicket, v)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTicket sets the "ticket" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsert) UpdateTicket() *SharePurchaseUpsert {
|
||||||
|
u.SetExcluded(sharepurchase.FieldTicket)
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateNewValues() *SharePurchaseUpsertOne {
|
||||||
|
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(sharepurchase.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *SharePurchaseUpsertOne) Ignore() *SharePurchaseUpsertOne {
|
||||||
|
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 *SharePurchaseUpsertOne) DoNothing() *SharePurchaseUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the SharePurchaseCreate.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *SharePurchaseUpsertOne) Update(set func(*SharePurchaseUpsert)) *SharePurchaseUpsertOne {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&SharePurchaseUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetUpdatedAt(v time.Time) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateUpdatedAt() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetDeletedAt(v time.Time) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetDeletedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateDeletedAt() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateDeletedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) ClearDeletedAt() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.ClearDeletedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetShareID(v int) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetShareID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateShareID sets the "share_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateShareID() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateShareID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetBuyerID(v int) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetBuyerID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateBuyerID sets the "buyer_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateBuyerID() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateBuyerID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetPoints(v int) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetPoints(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPoints adds v to the "points" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) AddPoints(v int) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.AddPoints(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePoints sets the "points" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdatePoints() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdatePoints()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (u *SharePurchaseUpsertOne) SetTicket(v string) *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetTicket(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTicket sets the "ticket" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertOne) UpdateTicket() *SharePurchaseUpsertOne {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateTicket()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *SharePurchaseUpsertOne) Exec(ctx context.Context) error {
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for SharePurchaseCreate.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *SharePurchaseUpsertOne) 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 *SharePurchaseUpsertOne) 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 *SharePurchaseUpsertOne) IDX(ctx context.Context) int {
|
||||||
|
id, err := u.ID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SharePurchaseCreate) SetRawID(t int) *SharePurchaseCreate {
|
||||||
|
m.mutation.SetRawID(t)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseCreateBulk is the builder for creating many SharePurchase entities in bulk.
|
||||||
|
type SharePurchaseCreateBulk struct {
|
||||||
|
config
|
||||||
|
err error
|
||||||
|
builders []*SharePurchaseCreate
|
||||||
|
conflict []sql.ConflictOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the SharePurchase entities in the database.
|
||||||
|
func (spcb *SharePurchaseCreateBulk) Save(ctx context.Context) ([]*SharePurchase, error) {
|
||||||
|
if spcb.err != nil {
|
||||||
|
return nil, spcb.err
|
||||||
|
}
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(spcb.builders))
|
||||||
|
nodes := make([]*SharePurchase, len(spcb.builders))
|
||||||
|
mutators := make([]Mutator, len(spcb.builders))
|
||||||
|
for i := range spcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := spcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*SharePurchaseMutation)
|
||||||
|
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, spcb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
spec.OnConflict = spcb.conflict
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, spcb.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, spcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (spcb *SharePurchaseCreateBulk) SaveX(ctx context.Context) []*SharePurchase {
|
||||||
|
v, err := spcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (spcb *SharePurchaseCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := spcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spcb *SharePurchaseCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := spcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||||
|
// of the `INSERT` statement. For example:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.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.SharePurchaseUpsert) {
|
||||||
|
// SetCreatedAt(v+v).
|
||||||
|
// }).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (spcb *SharePurchaseCreateBulk) OnConflict(opts ...sql.ConflictOption) *SharePurchaseUpsertBulk {
|
||||||
|
spcb.conflict = opts
|
||||||
|
return &SharePurchaseUpsertBulk{
|
||||||
|
create: spcb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||||
|
// as conflict target. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(sql.ConflictColumns(columns...)).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (spcb *SharePurchaseCreateBulk) OnConflictColumns(columns ...string) *SharePurchaseUpsertBulk {
|
||||||
|
spcb.conflict = append(spcb.conflict, sql.ConflictColumns(columns...))
|
||||||
|
return &SharePurchaseUpsertBulk{
|
||||||
|
create: spcb,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseUpsertBulk is the builder for "upsert"-ing
|
||||||
|
// a bulk of SharePurchase nodes.
|
||||||
|
type SharePurchaseUpsertBulk struct {
|
||||||
|
create *SharePurchaseCreateBulk
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNewValues updates the mutable fields using the new values that
|
||||||
|
// were set on create. Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(
|
||||||
|
// sql.ResolveWithNewValues(),
|
||||||
|
// ).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateNewValues() *SharePurchaseUpsertBulk {
|
||||||
|
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(sharepurchase.FieldCreatedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore sets each column to itself in case of conflict.
|
||||||
|
// Using this option is equivalent to using:
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Create().
|
||||||
|
// OnConflict(sql.ResolveWithIgnore()).
|
||||||
|
// Exec(ctx)
|
||||||
|
func (u *SharePurchaseUpsertBulk) Ignore() *SharePurchaseUpsertBulk {
|
||||||
|
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 *SharePurchaseUpsertBulk) DoNothing() *SharePurchaseUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update allows overriding fields `UPDATE` values. See the SharePurchaseCreateBulk.OnConflict
|
||||||
|
// documentation for more info.
|
||||||
|
func (u *SharePurchaseUpsertBulk) Update(set func(*SharePurchaseUpsert)) *SharePurchaseUpsertBulk {
|
||||||
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||||
|
set(&SharePurchaseUpsert{UpdateSet: update})
|
||||||
|
}))
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetUpdatedAt(v time.Time) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetUpdatedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateUpdatedAt() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateUpdatedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetDeletedAt(v time.Time) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetDeletedAt(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateDeletedAt() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateDeletedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) ClearDeletedAt() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.ClearDeletedAt()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetShareID(v int) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetShareID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateShareID sets the "share_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateShareID() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateShareID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetBuyerID(v int) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetBuyerID(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateBuyerID sets the "buyer_id" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateBuyerID() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateBuyerID()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetPoints(v int) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetPoints(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPoints adds v to the "points" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) AddPoints(v int) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.AddPoints(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePoints sets the "points" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdatePoints() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdatePoints()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (u *SharePurchaseUpsertBulk) SetTicket(v string) *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.SetTicket(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTicket sets the "ticket" field to the value that was provided on create.
|
||||||
|
func (u *SharePurchaseUpsertBulk) UpdateTicket() *SharePurchaseUpsertBulk {
|
||||||
|
return u.Update(func(s *SharePurchaseUpsert) {
|
||||||
|
s.UpdateTicket()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (u *SharePurchaseUpsertBulk) 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 SharePurchaseCreateBulk instead", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(u.create.conflict) == 0 {
|
||||||
|
return errors.New("ent: missing options for SharePurchaseCreateBulk.OnConflict")
|
||||||
|
}
|
||||||
|
return u.create.Exec(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (u *SharePurchaseUpsertBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := u.create.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/sharepurchase"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchaseDelete is the builder for deleting a SharePurchase entity.
|
||||||
|
type SharePurchaseDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *SharePurchaseMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the SharePurchaseDelete builder.
|
||||||
|
func (spd *SharePurchaseDelete) Where(ps ...predicate.SharePurchase) *SharePurchaseDelete {
|
||||||
|
spd.mutation.Where(ps...)
|
||||||
|
return spd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (spd *SharePurchaseDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
return withHooks(ctx, spd.sqlExec, spd.mutation, spd.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spd *SharePurchaseDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := spd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spd *SharePurchaseDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := sqlgraph.NewDeleteSpec(sharepurchase.Table, sqlgraph.NewFieldSpec(sharepurchase.FieldID, field.TypeInt))
|
||||||
|
if ps := spd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, spd.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
spd.mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseDeleteOne is the builder for deleting a single SharePurchase entity.
|
||||||
|
type SharePurchaseDeleteOne struct {
|
||||||
|
spd *SharePurchaseDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the SharePurchaseDelete builder.
|
||||||
|
func (spdo *SharePurchaseDeleteOne) Where(ps ...predicate.SharePurchase) *SharePurchaseDeleteOne {
|
||||||
|
spdo.spd.mutation.Where(ps...)
|
||||||
|
return spdo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (spdo *SharePurchaseDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := spdo.spd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{sharepurchase.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spdo *SharePurchaseDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
if err := spdo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,680 @@
|
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/share"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/sharepurchase"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchaseQuery is the builder for querying SharePurchase entities.
|
||||||
|
type SharePurchaseQuery struct {
|
||||||
|
config
|
||||||
|
ctx *QueryContext
|
||||||
|
order []sharepurchase.OrderOption
|
||||||
|
inters []Interceptor
|
||||||
|
predicates []predicate.SharePurchase
|
||||||
|
withShare *ShareQuery
|
||||||
|
withBuyer *UserQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the SharePurchaseQuery builder.
|
||||||
|
func (spq *SharePurchaseQuery) Where(ps ...predicate.SharePurchase) *SharePurchaseQuery {
|
||||||
|
spq.predicates = append(spq.predicates, ps...)
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (spq *SharePurchaseQuery) Limit(limit int) *SharePurchaseQuery {
|
||||||
|
spq.ctx.Limit = &limit
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (spq *SharePurchaseQuery) Offset(offset int) *SharePurchaseQuery {
|
||||||
|
spq.ctx.Offset = &offset
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (spq *SharePurchaseQuery) Unique(unique bool) *SharePurchaseQuery {
|
||||||
|
spq.ctx.Unique = &unique
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (spq *SharePurchaseQuery) Order(o ...sharepurchase.OrderOption) *SharePurchaseQuery {
|
||||||
|
spq.order = append(spq.order, o...)
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryShare chains the current query on the "share" edge.
|
||||||
|
func (spq *SharePurchaseQuery) QueryShare() *ShareQuery {
|
||||||
|
query := (&ShareClient{config: spq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := spq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := spq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(sharepurchase.Table, sharepurchase.FieldID, selector),
|
||||||
|
sqlgraph.To(share.Table, share.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, sharepurchase.ShareTable, sharepurchase.ShareColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(spq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryBuyer chains the current query on the "buyer" edge.
|
||||||
|
func (spq *SharePurchaseQuery) QueryBuyer() *UserQuery {
|
||||||
|
query := (&UserClient{config: spq.config}).Query()
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := spq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := spq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(sharepurchase.Table, sharepurchase.FieldID, selector),
|
||||||
|
sqlgraph.To(user.Table, user.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, sharepurchase.BuyerTable, sharepurchase.BuyerColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(spq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first SharePurchase entity from the query.
|
||||||
|
// Returns a *NotFoundError when no SharePurchase was found.
|
||||||
|
func (spq *SharePurchaseQuery) First(ctx context.Context) (*SharePurchase, error) {
|
||||||
|
nodes, err := spq.Limit(1).All(setContextOp(ctx, spq.ctx, "First"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{sharepurchase.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) FirstX(ctx context.Context) *SharePurchase {
|
||||||
|
node, err := spq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first SharePurchase ID from the query.
|
||||||
|
// Returns a *NotFoundError when no SharePurchase ID was found.
|
||||||
|
func (spq *SharePurchaseQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = spq.Limit(1).IDs(setContextOp(ctx, spq.ctx, "FirstID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{sharepurchase.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) FirstIDX(ctx context.Context) int {
|
||||||
|
id, err := spq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single SharePurchase entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one SharePurchase entity is found.
|
||||||
|
// Returns a *NotFoundError when no SharePurchase entities are found.
|
||||||
|
func (spq *SharePurchaseQuery) Only(ctx context.Context) (*SharePurchase, error) {
|
||||||
|
nodes, err := spq.Limit(2).All(setContextOp(ctx, spq.ctx, "Only"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{sharepurchase.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{sharepurchase.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) OnlyX(ctx context.Context) *SharePurchase {
|
||||||
|
node, err := spq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only SharePurchase ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one SharePurchase ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (spq *SharePurchaseQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||||
|
var ids []int
|
||||||
|
if ids, err = spq.Limit(2).IDs(setContextOp(ctx, spq.ctx, "OnlyID")); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{sharepurchase.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{sharepurchase.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) OnlyIDX(ctx context.Context) int {
|
||||||
|
id, err := spq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of SharePurchases.
|
||||||
|
func (spq *SharePurchaseQuery) All(ctx context.Context) ([]*SharePurchase, error) {
|
||||||
|
ctx = setContextOp(ctx, spq.ctx, "All")
|
||||||
|
if err := spq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
qr := querierAll[[]*SharePurchase, *SharePurchaseQuery]()
|
||||||
|
return withInterceptors[[]*SharePurchase](ctx, spq, qr, spq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) AllX(ctx context.Context) []*SharePurchase {
|
||||||
|
nodes, err := spq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of SharePurchase IDs.
|
||||||
|
func (spq *SharePurchaseQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||||
|
if spq.ctx.Unique == nil && spq.path != nil {
|
||||||
|
spq.Unique(true)
|
||||||
|
}
|
||||||
|
ctx = setContextOp(ctx, spq.ctx, "IDs")
|
||||||
|
if err = spq.Select(sharepurchase.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) IDsX(ctx context.Context) []int {
|
||||||
|
ids, err := spq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (spq *SharePurchaseQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
ctx = setContextOp(ctx, spq.ctx, "Count")
|
||||||
|
if err := spq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withInterceptors[int](ctx, spq, querierCount[*SharePurchaseQuery](), spq.inters)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := spq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (spq *SharePurchaseQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
ctx = setContextOp(ctx, spq.ctx, "Exist")
|
||||||
|
switch _, err := spq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (spq *SharePurchaseQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := spq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the SharePurchaseQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (spq *SharePurchaseQuery) Clone() *SharePurchaseQuery {
|
||||||
|
if spq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &SharePurchaseQuery{
|
||||||
|
config: spq.config,
|
||||||
|
ctx: spq.ctx.Clone(),
|
||||||
|
order: append([]sharepurchase.OrderOption{}, spq.order...),
|
||||||
|
inters: append([]Interceptor{}, spq.inters...),
|
||||||
|
predicates: append([]predicate.SharePurchase{}, spq.predicates...),
|
||||||
|
withShare: spq.withShare.Clone(),
|
||||||
|
withBuyer: spq.withBuyer.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: spq.sql.Clone(),
|
||||||
|
path: spq.path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithShare tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "share" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (spq *SharePurchaseQuery) WithShare(opts ...func(*ShareQuery)) *SharePurchaseQuery {
|
||||||
|
query := (&ShareClient{config: spq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
spq.withShare = query
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBuyer tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "buyer" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (spq *SharePurchaseQuery) WithBuyer(opts ...func(*UserQuery)) *SharePurchaseQuery {
|
||||||
|
query := (&UserClient{config: spq.config}).Query()
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
spq.withBuyer = query
|
||||||
|
return spq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Query().
|
||||||
|
// GroupBy(sharepurchase.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (spq *SharePurchaseQuery) GroupBy(field string, fields ...string) *SharePurchaseGroupBy {
|
||||||
|
spq.ctx.Fields = append([]string{field}, fields...)
|
||||||
|
grbuild := &SharePurchaseGroupBy{build: spq}
|
||||||
|
grbuild.flds = &spq.ctx.Fields
|
||||||
|
grbuild.label = sharepurchase.Label
|
||||||
|
grbuild.scan = grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.SharePurchase.Query().
|
||||||
|
// Select(sharepurchase.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (spq *SharePurchaseQuery) Select(fields ...string) *SharePurchaseSelect {
|
||||||
|
spq.ctx.Fields = append(spq.ctx.Fields, fields...)
|
||||||
|
sbuild := &SharePurchaseSelect{SharePurchaseQuery: spq}
|
||||||
|
sbuild.label = sharepurchase.Label
|
||||||
|
sbuild.flds, sbuild.scan = &spq.ctx.Fields, sbuild.Scan
|
||||||
|
return sbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a SharePurchaseSelect configured with the given aggregations.
|
||||||
|
func (spq *SharePurchaseQuery) Aggregate(fns ...AggregateFunc) *SharePurchaseSelect {
|
||||||
|
return spq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, inter := range spq.inters {
|
||||||
|
if inter == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
if trv, ok := inter.(Traverser); ok {
|
||||||
|
if err := trv.Traverse(ctx, spq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range spq.ctx.Fields {
|
||||||
|
if !sharepurchase.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if spq.path != nil {
|
||||||
|
prev, err := spq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
spq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SharePurchase, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*SharePurchase{}
|
||||||
|
_spec = spq.querySpec()
|
||||||
|
loadedTypes = [2]bool{
|
||||||
|
spq.withShare != nil,
|
||||||
|
spq.withBuyer != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*SharePurchase).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &SharePurchase{config: spq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, spq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := spq.withShare; query != nil {
|
||||||
|
if err := spq.loadShare(ctx, query, nodes, nil,
|
||||||
|
func(n *SharePurchase, e *Share) { n.Edges.Share = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if query := spq.withBuyer; query != nil {
|
||||||
|
if err := spq.loadBuyer(ctx, query, nodes, nil,
|
||||||
|
func(n *SharePurchase, e *User) { n.Edges.Buyer = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) loadShare(ctx context.Context, query *ShareQuery, nodes []*SharePurchase, init func(*SharePurchase), assign func(*SharePurchase, *Share)) error {
|
||||||
|
ids := make([]int, 0, len(nodes))
|
||||||
|
nodeids := make(map[int][]*SharePurchase)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].ShareID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(share.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "share_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (spq *SharePurchaseQuery) loadBuyer(ctx context.Context, query *UserQuery, nodes []*SharePurchase, init func(*SharePurchase), assign func(*SharePurchase, *User)) error {
|
||||||
|
ids := make([]int, 0, len(nodes))
|
||||||
|
nodeids := make(map[int][]*SharePurchase)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].BuyerID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
query.Where(user.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "buyer_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := spq.querySpec()
|
||||||
|
_spec.Node.Columns = spq.ctx.Fields
|
||||||
|
if len(spq.ctx.Fields) > 0 {
|
||||||
|
_spec.Unique = spq.ctx.Unique != nil && *spq.ctx.Unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, spq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := sqlgraph.NewQuerySpec(sharepurchase.Table, sharepurchase.Columns, sqlgraph.NewFieldSpec(sharepurchase.FieldID, field.TypeInt))
|
||||||
|
_spec.From = spq.sql
|
||||||
|
if unique := spq.ctx.Unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
} else if spq.path != nil {
|
||||||
|
_spec.Unique = true
|
||||||
|
}
|
||||||
|
if fields := spq.ctx.Fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, sharepurchase.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != sharepurchase.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if spq.withShare != nil {
|
||||||
|
_spec.Node.AddColumnOnce(sharepurchase.FieldShareID)
|
||||||
|
}
|
||||||
|
if spq.withBuyer != nil {
|
||||||
|
_spec.Node.AddColumnOnce(sharepurchase.FieldBuyerID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := spq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := spq.ctx.Limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := spq.ctx.Offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := spq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spq *SharePurchaseQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(spq.driver.Dialect())
|
||||||
|
t1 := builder.Table(sharepurchase.Table)
|
||||||
|
columns := spq.ctx.Fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = sharepurchase.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if spq.sql != nil {
|
||||||
|
selector = spq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if spq.ctx.Unique != nil && *spq.ctx.Unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range spq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range spq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := spq.ctx.Offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := spq.ctx.Limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseGroupBy is the group-by builder for SharePurchase entities.
|
||||||
|
type SharePurchaseGroupBy struct {
|
||||||
|
selector
|
||||||
|
build *SharePurchaseQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (spgb *SharePurchaseGroupBy) Aggregate(fns ...AggregateFunc) *SharePurchaseGroupBy {
|
||||||
|
spgb.fns = append(spgb.fns, fns...)
|
||||||
|
return spgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (spgb *SharePurchaseGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, spgb.build.ctx, "GroupBy")
|
||||||
|
if err := spgb.build.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*SharePurchaseQuery, *SharePurchaseGroupBy](ctx, spgb.build, spgb, spgb.build.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spgb *SharePurchaseGroupBy) sqlScan(ctx context.Context, root *SharePurchaseQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx).Select()
|
||||||
|
aggregation := make([]string, 0, len(spgb.fns))
|
||||||
|
for _, fn := range spgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(*spgb.flds)+len(spgb.fns))
|
||||||
|
for _, f := range *spgb.flds {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
selector.GroupBy(selector.Columns(*spgb.flds...)...)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := spgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseSelect is the builder for selecting fields of SharePurchase entities.
|
||||||
|
type SharePurchaseSelect struct {
|
||||||
|
*SharePurchaseQuery
|
||||||
|
selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (sps *SharePurchaseSelect) Aggregate(fns ...AggregateFunc) *SharePurchaseSelect {
|
||||||
|
sps.fns = append(sps.fns, fns...)
|
||||||
|
return sps
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (sps *SharePurchaseSelect) Scan(ctx context.Context, v any) error {
|
||||||
|
ctx = setContextOp(ctx, sps.ctx, "Select")
|
||||||
|
if err := sps.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return scanWithInterceptors[*SharePurchaseQuery, *SharePurchaseSelect](ctx, sps.SharePurchaseQuery, sps, sps.inters, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sps *SharePurchaseSelect) sqlScan(ctx context.Context, root *SharePurchaseQuery, v any) error {
|
||||||
|
selector := root.sqlQuery(ctx)
|
||||||
|
aggregation := make([]string, 0, len(sps.fns))
|
||||||
|
for _, fn := range sps.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
switch n := len(*sps.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
selector.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
selector.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := sps.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
@ -0,0 +1,620 @@
|
|||||||
|
// 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/predicate"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/share"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/sharepurchase"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SharePurchaseUpdate is the builder for updating SharePurchase entities.
|
||||||
|
type SharePurchaseUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *SharePurchaseMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the SharePurchaseUpdate builder.
|
||||||
|
func (spu *SharePurchaseUpdate) Where(ps ...predicate.SharePurchase) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.Where(ps...)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetUpdatedAt(t time.Time) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.SetUpdatedAt(t)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetDeletedAt(t time.Time) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.SetDeletedAt(t)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||||
|
func (spu *SharePurchaseUpdate) SetNillableDeletedAt(t *time.Time) *SharePurchaseUpdate {
|
||||||
|
if t != nil {
|
||||||
|
spu.SetDeletedAt(*t)
|
||||||
|
}
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||||
|
func (spu *SharePurchaseUpdate) ClearDeletedAt() *SharePurchaseUpdate {
|
||||||
|
spu.mutation.ClearDeletedAt()
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetShareID(i int) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.SetShareID(i)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableShareID sets the "share_id" field if the given value is not nil.
|
||||||
|
func (spu *SharePurchaseUpdate) SetNillableShareID(i *int) *SharePurchaseUpdate {
|
||||||
|
if i != nil {
|
||||||
|
spu.SetShareID(*i)
|
||||||
|
}
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetBuyerID(i int) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.SetBuyerID(i)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableBuyerID sets the "buyer_id" field if the given value is not nil.
|
||||||
|
func (spu *SharePurchaseUpdate) SetNillableBuyerID(i *int) *SharePurchaseUpdate {
|
||||||
|
if i != nil {
|
||||||
|
spu.SetBuyerID(*i)
|
||||||
|
}
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetPoints(i int) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.ResetPoints()
|
||||||
|
spu.mutation.SetPoints(i)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePoints sets the "points" field if the given value is not nil.
|
||||||
|
func (spu *SharePurchaseUpdate) SetNillablePoints(i *int) *SharePurchaseUpdate {
|
||||||
|
if i != nil {
|
||||||
|
spu.SetPoints(*i)
|
||||||
|
}
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPoints adds i to the "points" field.
|
||||||
|
func (spu *SharePurchaseUpdate) AddPoints(i int) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.AddPoints(i)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (spu *SharePurchaseUpdate) SetTicket(s string) *SharePurchaseUpdate {
|
||||||
|
spu.mutation.SetTicket(s)
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTicket sets the "ticket" field if the given value is not nil.
|
||||||
|
func (spu *SharePurchaseUpdate) SetNillableTicket(s *string) *SharePurchaseUpdate {
|
||||||
|
if s != nil {
|
||||||
|
spu.SetTicket(*s)
|
||||||
|
}
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShare sets the "share" edge to the Share entity.
|
||||||
|
func (spu *SharePurchaseUpdate) SetShare(s *Share) *SharePurchaseUpdate {
|
||||||
|
return spu.SetShareID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyer sets the "buyer" edge to the User entity.
|
||||||
|
func (spu *SharePurchaseUpdate) SetBuyer(u *User) *SharePurchaseUpdate {
|
||||||
|
return spu.SetBuyerID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the SharePurchaseMutation object of the builder.
|
||||||
|
func (spu *SharePurchaseUpdate) Mutation() *SharePurchaseMutation {
|
||||||
|
return spu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearShare clears the "share" edge to the Share entity.
|
||||||
|
func (spu *SharePurchaseUpdate) ClearShare() *SharePurchaseUpdate {
|
||||||
|
spu.mutation.ClearShare()
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBuyer clears the "buyer" edge to the User entity.
|
||||||
|
func (spu *SharePurchaseUpdate) ClearBuyer() *SharePurchaseUpdate {
|
||||||
|
spu.mutation.ClearBuyer()
|
||||||
|
return spu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (spu *SharePurchaseUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
if err := spu.defaults(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return withHooks(ctx, spu.sqlSave, spu.mutation, spu.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (spu *SharePurchaseUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := spu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (spu *SharePurchaseUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := spu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spu *SharePurchaseUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := spu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (spu *SharePurchaseUpdate) defaults() error {
|
||||||
|
if _, ok := spu.mutation.UpdatedAt(); !ok {
|
||||||
|
if sharepurchase.UpdateDefaultUpdatedAt == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized sharepurchase.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
v := sharepurchase.UpdateDefaultUpdatedAt()
|
||||||
|
spu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (spu *SharePurchaseUpdate) check() error {
|
||||||
|
if v, ok := spu.mutation.Ticket(); ok {
|
||||||
|
if err := sharepurchase.TicketValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "ticket", err: fmt.Errorf(`ent: validator failed for field "SharePurchase.ticket": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := spu.mutation.ShareID(); spu.mutation.ShareCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "SharePurchase.share"`)
|
||||||
|
}
|
||||||
|
if _, ok := spu.mutation.BuyerID(); spu.mutation.BuyerCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "SharePurchase.buyer"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spu *SharePurchaseUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
if err := spu.check(); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(sharepurchase.Table, sharepurchase.Columns, sqlgraph.NewFieldSpec(sharepurchase.FieldID, field.TypeInt))
|
||||||
|
if ps := spu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := spu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := spu.mutation.DeletedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldDeletedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if spu.mutation.DeletedAtCleared() {
|
||||||
|
_spec.ClearField(sharepurchase.FieldDeletedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := spu.mutation.Points(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldPoints, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := spu.mutation.AddedPoints(); ok {
|
||||||
|
_spec.AddField(sharepurchase.FieldPoints, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := spu.mutation.Ticket(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldTicket, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if spu.mutation.ShareCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.ShareTable,
|
||||||
|
Columns: []string{sharepurchase.ShareColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := spu.mutation.ShareIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.ShareTable,
|
||||||
|
Columns: []string{sharepurchase.ShareColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if spu.mutation.BuyerCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.BuyerTable,
|
||||||
|
Columns: []string{sharepurchase.BuyerColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := spu.mutation.BuyerIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.BuyerTable,
|
||||||
|
Columns: []string{sharepurchase.BuyerColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, spu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{sharepurchase.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
spu.mutation.done = true
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SharePurchaseUpdateOne is the builder for updating a single SharePurchase entity.
|
||||||
|
type SharePurchaseUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *SharePurchaseMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetUpdatedAt(t time.Time) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.SetUpdatedAt(t)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeletedAt sets the "deleted_at" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetDeletedAt(t time.Time) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.SetDeletedAt(t)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetNillableDeletedAt(t *time.Time) *SharePurchaseUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
spuo.SetDeletedAt(*t)
|
||||||
|
}
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) ClearDeletedAt() *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.ClearDeletedAt()
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShareID sets the "share_id" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetShareID(i int) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.SetShareID(i)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableShareID sets the "share_id" field if the given value is not nil.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetNillableShareID(i *int) *SharePurchaseUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
spuo.SetShareID(*i)
|
||||||
|
}
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyerID sets the "buyer_id" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetBuyerID(i int) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.SetBuyerID(i)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableBuyerID sets the "buyer_id" field if the given value is not nil.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetNillableBuyerID(i *int) *SharePurchaseUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
spuo.SetBuyerID(*i)
|
||||||
|
}
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPoints sets the "points" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetPoints(i int) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.ResetPoints()
|
||||||
|
spuo.mutation.SetPoints(i)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillablePoints sets the "points" field if the given value is not nil.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetNillablePoints(i *int) *SharePurchaseUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
spuo.SetPoints(*i)
|
||||||
|
}
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddPoints adds i to the "points" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) AddPoints(i int) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.AddPoints(i)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTicket sets the "ticket" field.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetTicket(s string) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.SetTicket(s)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTicket sets the "ticket" field if the given value is not nil.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetNillableTicket(s *string) *SharePurchaseUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
spuo.SetTicket(*s)
|
||||||
|
}
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetShare sets the "share" edge to the Share entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetShare(s *Share) *SharePurchaseUpdateOne {
|
||||||
|
return spuo.SetShareID(s.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBuyer sets the "buyer" edge to the User entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SetBuyer(u *User) *SharePurchaseUpdateOne {
|
||||||
|
return spuo.SetBuyerID(u.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the SharePurchaseMutation object of the builder.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) Mutation() *SharePurchaseMutation {
|
||||||
|
return spuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearShare clears the "share" edge to the Share entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) ClearShare() *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.ClearShare()
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearBuyer clears the "buyer" edge to the User entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) ClearBuyer() *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.ClearBuyer()
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the SharePurchaseUpdate builder.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) Where(ps ...predicate.SharePurchase) *SharePurchaseUpdateOne {
|
||||||
|
spuo.mutation.Where(ps...)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) Select(field string, fields ...string) *SharePurchaseUpdateOne {
|
||||||
|
spuo.fields = append([]string{field}, fields...)
|
||||||
|
return spuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated SharePurchase entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) Save(ctx context.Context) (*SharePurchase, error) {
|
||||||
|
if err := spuo.defaults(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return withHooks(ctx, spuo.sqlSave, spuo.mutation, spuo.hooks)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) SaveX(ctx context.Context) *SharePurchase {
|
||||||
|
node, err := spuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := spuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := spuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) defaults() error {
|
||||||
|
if _, ok := spuo.mutation.UpdatedAt(); !ok {
|
||||||
|
if sharepurchase.UpdateDefaultUpdatedAt == nil {
|
||||||
|
return fmt.Errorf("ent: uninitialized sharepurchase.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
v := sharepurchase.UpdateDefaultUpdatedAt()
|
||||||
|
spuo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (spuo *SharePurchaseUpdateOne) check() error {
|
||||||
|
if v, ok := spuo.mutation.Ticket(); ok {
|
||||||
|
if err := sharepurchase.TicketValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "ticket", err: fmt.Errorf(`ent: validator failed for field "SharePurchase.ticket": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := spuo.mutation.ShareID(); spuo.mutation.ShareCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "SharePurchase.share"`)
|
||||||
|
}
|
||||||
|
if _, ok := spuo.mutation.BuyerID(); spuo.mutation.BuyerCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "SharePurchase.buyer"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spuo *SharePurchaseUpdateOne) sqlSave(ctx context.Context) (_node *SharePurchase, err error) {
|
||||||
|
if err := spuo.check(); err != nil {
|
||||||
|
return _node, err
|
||||||
|
}
|
||||||
|
_spec := sqlgraph.NewUpdateSpec(sharepurchase.Table, sharepurchase.Columns, sqlgraph.NewFieldSpec(sharepurchase.FieldID, field.TypeInt))
|
||||||
|
id, ok := spuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SharePurchase.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := spuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, sharepurchase.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !sharepurchase.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != sharepurchase.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := spuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := spuo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := spuo.mutation.DeletedAt(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldDeletedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if spuo.mutation.DeletedAtCleared() {
|
||||||
|
_spec.ClearField(sharepurchase.FieldDeletedAt, field.TypeTime)
|
||||||
|
}
|
||||||
|
if value, ok := spuo.mutation.Points(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldPoints, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := spuo.mutation.AddedPoints(); ok {
|
||||||
|
_spec.AddField(sharepurchase.FieldPoints, field.TypeInt, value)
|
||||||
|
}
|
||||||
|
if value, ok := spuo.mutation.Ticket(); ok {
|
||||||
|
_spec.SetField(sharepurchase.FieldTicket, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if spuo.mutation.ShareCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.ShareTable,
|
||||||
|
Columns: []string{sharepurchase.ShareColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := spuo.mutation.ShareIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.ShareTable,
|
||||||
|
Columns: []string{sharepurchase.ShareColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if spuo.mutation.BuyerCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.BuyerTable,
|
||||||
|
Columns: []string{sharepurchase.BuyerColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := spuo.mutation.BuyerIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: sharepurchase.BuyerTable,
|
||||||
|
Columns: []string{sharepurchase.BuyerColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &SharePurchase{config: spuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, spuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{sharepurchase.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
spuo.mutation.done = true
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
import { Alert, Box, Button, Typography } from "@mui/material";
|
||||||
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Link as RouterLink } from "react-router-dom";
|
||||||
|
import { getCredit, purchaseShare } from "../../api/api.ts";
|
||||||
|
import { CreditInfo } from "../../api/user.ts";
|
||||||
|
import { Share } from "../../api/explorer.ts";
|
||||||
|
import { useAppDispatch } from "../../redux/hooks.ts";
|
||||||
|
import SessionManager from "../../session/index.ts";
|
||||||
|
import CoinStack from "../Icons/CoinStack.tsx";
|
||||||
|
|
||||||
|
interface PaidShareGateProps {
|
||||||
|
shareInfo: Share;
|
||||||
|
// Called after a successful purchase; the caller typically reloads state.
|
||||||
|
onPurchased?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// PaidShareGate renders the purchase CTA for a priced share the visitor has
|
||||||
|
// not paid for. Anonymous visitors get a sign-in prompt; buyers resume via
|
||||||
|
// the ticket stored by purchaseShare.
|
||||||
|
const PaidShareGate = ({ shareInfo, onPurchased }: PaidShareGateProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [credit, setCredit] = useState<CreditInfo | null>(null);
|
||||||
|
|
||||||
|
const user = SessionManager.currentLoginOrNull();
|
||||||
|
const price = shareInfo.price ?? 0;
|
||||||
|
const paid = shareInfo.paid ?? false;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user && price > 0 && !paid) {
|
||||||
|
dispatch(getCredit())
|
||||||
|
.then(setCredit)
|
||||||
|
.catch(() => setCredit(null));
|
||||||
|
}
|
||||||
|
}, [user, price, paid, dispatch]);
|
||||||
|
|
||||||
|
const purchase = useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
await dispatch(purchaseShare(shareInfo.id));
|
||||||
|
onPurchased?.();
|
||||||
|
} catch (_e) {
|
||||||
|
// snackbar already reported by the request layer
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [dispatch, shareInfo.id, onPurchased]);
|
||||||
|
|
||||||
|
if (price <= 0 || paid || (user && shareInfo.owner.id == user.user.id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
severity="info"
|
||||||
|
icon={<CoinStack />}
|
||||||
|
sx={{ alignItems: "center" }}
|
||||||
|
action={
|
||||||
|
user ? (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
size="small"
|
||||||
|
disabled={loading || (credit != null && credit.credits < price)}
|
||||||
|
onClick={purchase}
|
||||||
|
>
|
||||||
|
{t("application:share.purchaseForPoints", { price })}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<Button variant="contained" size="small" component={RouterLink} to="/session">
|
||||||
|
{t("application:share.signInToPurchase")}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Typography variant="body2">{t("application:share.paidShareDes", { price })}</Typography>
|
||||||
|
{user && credit != null && (
|
||||||
|
<Typography variant="caption" color="text.secondary">
|
||||||
|
{t("application:share.yourBalance", { credits: credit.credits })}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PaidShareGate;
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
package share
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/activity"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SharePurchaseService purchases a paid share with the caller's credit
|
||||||
|
// balance and returns the resume ticket.
|
||||||
|
SharePurchaseService struct{}
|
||||||
|
SharePurchaseParamCtx struct{}
|
||||||
|
SharePurchaseResponse struct {
|
||||||
|
Ticket string `json:"ticket"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *SharePurchaseService) Purchase(c *gin.Context) (*SharePurchaseResponse, error) {
|
||||||
|
dep := dependency.FromContext(c)
|
||||||
|
u := inventory.UserFromContext(c)
|
||||||
|
|
||||||
|
ctx := context.WithValue(c, inventory.LoadShareUser{}, true)
|
||||||
|
ctx = context.WithValue(ctx, inventory.LoadShareFile{}, true)
|
||||||
|
share, err := dep.ShareClient().GetByID(ctx, hashid.FromContext(c))
|
||||||
|
if err != nil {
|
||||||
|
return nil, serializer.NewError(serializer.CodeNotFound, "Share not found", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := inventory.IsValidShare(share); err != nil {
|
||||||
|
return nil, serializer.NewError(serializer.CodeNotFound, "Share link expired", err)
|
||||||
|
}
|
||||||
|
if share.PricePoints <= 0 {
|
||||||
|
return nil, serializer.NewError(serializer.CodeParamErr, "Share is free", nil)
|
||||||
|
}
|
||||||
|
if share.Edges.User.ID == u.ID {
|
||||||
|
return nil, serializer.NewError(serializer.CodeParamErr, "Cannot purchase own share", nil)
|
||||||
|
}
|
||||||
|
if !u.Edges.Group.Permissions.Enabled(int(types.GroupPermissionShareDownload)) {
|
||||||
|
return nil, serializer.NewError(serializer.CodeNoPermissionErr, "You don't have permission to access share links", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
purchase, err := dep.VasClient().PurchaseShare(ctx, share, u.ID, dep.SettingProvider().ShareScoreRate(c))
|
||||||
|
if err != nil {
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, inventory.ErrInsufficientPoints):
|
||||||
|
return nil, serializer.NewError(serializer.CodeParamErr, "Insufficient credit balance", err)
|
||||||
|
default:
|
||||||
|
return nil, serializer.NewError(serializer.CodeDBError, "Failed to purchase share", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
activity.Record(c, dep.SettingProvider(), dep.ActivityClient(), types.EventPaymentFulfilled,
|
||||||
|
activity.Share(share.ID), activity.File(share.Edges.File.ID),
|
||||||
|
activity.Extra(map[string]any{
|
||||||
|
"points": purchase.Points,
|
||||||
|
"seller": share.Edges.User.ID,
|
||||||
|
}))
|
||||||
|
|
||||||
|
return &SharePurchaseResponse{Ticket: purchase.Ticket}, nil
|
||||||
|
}
|
||||||
Loading…
Reference in new issue