123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "reflect"
- "sync"
- "wechat-api/ent/agent"
- "wechat-api/ent/agentbase"
- "wechat-api/ent/aliyunavatar"
- "wechat-api/ent/allocagent"
- "wechat-api/ent/batchmsg"
- "wechat-api/ent/category"
- "wechat-api/ent/chatrecords"
- "wechat-api/ent/chatsession"
- "wechat-api/ent/contact"
- "wechat-api/ent/creditbalance"
- "wechat-api/ent/creditusage"
- "wechat-api/ent/employee"
- "wechat-api/ent/employeeconfig"
- "wechat-api/ent/label"
- "wechat-api/ent/labelrelationship"
- "wechat-api/ent/labeltagging"
- "wechat-api/ent/message"
- "wechat-api/ent/messagerecords"
- "wechat-api/ent/msg"
- "wechat-api/ent/payrecharge"
- "wechat-api/ent/server"
- "wechat-api/ent/sopnode"
- "wechat-api/ent/sopstage"
- "wechat-api/ent/soptask"
- "wechat-api/ent/token"
- "wechat-api/ent/tutorial"
- "wechat-api/ent/usagedetail"
- "wechat-api/ent/usagestatisticday"
- "wechat-api/ent/usagestatistichour"
- "wechat-api/ent/usagestatisticmonth"
- "wechat-api/ent/usagetotal"
- "wechat-api/ent/whatsapp"
- "wechat-api/ent/whatsappchannel"
- "wechat-api/ent/workexperience"
- "wechat-api/ent/wpchatroom"
- "wechat-api/ent/wpchatroommember"
- "wechat-api/ent/wx"
- "wechat-api/ent/wxcard"
- "wechat-api/ent/wxcarduser"
- "wechat-api/ent/wxcardvisit"
- "entgo.io/ent"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- )
- // ent aliases to avoid import conflicts in user's code.
- type (
- Op = ent.Op
- Hook = ent.Hook
- Value = ent.Value
- Query = ent.Query
- QueryContext = ent.QueryContext
- Querier = ent.Querier
- QuerierFunc = ent.QuerierFunc
- Interceptor = ent.Interceptor
- InterceptFunc = ent.InterceptFunc
- Traverser = ent.Traverser
- TraverseFunc = ent.TraverseFunc
- Policy = ent.Policy
- Mutator = ent.Mutator
- Mutation = ent.Mutation
- MutateFunc = ent.MutateFunc
- )
- type clientCtxKey struct{}
- // FromContext returns a Client stored inside a context, or nil if there isn't one.
- func FromContext(ctx context.Context) *Client {
- c, _ := ctx.Value(clientCtxKey{}).(*Client)
- return c
- }
- // NewContext returns a new context with the given Client attached.
- func NewContext(parent context.Context, c *Client) context.Context {
- return context.WithValue(parent, clientCtxKey{}, c)
- }
- type txCtxKey struct{}
- // TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
- func TxFromContext(ctx context.Context) *Tx {
- tx, _ := ctx.Value(txCtxKey{}).(*Tx)
- return tx
- }
- // NewTxContext returns a new context with the given Tx attached.
- func NewTxContext(parent context.Context, tx *Tx) context.Context {
- return context.WithValue(parent, txCtxKey{}, tx)
- }
- // OrderFunc applies an ordering on the sql selector.
- // Deprecated: Use Asc/Desc functions or the package builders instead.
- type OrderFunc func(*sql.Selector)
- var (
- initCheck sync.Once
- columnCheck sql.ColumnCheck
- )
- // columnChecker checks if the column exists in the given table.
- func checkColumn(table, column string) error {
- initCheck.Do(func() {
- columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
- agent.Table: agent.ValidColumn,
- agentbase.Table: agentbase.ValidColumn,
- aliyunavatar.Table: aliyunavatar.ValidColumn,
- allocagent.Table: allocagent.ValidColumn,
- batchmsg.Table: batchmsg.ValidColumn,
- category.Table: category.ValidColumn,
- chatrecords.Table: chatrecords.ValidColumn,
- chatsession.Table: chatsession.ValidColumn,
- contact.Table: contact.ValidColumn,
- creditbalance.Table: creditbalance.ValidColumn,
- creditusage.Table: creditusage.ValidColumn,
- employee.Table: employee.ValidColumn,
- employeeconfig.Table: employeeconfig.ValidColumn,
- label.Table: label.ValidColumn,
- labelrelationship.Table: labelrelationship.ValidColumn,
- labeltagging.Table: labeltagging.ValidColumn,
- message.Table: message.ValidColumn,
- messagerecords.Table: messagerecords.ValidColumn,
- msg.Table: msg.ValidColumn,
- payrecharge.Table: payrecharge.ValidColumn,
- server.Table: server.ValidColumn,
- sopnode.Table: sopnode.ValidColumn,
- sopstage.Table: sopstage.ValidColumn,
- soptask.Table: soptask.ValidColumn,
- token.Table: token.ValidColumn,
- tutorial.Table: tutorial.ValidColumn,
- usagedetail.Table: usagedetail.ValidColumn,
- usagestatisticday.Table: usagestatisticday.ValidColumn,
- usagestatistichour.Table: usagestatistichour.ValidColumn,
- usagestatisticmonth.Table: usagestatisticmonth.ValidColumn,
- usagetotal.Table: usagetotal.ValidColumn,
- whatsapp.Table: whatsapp.ValidColumn,
- whatsappchannel.Table: whatsappchannel.ValidColumn,
- workexperience.Table: workexperience.ValidColumn,
- wpchatroom.Table: wpchatroom.ValidColumn,
- wpchatroommember.Table: wpchatroommember.ValidColumn,
- wx.Table: wx.ValidColumn,
- wxcard.Table: wxcard.ValidColumn,
- wxcarduser.Table: wxcarduser.ValidColumn,
- wxcardvisit.Table: wxcardvisit.ValidColumn,
- })
- })
- return columnCheck(table, column)
- }
- // Asc applies the given fields in ASC order.
- func Asc(fields ...string) func(*sql.Selector) {
- return func(s *sql.Selector) {
- for _, f := range fields {
- if err := checkColumn(s.TableName(), f); err != nil {
- s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
- }
- s.OrderBy(sql.Asc(s.C(f)))
- }
- }
- }
- // Desc applies the given fields in DESC order.
- func Desc(fields ...string) func(*sql.Selector) {
- return func(s *sql.Selector) {
- for _, f := range fields {
- if err := checkColumn(s.TableName(), f); err != nil {
- s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
- }
- s.OrderBy(sql.Desc(s.C(f)))
- }
- }
- }
- // AggregateFunc applies an aggregation step on the group-by traversal/selector.
- type AggregateFunc func(*sql.Selector) string
- // As is a pseudo aggregation function for renaming another other functions with custom names. For example:
- //
- // GroupBy(field1, field2).
- // Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
- // Scan(ctx, &v)
- func As(fn AggregateFunc, end string) AggregateFunc {
- return func(s *sql.Selector) string {
- return sql.As(fn(s), end)
- }
- }
- // Count applies the "count" aggregation function on each group.
- func Count() AggregateFunc {
- return func(s *sql.Selector) string {
- return sql.Count("*")
- }
- }
- // Max applies the "max" aggregation function on the given field of each group.
- func Max(field string) AggregateFunc {
- return func(s *sql.Selector) string {
- if err := checkColumn(s.TableName(), field); err != nil {
- s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
- return ""
- }
- return sql.Max(s.C(field))
- }
- }
- // Mean applies the "mean" aggregation function on the given field of each group.
- func Mean(field string) AggregateFunc {
- return func(s *sql.Selector) string {
- if err := checkColumn(s.TableName(), field); err != nil {
- s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
- return ""
- }
- return sql.Avg(s.C(field))
- }
- }
- // Min applies the "min" aggregation function on the given field of each group.
- func Min(field string) AggregateFunc {
- return func(s *sql.Selector) string {
- if err := checkColumn(s.TableName(), field); err != nil {
- s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
- return ""
- }
- return sql.Min(s.C(field))
- }
- }
- // Sum applies the "sum" aggregation function on the given field of each group.
- func Sum(field string) AggregateFunc {
- return func(s *sql.Selector) string {
- if err := checkColumn(s.TableName(), field); err != nil {
- s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
- return ""
- }
- return sql.Sum(s.C(field))
- }
- }
- // ValidationError returns when validating a field or edge fails.
- type ValidationError struct {
- Name string // Field or edge name.
- err error
- }
- // Error implements the error interface.
- func (e *ValidationError) Error() string {
- return e.err.Error()
- }
- // Unwrap implements the errors.Wrapper interface.
- func (e *ValidationError) Unwrap() error {
- return e.err
- }
- // IsValidationError returns a boolean indicating whether the error is a validation error.
- func IsValidationError(err error) bool {
- if err == nil {
- return false
- }
- var e *ValidationError
- return errors.As(err, &e)
- }
- // NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
- type NotFoundError struct {
- label string
- }
- // Error implements the error interface.
- func (e *NotFoundError) Error() string {
- return "ent: " + e.label + " not found"
- }
- // IsNotFound returns a boolean indicating whether the error is a not found error.
- func IsNotFound(err error) bool {
- if err == nil {
- return false
- }
- var e *NotFoundError
- return errors.As(err, &e)
- }
- // MaskNotFound masks not found error.
- func MaskNotFound(err error) error {
- if IsNotFound(err) {
- return nil
- }
- return err
- }
- // NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
- type NotSingularError struct {
- label string
- }
- // Error implements the error interface.
- func (e *NotSingularError) Error() string {
- return "ent: " + e.label + " not singular"
- }
- // IsNotSingular returns a boolean indicating whether the error is a not singular error.
- func IsNotSingular(err error) bool {
- if err == nil {
- return false
- }
- var e *NotSingularError
- return errors.As(err, &e)
- }
- // NotLoadedError returns when trying to get a node that was not loaded by the query.
- type NotLoadedError struct {
- edge string
- }
- // Error implements the error interface.
- func (e *NotLoadedError) Error() string {
- return "ent: " + e.edge + " edge was not loaded"
- }
- // IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
- func IsNotLoaded(err error) bool {
- if err == nil {
- return false
- }
- var e *NotLoadedError
- return errors.As(err, &e)
- }
- // ConstraintError returns when trying to create/update one or more entities and
- // one or more of their constraints failed. For example, violation of edge or
- // field uniqueness.
- type ConstraintError struct {
- msg string
- wrap error
- }
- // Error implements the error interface.
- func (e ConstraintError) Error() string {
- return "ent: constraint failed: " + e.msg
- }
- // Unwrap implements the errors.Wrapper interface.
- func (e *ConstraintError) Unwrap() error {
- return e.wrap
- }
- // IsConstraintError returns a boolean indicating whether the error is a constraint failure.
- func IsConstraintError(err error) bool {
- if err == nil {
- return false
- }
- var e *ConstraintError
- return errors.As(err, &e)
- }
- // selector embedded by the different Select/GroupBy builders.
- type selector struct {
- label string
- flds *[]string
- fns []AggregateFunc
- scan func(context.Context, any) error
- }
- // ScanX is like Scan, but panics if an error occurs.
- func (s *selector) ScanX(ctx context.Context, v any) {
- if err := s.scan(ctx, v); err != nil {
- panic(err)
- }
- }
- // Strings returns list of strings from a selector. It is only allowed when selecting one field.
- func (s *selector) Strings(ctx context.Context) ([]string, error) {
- if len(*s.flds) > 1 {
- return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field")
- }
- var v []string
- if err := s.scan(ctx, &v); err != nil {
- return nil, err
- }
- return v, nil
- }
- // StringsX is like Strings, but panics if an error occurs.
- func (s *selector) StringsX(ctx context.Context) []string {
- v, err := s.Strings(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // String returns a single string from a selector. It is only allowed when selecting one field.
- func (s *selector) String(ctx context.Context) (_ string, err error) {
- var v []string
- if v, err = s.Strings(ctx); err != nil {
- return
- }
- switch len(v) {
- case 1:
- return v[0], nil
- case 0:
- err = &NotFoundError{s.label}
- default:
- err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v))
- }
- return
- }
- // StringX is like String, but panics if an error occurs.
- func (s *selector) StringX(ctx context.Context) string {
- v, err := s.String(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Ints returns list of ints from a selector. It is only allowed when selecting one field.
- func (s *selector) Ints(ctx context.Context) ([]int, error) {
- if len(*s.flds) > 1 {
- return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field")
- }
- var v []int
- if err := s.scan(ctx, &v); err != nil {
- return nil, err
- }
- return v, nil
- }
- // IntsX is like Ints, but panics if an error occurs.
- func (s *selector) IntsX(ctx context.Context) []int {
- v, err := s.Ints(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Int returns a single int from a selector. It is only allowed when selecting one field.
- func (s *selector) Int(ctx context.Context) (_ int, err error) {
- var v []int
- if v, err = s.Ints(ctx); err != nil {
- return
- }
- switch len(v) {
- case 1:
- return v[0], nil
- case 0:
- err = &NotFoundError{s.label}
- default:
- err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v))
- }
- return
- }
- // IntX is like Int, but panics if an error occurs.
- func (s *selector) IntX(ctx context.Context) int {
- v, err := s.Int(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
- func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
- if len(*s.flds) > 1 {
- return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field")
- }
- var v []float64
- if err := s.scan(ctx, &v); err != nil {
- return nil, err
- }
- return v, nil
- }
- // Float64sX is like Float64s, but panics if an error occurs.
- func (s *selector) Float64sX(ctx context.Context) []float64 {
- v, err := s.Float64s(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
- func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
- var v []float64
- if v, err = s.Float64s(ctx); err != nil {
- return
- }
- switch len(v) {
- case 1:
- return v[0], nil
- case 0:
- err = &NotFoundError{s.label}
- default:
- err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v))
- }
- return
- }
- // Float64X is like Float64, but panics if an error occurs.
- func (s *selector) Float64X(ctx context.Context) float64 {
- v, err := s.Float64(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Bools returns list of bools from a selector. It is only allowed when selecting one field.
- func (s *selector) Bools(ctx context.Context) ([]bool, error) {
- if len(*s.flds) > 1 {
- return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field")
- }
- var v []bool
- if err := s.scan(ctx, &v); err != nil {
- return nil, err
- }
- return v, nil
- }
- // BoolsX is like Bools, but panics if an error occurs.
- func (s *selector) BoolsX(ctx context.Context) []bool {
- v, err := s.Bools(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Bool returns a single bool from a selector. It is only allowed when selecting one field.
- func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
- var v []bool
- if v, err = s.Bools(ctx); err != nil {
- return
- }
- switch len(v) {
- case 1:
- return v[0], nil
- case 0:
- err = &NotFoundError{s.label}
- default:
- err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v))
- }
- return
- }
- // BoolX is like Bool, but panics if an error occurs.
- func (s *selector) BoolX(ctx context.Context) bool {
- v, err := s.Bool(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // withHooks invokes the builder operation with the given hooks, if any.
- func withHooks[V Value, M any, PM interface {
- *M
- Mutation
- }](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
- if len(hooks) == 0 {
- return exec(ctx)
- }
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutationT, ok := any(m).(PM)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- // Set the mutation to the builder.
- *mutation = *mutationT
- return exec(ctx)
- })
- for i := len(hooks) - 1; i >= 0; i-- {
- if hooks[i] == nil {
- return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
- }
- mut = hooks[i](mut)
- }
- v, err := mut.Mutate(ctx, mutation)
- if err != nil {
- return value, err
- }
- nv, ok := v.(V)
- if !ok {
- return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
- }
- return nv, nil
- }
- // setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
- func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
- if ent.QueryFromContext(ctx) == nil {
- qc.Op = op
- ctx = ent.NewQueryContext(ctx, qc)
- }
- return ctx
- }
- func querierAll[V Value, Q interface {
- sqlAll(context.Context, ...queryHook) (V, error)
- }]() Querier {
- return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
- query, ok := q.(Q)
- if !ok {
- return nil, fmt.Errorf("unexpected query type %T", q)
- }
- return query.sqlAll(ctx)
- })
- }
- func querierCount[Q interface {
- sqlCount(context.Context) (int, error)
- }]() Querier {
- return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
- query, ok := q.(Q)
- if !ok {
- return nil, fmt.Errorf("unexpected query type %T", q)
- }
- return query.sqlCount(ctx)
- })
- }
- func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
- for i := len(inters) - 1; i >= 0; i-- {
- qr = inters[i].Intercept(qr)
- }
- rv, err := qr.Query(ctx, q)
- if err != nil {
- return v, err
- }
- vt, ok := rv.(V)
- if !ok {
- return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
- }
- return vt, nil
- }
- func scanWithInterceptors[Q1 ent.Query, Q2 interface {
- sqlScan(context.Context, Q1, any) error
- }](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
- rv := reflect.ValueOf(v)
- var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
- query, ok := q.(Q1)
- if !ok {
- return nil, fmt.Errorf("unexpected query type %T", q)
- }
- if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
- return nil, err
- }
- if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
- return rv.Elem().Interface(), nil
- }
- return v, nil
- })
- for i := len(inters) - 1; i >= 0; i-- {
- qr = inters[i].Intercept(qr)
- }
- vv, err := qr.Query(ctx, rootQuery)
- if err != nil {
- return err
- }
- switch rv2 := reflect.ValueOf(vv); {
- case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
- case rv.Type() == rv2.Type():
- rv.Elem().Set(rv2.Elem())
- case rv.Elem().Type() == rv2.Type():
- rv.Elem().Set(rv2)
- }
- return nil
- }
- // queryHook describes an internal hook for the different sqlAll methods.
- type queryHook func(context.Context, *sqlgraph.QuerySpec)
|