| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "fmt"
- "strings"
- "time"
- "entgo.io/ent"
- "entgo.io/ent/dialect/sql"
- "github.com/Wei-Shaw/sub2api/ent/proxy"
- )
- // Proxy is the model entity for the Proxy schema.
- type Proxy struct {
- config `json:"-"`
- // ID of the ent.
- ID int64 `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"`
- // Name holds the value of the "name" field.
- Name string `json:"name,omitempty"`
- // Protocol holds the value of the "protocol" field.
- Protocol string `json:"protocol,omitempty"`
- // Host holds the value of the "host" field.
- Host string `json:"host,omitempty"`
- // Port holds the value of the "port" field.
- Port int `json:"port,omitempty"`
- // Username holds the value of the "username" field.
- Username *string `json:"username,omitempty"`
- // Password holds the value of the "password" field.
- Password *string `json:"password,omitempty"`
- // Status holds the value of the "status" field.
- Status string `json:"status,omitempty"`
- // Proxy expiration time (NULL means never expires).
- ExpiresAt *time.Time `json:"expires_at,omitempty"`
- // Fallback target on expiry: none | proxy | direct.
- FallbackMode string `json:"fallback_mode,omitempty"`
- // Backup proxy id when fallback_mode=proxy (self-reference).
- BackupProxyID *int64 `json:"backup_proxy_id,omitempty"`
- // Days before expiry to flag as expiring-soon (per proxy).
- ExpiryWarnDays int `json:"expiry_warn_days,omitempty"`
- // Edges holds the relations/edges for other nodes in the graph.
- // The values are being populated by the ProxyQuery when eager-loading is set.
- Edges ProxyEdges `json:"edges"`
- selectValues sql.SelectValues
- }
- // ProxyEdges holds the relations/edges for other nodes in the graph.
- type ProxyEdges struct {
- // Accounts holds the value of the accounts edge.
- Accounts []*Account `json:"accounts,omitempty"`
- // PrimaryProxies holds the value of the primary_proxies edge.
- PrimaryProxies []*Proxy `json:"primary_proxies,omitempty"`
- // BackupProxy holds the value of the backup_proxy edge.
- BackupProxy *Proxy `json:"backup_proxy,omitempty"`
- // loadedTypes holds the information for reporting if a
- // type was loaded (or requested) in eager-loading or not.
- loadedTypes [3]bool
- }
- // AccountsOrErr returns the Accounts value or an error if the edge
- // was not loaded in eager-loading.
- func (e ProxyEdges) AccountsOrErr() ([]*Account, error) {
- if e.loadedTypes[0] {
- return e.Accounts, nil
- }
- return nil, &NotLoadedError{edge: "accounts"}
- }
- // PrimaryProxiesOrErr returns the PrimaryProxies value or an error if the edge
- // was not loaded in eager-loading.
- func (e ProxyEdges) PrimaryProxiesOrErr() ([]*Proxy, error) {
- if e.loadedTypes[1] {
- return e.PrimaryProxies, nil
- }
- return nil, &NotLoadedError{edge: "primary_proxies"}
- }
- // BackupProxyOrErr returns the BackupProxy value or an error if the edge
- // was not loaded in eager-loading, or loaded but was not found.
- func (e ProxyEdges) BackupProxyOrErr() (*Proxy, error) {
- if e.BackupProxy != nil {
- return e.BackupProxy, nil
- } else if e.loadedTypes[2] {
- return nil, &NotFoundError{label: proxy.Label}
- }
- return nil, &NotLoadedError{edge: "backup_proxy"}
- }
- // scanValues returns the types for scanning values from sql.Rows.
- func (*Proxy) scanValues(columns []string) ([]any, error) {
- values := make([]any, len(columns))
- for i := range columns {
- switch columns[i] {
- case proxy.FieldID, proxy.FieldPort, proxy.FieldBackupProxyID, proxy.FieldExpiryWarnDays:
- values[i] = new(sql.NullInt64)
- case proxy.FieldName, proxy.FieldProtocol, proxy.FieldHost, proxy.FieldUsername, proxy.FieldPassword, proxy.FieldStatus, proxy.FieldFallbackMode:
- values[i] = new(sql.NullString)
- case proxy.FieldCreatedAt, proxy.FieldUpdatedAt, proxy.FieldDeletedAt, proxy.FieldExpiresAt:
- 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 Proxy fields.
- func (_m *Proxy) 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 proxy.FieldID:
- value, ok := values[i].(*sql.NullInt64)
- if !ok {
- return fmt.Errorf("unexpected type %T for field id", value)
- }
- _m.ID = int64(value.Int64)
- case proxy.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 {
- _m.CreatedAt = value.Time
- }
- case proxy.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 {
- _m.UpdatedAt = value.Time
- }
- case proxy.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 {
- _m.DeletedAt = new(time.Time)
- *_m.DeletedAt = value.Time
- }
- case proxy.FieldName:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field name", values[i])
- } else if value.Valid {
- _m.Name = value.String
- }
- case proxy.FieldProtocol:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field protocol", values[i])
- } else if value.Valid {
- _m.Protocol = value.String
- }
- case proxy.FieldHost:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field host", values[i])
- } else if value.Valid {
- _m.Host = value.String
- }
- case proxy.FieldPort:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field port", values[i])
- } else if value.Valid {
- _m.Port = int(value.Int64)
- }
- case proxy.FieldUsername:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field username", values[i])
- } else if value.Valid {
- _m.Username = new(string)
- *_m.Username = value.String
- }
- case proxy.FieldPassword:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field password", values[i])
- } else if value.Valid {
- _m.Password = new(string)
- *_m.Password = value.String
- }
- case proxy.FieldStatus:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field status", values[i])
- } else if value.Valid {
- _m.Status = value.String
- }
- case proxy.FieldExpiresAt:
- if value, ok := values[i].(*sql.NullTime); !ok {
- return fmt.Errorf("unexpected type %T for field expires_at", values[i])
- } else if value.Valid {
- _m.ExpiresAt = new(time.Time)
- *_m.ExpiresAt = value.Time
- }
- case proxy.FieldFallbackMode:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field fallback_mode", values[i])
- } else if value.Valid {
- _m.FallbackMode = value.String
- }
- case proxy.FieldBackupProxyID:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field backup_proxy_id", values[i])
- } else if value.Valid {
- _m.BackupProxyID = new(int64)
- *_m.BackupProxyID = value.Int64
- }
- case proxy.FieldExpiryWarnDays:
- if value, ok := values[i].(*sql.NullInt64); !ok {
- return fmt.Errorf("unexpected type %T for field expiry_warn_days", values[i])
- } else if value.Valid {
- _m.ExpiryWarnDays = int(value.Int64)
- }
- default:
- _m.selectValues.Set(columns[i], values[i])
- }
- }
- return nil
- }
- // Value returns the ent.Value that was dynamically selected and assigned to the Proxy.
- // This includes values selected through modifiers, order, etc.
- func (_m *Proxy) Value(name string) (ent.Value, error) {
- return _m.selectValues.Get(name)
- }
- // QueryAccounts queries the "accounts" edge of the Proxy entity.
- func (_m *Proxy) QueryAccounts() *AccountQuery {
- return NewProxyClient(_m.config).QueryAccounts(_m)
- }
- // QueryPrimaryProxies queries the "primary_proxies" edge of the Proxy entity.
- func (_m *Proxy) QueryPrimaryProxies() *ProxyQuery {
- return NewProxyClient(_m.config).QueryPrimaryProxies(_m)
- }
- // QueryBackupProxy queries the "backup_proxy" edge of the Proxy entity.
- func (_m *Proxy) QueryBackupProxy() *ProxyQuery {
- return NewProxyClient(_m.config).QueryBackupProxy(_m)
- }
- // Update returns a builder for updating this Proxy.
- // Note that you need to call Proxy.Unwrap() before calling this method if this Proxy
- // was returned from a transaction, and the transaction was committed or rolled back.
- func (_m *Proxy) Update() *ProxyUpdateOne {
- return NewProxyClient(_m.config).UpdateOne(_m)
- }
- // Unwrap unwraps the Proxy 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 (_m *Proxy) Unwrap() *Proxy {
- _tx, ok := _m.config.driver.(*txDriver)
- if !ok {
- panic("ent: Proxy is not a transactional entity")
- }
- _m.config.driver = _tx.drv
- return _m
- }
- // String implements the fmt.Stringer.
- func (_m *Proxy) String() string {
- var builder strings.Builder
- builder.WriteString("Proxy(")
- builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
- builder.WriteString("created_at=")
- builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
- builder.WriteString(", ")
- builder.WriteString("updated_at=")
- builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
- builder.WriteString(", ")
- if v := _m.DeletedAt; v != nil {
- builder.WriteString("deleted_at=")
- builder.WriteString(v.Format(time.ANSIC))
- }
- builder.WriteString(", ")
- builder.WriteString("name=")
- builder.WriteString(_m.Name)
- builder.WriteString(", ")
- builder.WriteString("protocol=")
- builder.WriteString(_m.Protocol)
- builder.WriteString(", ")
- builder.WriteString("host=")
- builder.WriteString(_m.Host)
- builder.WriteString(", ")
- builder.WriteString("port=")
- builder.WriteString(fmt.Sprintf("%v", _m.Port))
- builder.WriteString(", ")
- if v := _m.Username; v != nil {
- builder.WriteString("username=")
- builder.WriteString(*v)
- }
- builder.WriteString(", ")
- if v := _m.Password; v != nil {
- builder.WriteString("password=")
- builder.WriteString(*v)
- }
- builder.WriteString(", ")
- builder.WriteString("status=")
- builder.WriteString(_m.Status)
- builder.WriteString(", ")
- if v := _m.ExpiresAt; v != nil {
- builder.WriteString("expires_at=")
- builder.WriteString(v.Format(time.ANSIC))
- }
- builder.WriteString(", ")
- builder.WriteString("fallback_mode=")
- builder.WriteString(_m.FallbackMode)
- builder.WriteString(", ")
- if v := _m.BackupProxyID; v != nil {
- builder.WriteString("backup_proxy_id=")
- builder.WriteString(fmt.Sprintf("%v", *v))
- }
- builder.WriteString(", ")
- builder.WriteString("expiry_warn_days=")
- builder.WriteString(fmt.Sprintf("%v", _m.ExpiryWarnDays))
- builder.WriteByte(')')
- return builder.String()
- }
- // Proxies is a parsable slice of Proxy.
- type Proxies []*Proxy
|