192 lines
6.4 KiB
Go
192 lines
6.4 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"time"
|
||
|
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"gitserver.in/patialtech/rano/db/ent/user"
|
||
|
"gitserver.in/patialtech/rano/db/ent/usersession"
|
||
|
)
|
||
|
|
||
|
// UserSession is the model entity for the UserSession schema.
|
||
|
type UserSession struct {
|
||
|
config `json:"-"`
|
||
|
// ID of the ent.
|
||
|
ID int64 `json:"id,omitempty"`
|
||
|
// IssuedAt holds the value of the "issued_at" field.
|
||
|
IssuedAt time.Time `json:"issued_at,omitempty"`
|
||
|
// ExpiresAt holds the value of the "expires_at" field.
|
||
|
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||
|
// Invalidated holds the value of the "invalidated" field.
|
||
|
Invalidated bool `json:"invalidated,omitempty"`
|
||
|
// UserAgent holds the value of the "user_agent" field.
|
||
|
UserAgent string `json:"user_agent,omitempty"`
|
||
|
// IP holds the value of the "ip" field.
|
||
|
IP string `json:"ip,omitempty"`
|
||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||
|
// The values are being populated by the UserSessionQuery when eager-loading is set.
|
||
|
Edges UserSessionEdges `json:"edges"`
|
||
|
user_id *int64
|
||
|
selectValues sql.SelectValues
|
||
|
}
|
||
|
|
||
|
// UserSessionEdges holds the relations/edges for other nodes in the graph.
|
||
|
type UserSessionEdges struct {
|
||
|
// User holds the value of the user edge.
|
||
|
User *User `json:"user,omitempty"`
|
||
|
// loadedTypes holds the information for reporting if a
|
||
|
// type was loaded (or requested) in eager-loading or not.
|
||
|
loadedTypes [1]bool
|
||
|
}
|
||
|
|
||
|
// UserOrErr returns the User value or an error if the edge
|
||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||
|
func (e UserSessionEdges) UserOrErr() (*User, error) {
|
||
|
if e.User != nil {
|
||
|
return e.User, nil
|
||
|
} else if e.loadedTypes[0] {
|
||
|
return nil, &NotFoundError{label: user.Label}
|
||
|
}
|
||
|
return nil, &NotLoadedError{edge: "user"}
|
||
|
}
|
||
|
|
||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||
|
func (*UserSession) scanValues(columns []string) ([]any, error) {
|
||
|
values := make([]any, len(columns))
|
||
|
for i := range columns {
|
||
|
switch columns[i] {
|
||
|
case usersession.FieldInvalidated:
|
||
|
values[i] = new(sql.NullBool)
|
||
|
case usersession.FieldID:
|
||
|
values[i] = new(sql.NullInt64)
|
||
|
case usersession.FieldUserAgent, usersession.FieldIP:
|
||
|
values[i] = new(sql.NullString)
|
||
|
case usersession.FieldIssuedAt, usersession.FieldExpiresAt:
|
||
|
values[i] = new(sql.NullTime)
|
||
|
case usersession.ForeignKeys[0]: // user_id
|
||
|
values[i] = new(sql.NullInt64)
|
||
|
default:
|
||
|
values[i] = new(sql.UnknownType)
|
||
|
}
|
||
|
}
|
||
|
return values, nil
|
||
|
}
|
||
|
|
||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||
|
// to the UserSession fields.
|
||
|
func (us *UserSession) 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 usersession.FieldID:
|
||
|
value, ok := values[i].(*sql.NullInt64)
|
||
|
if !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||
|
}
|
||
|
us.ID = int64(value.Int64)
|
||
|
case usersession.FieldIssuedAt:
|
||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field issued_at", values[i])
|
||
|
} else if value.Valid {
|
||
|
us.IssuedAt = value.Time
|
||
|
}
|
||
|
case usersession.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 {
|
||
|
us.ExpiresAt = value.Time
|
||
|
}
|
||
|
case usersession.FieldInvalidated:
|
||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field invalidated", values[i])
|
||
|
} else if value.Valid {
|
||
|
us.Invalidated = value.Bool
|
||
|
}
|
||
|
case usersession.FieldUserAgent:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field user_agent", values[i])
|
||
|
} else if value.Valid {
|
||
|
us.UserAgent = value.String
|
||
|
}
|
||
|
case usersession.FieldIP:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field ip", values[i])
|
||
|
} else if value.Valid {
|
||
|
us.IP = value.String
|
||
|
}
|
||
|
case usersession.ForeignKeys[0]:
|
||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for edge-field user_id", value)
|
||
|
} else if value.Valid {
|
||
|
us.user_id = new(int64)
|
||
|
*us.user_id = int64(value.Int64)
|
||
|
}
|
||
|
default:
|
||
|
us.selectValues.Set(columns[i], values[i])
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// Value returns the ent.Value that was dynamically selected and assigned to the UserSession.
|
||
|
// This includes values selected through modifiers, order, etc.
|
||
|
func (us *UserSession) Value(name string) (ent.Value, error) {
|
||
|
return us.selectValues.Get(name)
|
||
|
}
|
||
|
|
||
|
// QueryUser queries the "user" edge of the UserSession entity.
|
||
|
func (us *UserSession) QueryUser() *UserQuery {
|
||
|
return NewUserSessionClient(us.config).QueryUser(us)
|
||
|
}
|
||
|
|
||
|
// Update returns a builder for updating this UserSession.
|
||
|
// Note that you need to call UserSession.Unwrap() before calling this method if this UserSession
|
||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||
|
func (us *UserSession) Update() *UserSessionUpdateOne {
|
||
|
return NewUserSessionClient(us.config).UpdateOne(us)
|
||
|
}
|
||
|
|
||
|
// Unwrap unwraps the UserSession 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 (us *UserSession) Unwrap() *UserSession {
|
||
|
_tx, ok := us.config.driver.(*txDriver)
|
||
|
if !ok {
|
||
|
panic("ent: UserSession is not a transactional entity")
|
||
|
}
|
||
|
us.config.driver = _tx.drv
|
||
|
return us
|
||
|
}
|
||
|
|
||
|
// String implements the fmt.Stringer.
|
||
|
func (us *UserSession) String() string {
|
||
|
var builder strings.Builder
|
||
|
builder.WriteString("UserSession(")
|
||
|
builder.WriteString(fmt.Sprintf("id=%v, ", us.ID))
|
||
|
builder.WriteString("issued_at=")
|
||
|
builder.WriteString(us.IssuedAt.Format(time.ANSIC))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("expires_at=")
|
||
|
builder.WriteString(us.ExpiresAt.Format(time.ANSIC))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("invalidated=")
|
||
|
builder.WriteString(fmt.Sprintf("%v", us.Invalidated))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("user_agent=")
|
||
|
builder.WriteString(us.UserAgent)
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("ip=")
|
||
|
builder.WriteString(us.IP)
|
||
|
builder.WriteByte(')')
|
||
|
return builder.String()
|
||
|
}
|
||
|
|
||
|
// UserSessions is a parsable slice of UserSession.
|
||
|
type UserSessions []*UserSession
|