544 lines
14 KiB
Go
544 lines
14 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package session
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/examples/migration/ent/predicate"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Mutation represents an operation that mutates the Session nodes in the graph.
|
|
type Mutation struct {
|
|
op ent.Op
|
|
typ string
|
|
active *bool
|
|
issued_at *time.Time
|
|
expires_at *time.Time
|
|
token *string
|
|
method *map[string]interface{}
|
|
clearedFields map[string]struct{}
|
|
device *uuid.UUID
|
|
cleareddevice bool
|
|
predicates []predicate.Session
|
|
}
|
|
|
|
// NewMutation creates a new Mutation for the Session entity.
|
|
func NewMutation(op ent.Op) *Mutation {
|
|
return &Mutation{
|
|
op: op,
|
|
typ: "Session",
|
|
clearedFields: make(map[string]struct{}),
|
|
}
|
|
}
|
|
|
|
// Predicates returns the list of predicates set on the mutation.
|
|
func (m *Mutation) Predicates() []predicate.Session {
|
|
return m.predicates
|
|
}
|
|
|
|
// SetActive sets the "active" field.
|
|
func (m *Mutation) SetActive(b bool) {
|
|
m.active = &b
|
|
}
|
|
|
|
// Active returns the value of the "active" field in the mutation.
|
|
func (m *Mutation) Active() (r bool, exists bool) {
|
|
v := m.active
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetActive resets all changes to the "active" field.
|
|
func (m *Mutation) ResetActive() {
|
|
m.active = nil
|
|
}
|
|
|
|
// SetIssuedAt sets the "issued_at" field.
|
|
func (m *Mutation) SetIssuedAt(t time.Time) {
|
|
m.issued_at = &t
|
|
}
|
|
|
|
// IssuedAt returns the value of the "issued_at" field in the mutation.
|
|
func (m *Mutation) IssuedAt() (r time.Time, exists bool) {
|
|
v := m.issued_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ResetIssuedAt resets all changes to the "issued_at" field.
|
|
func (m *Mutation) ResetIssuedAt() {
|
|
m.issued_at = nil
|
|
}
|
|
|
|
// SetExpiresAt sets the "expires_at" field.
|
|
func (m *Mutation) SetExpiresAt(t time.Time) {
|
|
m.expires_at = &t
|
|
}
|
|
|
|
// ExpiresAt returns the value of the "expires_at" field in the mutation.
|
|
func (m *Mutation) ExpiresAt() (r time.Time, exists bool) {
|
|
v := m.expires_at
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearExpiresAt clears the value of the "expires_at" field.
|
|
func (m *Mutation) ClearExpiresAt() {
|
|
m.expires_at = nil
|
|
m.clearedFields[FieldExpiresAt] = struct{}{}
|
|
}
|
|
|
|
// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
|
|
func (m *Mutation) ExpiresAtCleared() bool {
|
|
_, ok := m.clearedFields[FieldExpiresAt]
|
|
return ok
|
|
}
|
|
|
|
// ResetExpiresAt resets all changes to the "expires_at" field.
|
|
func (m *Mutation) ResetExpiresAt() {
|
|
m.expires_at = nil
|
|
delete(m.clearedFields, FieldExpiresAt)
|
|
}
|
|
|
|
// SetToken sets the "token" field.
|
|
func (m *Mutation) SetToken(s string) {
|
|
m.token = &s
|
|
}
|
|
|
|
// Token returns the value of the "token" field in the mutation.
|
|
func (m *Mutation) Token() (r string, exists bool) {
|
|
v := m.token
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearToken clears the value of the "token" field.
|
|
func (m *Mutation) ClearToken() {
|
|
m.token = nil
|
|
m.clearedFields[FieldToken] = struct{}{}
|
|
}
|
|
|
|
// TokenCleared returns if the "token" field was cleared in this mutation.
|
|
func (m *Mutation) TokenCleared() bool {
|
|
_, ok := m.clearedFields[FieldToken]
|
|
return ok
|
|
}
|
|
|
|
// ResetToken resets all changes to the "token" field.
|
|
func (m *Mutation) ResetToken() {
|
|
m.token = nil
|
|
delete(m.clearedFields, FieldToken)
|
|
}
|
|
|
|
// SetMethod sets the "method" field.
|
|
func (m *Mutation) SetMethod(value map[string]interface{}) {
|
|
m.method = &value
|
|
}
|
|
|
|
// Method returns the value of the "method" field in the mutation.
|
|
func (m *Mutation) Method() (r map[string]interface{}, exists bool) {
|
|
v := m.method
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearMethod clears the value of the "method" field.
|
|
func (m *Mutation) ClearMethod() {
|
|
m.method = nil
|
|
m.clearedFields[FieldMethod] = struct{}{}
|
|
}
|
|
|
|
// MethodCleared returns if the "method" field was cleared in this mutation.
|
|
func (m *Mutation) MethodCleared() bool {
|
|
_, ok := m.clearedFields[FieldMethod]
|
|
return ok
|
|
}
|
|
|
|
// ResetMethod resets all changes to the "method" field.
|
|
func (m *Mutation) ResetMethod() {
|
|
m.method = nil
|
|
delete(m.clearedFields, FieldMethod)
|
|
}
|
|
|
|
// SetDeviceID sets the "device_id" field.
|
|
func (m *Mutation) SetDeviceID(u uuid.UUID) {
|
|
m.device = &u
|
|
}
|
|
|
|
// DeviceID returns the value of the "device_id" field in the mutation.
|
|
func (m *Mutation) DeviceID() (r uuid.UUID, exists bool) {
|
|
v := m.device
|
|
if v == nil {
|
|
return
|
|
}
|
|
return *v, true
|
|
}
|
|
|
|
// ClearDeviceID clears the value of the "device_id" field.
|
|
func (m *Mutation) ClearDeviceID() {
|
|
m.device = nil
|
|
m.clearedFields[FieldDeviceID] = struct{}{}
|
|
}
|
|
|
|
// DeviceIDCleared returns if the "device_id" field was cleared in this mutation.
|
|
func (m *Mutation) DeviceIDCleared() bool {
|
|
_, ok := m.clearedFields[FieldDeviceID]
|
|
return ok
|
|
}
|
|
|
|
// ResetDeviceID resets all changes to the "device_id" field.
|
|
func (m *Mutation) ResetDeviceID() {
|
|
m.device = nil
|
|
delete(m.clearedFields, FieldDeviceID)
|
|
}
|
|
|
|
// ClearDevice clears the "device" edge to the SessionDevice entity.
|
|
func (m *Mutation) ClearDevice() {
|
|
m.cleareddevice = true
|
|
m.clearedFields[FieldDeviceID] = struct{}{}
|
|
}
|
|
|
|
// DeviceCleared reports if the "device" edge to the SessionDevice entity was cleared.
|
|
func (m *Mutation) DeviceCleared() bool {
|
|
return m.DeviceIDCleared() || m.cleareddevice
|
|
}
|
|
|
|
// DeviceIDs returns the "device" edge IDs in the mutation.
|
|
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
|
// DeviceID instead. It exists only for internal usage by the builders.
|
|
func (m *Mutation) DeviceIDs() (ids []uuid.UUID) {
|
|
if id := m.device; id != nil {
|
|
ids = append(ids, *id)
|
|
}
|
|
return
|
|
}
|
|
|
|
// ResetDevice resets all changes to the "device" edge.
|
|
func (m *Mutation) ResetDevice() {
|
|
m.device = nil
|
|
m.cleareddevice = false
|
|
}
|
|
|
|
// Where appends a list predicates to the Mutation builder.
|
|
func (m *Mutation) Where(ps ...predicate.Session) {
|
|
m.predicates = append(m.predicates, ps...)
|
|
}
|
|
|
|
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
|
// users can use type-assertion to append predicates that do not depend on any generated package.
|
|
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
|
p := make([]predicate.Session, len(ps))
|
|
for i := range ps {
|
|
p[i] = ps[i]
|
|
}
|
|
m.Where(p...)
|
|
}
|
|
|
|
// Op returns the operation name.
|
|
func (m *Mutation) Op() ent.Op {
|
|
return m.op
|
|
}
|
|
|
|
// SetOp allows setting the mutation operation.
|
|
func (m *Mutation) SetOp(op ent.Op) {
|
|
m.op = op
|
|
}
|
|
|
|
// Type returns the node type of this mutation (Session).
|
|
func (m *Mutation) Type() string {
|
|
return m.typ
|
|
}
|
|
|
|
// Fields returns all fields that were changed during this mutation. Note that in
|
|
// order to get all numeric fields that were incremented/decremented, call
|
|
// AddedFields().
|
|
func (m *Mutation) Fields() []string {
|
|
fields := make([]string, 0, 6)
|
|
if m.active != nil {
|
|
fields = append(fields, FieldActive)
|
|
}
|
|
if m.issued_at != nil {
|
|
fields = append(fields, FieldIssuedAt)
|
|
}
|
|
if m.expires_at != nil {
|
|
fields = append(fields, FieldExpiresAt)
|
|
}
|
|
if m.token != nil {
|
|
fields = append(fields, FieldToken)
|
|
}
|
|
if m.method != nil {
|
|
fields = append(fields, FieldMethod)
|
|
}
|
|
if m.device != nil {
|
|
fields = append(fields, FieldDeviceID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// Field returns the value of a field with the given name. The second boolean
|
|
// return value indicates that this field was not set, or was not defined in the
|
|
// schema.
|
|
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
|
switch name {
|
|
case FieldActive:
|
|
return m.Active()
|
|
case FieldIssuedAt:
|
|
return m.IssuedAt()
|
|
case FieldExpiresAt:
|
|
return m.ExpiresAt()
|
|
case FieldToken:
|
|
return m.Token()
|
|
case FieldMethod:
|
|
return m.Method()
|
|
case FieldDeviceID:
|
|
return m.DeviceID()
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
// OldField returns the old value of the field from the database. An error is
|
|
// returned if the mutation operation is not UpdateOne, or the query to the
|
|
// database failed.
|
|
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
|
return nil, fmt.Errorf("unknown Session field %s", name)
|
|
}
|
|
|
|
// SetField sets the value of a field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *Mutation) SetField(name string, value ent.Value) error {
|
|
switch name {
|
|
case FieldActive:
|
|
v, ok := value.(bool)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetActive(v)
|
|
return nil
|
|
case FieldIssuedAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetIssuedAt(v)
|
|
return nil
|
|
case FieldExpiresAt:
|
|
v, ok := value.(time.Time)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetExpiresAt(v)
|
|
return nil
|
|
case FieldToken:
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetToken(v)
|
|
return nil
|
|
case FieldMethod:
|
|
v, ok := value.(map[string]interface{})
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetMethod(v)
|
|
return nil
|
|
case FieldDeviceID:
|
|
v, ok := value.(uuid.UUID)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
|
}
|
|
m.SetDeviceID(v)
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Session field %s", name)
|
|
}
|
|
|
|
// AddedFields returns all numeric fields that were incremented/decremented during
|
|
// this mutation.
|
|
func (m *Mutation) AddedFields() []string {
|
|
return nil
|
|
}
|
|
|
|
// AddedField returns the numeric value that was incremented/decremented on a field
|
|
// with the given name. The second boolean return value indicates that this field
|
|
// was not set, or was not defined in the schema.
|
|
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
|
return nil, false
|
|
}
|
|
|
|
// AddField adds the value to the field with the given name. It returns an error if
|
|
// the field is not defined in the schema, or if the type mismatched the field
|
|
// type.
|
|
func (m *Mutation) AddField(name string, value ent.Value) error {
|
|
switch name {
|
|
}
|
|
return fmt.Errorf("unknown Session numeric field %s", name)
|
|
}
|
|
|
|
// ClearedFields returns all nullable fields that were cleared during this
|
|
// mutation.
|
|
func (m *Mutation) ClearedFields() []string {
|
|
var fields []string
|
|
if m.FieldCleared(FieldExpiresAt) {
|
|
fields = append(fields, FieldExpiresAt)
|
|
}
|
|
if m.FieldCleared(FieldToken) {
|
|
fields = append(fields, FieldToken)
|
|
}
|
|
if m.FieldCleared(FieldMethod) {
|
|
fields = append(fields, FieldMethod)
|
|
}
|
|
if m.FieldCleared(FieldDeviceID) {
|
|
fields = append(fields, FieldDeviceID)
|
|
}
|
|
return fields
|
|
}
|
|
|
|
// FieldCleared returns a boolean indicating if a field with the given name was
|
|
// cleared in this mutation.
|
|
func (m *Mutation) FieldCleared(name string) bool {
|
|
_, ok := m.clearedFields[name]
|
|
return ok
|
|
}
|
|
|
|
// ClearField clears the value of the field with the given name. It returns an
|
|
// error if the field is not defined in the schema.
|
|
func (m *Mutation) ClearField(name string) error {
|
|
switch name {
|
|
case FieldExpiresAt:
|
|
m.ClearExpiresAt()
|
|
return nil
|
|
case FieldToken:
|
|
m.ClearToken()
|
|
return nil
|
|
case FieldMethod:
|
|
m.ClearMethod()
|
|
return nil
|
|
case FieldDeviceID:
|
|
m.ClearDeviceID()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Session nullable field %s", name)
|
|
}
|
|
|
|
// ResetField resets all changes in the mutation for the field with the given name.
|
|
// It returns an error if the field is not defined in the schema.
|
|
func (m *Mutation) ResetField(name string) error {
|
|
switch name {
|
|
case FieldActive:
|
|
m.ResetActive()
|
|
return nil
|
|
case FieldIssuedAt:
|
|
m.ResetIssuedAt()
|
|
return nil
|
|
case FieldExpiresAt:
|
|
m.ResetExpiresAt()
|
|
return nil
|
|
case FieldToken:
|
|
m.ResetToken()
|
|
return nil
|
|
case FieldMethod:
|
|
m.ResetMethod()
|
|
return nil
|
|
case FieldDeviceID:
|
|
m.ResetDeviceID()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Session field %s", name)
|
|
}
|
|
|
|
// AddedEdges returns all edge names that were set/added in this mutation.
|
|
func (m *Mutation) AddedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.device != nil {
|
|
edges = append(edges, EdgeDevice)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
|
// name in this mutation.
|
|
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
|
switch name {
|
|
case EdgeDevice:
|
|
if id := m.device; id != nil {
|
|
return []ent.Value{*id}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RemovedEdges returns all edge names that were removed in this mutation.
|
|
func (m *Mutation) RemovedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
return edges
|
|
}
|
|
|
|
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
|
// the given name in this mutation.
|
|
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
|
return nil
|
|
}
|
|
|
|
// ClearedEdges returns all edge names that were cleared in this mutation.
|
|
func (m *Mutation) ClearedEdges() []string {
|
|
edges := make([]string, 0, 1)
|
|
if m.cleareddevice {
|
|
edges = append(edges, EdgeDevice)
|
|
}
|
|
return edges
|
|
}
|
|
|
|
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
|
// was cleared in this mutation.
|
|
func (m *Mutation) EdgeCleared(name string) bool {
|
|
switch name {
|
|
case EdgeDevice:
|
|
return m.cleareddevice
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ClearEdge clears the value of the edge with the given name. It returns an error
|
|
// if that edge is not defined in the schema.
|
|
func (m *Mutation) ClearEdge(name string) error {
|
|
switch name {
|
|
case EdgeDevice:
|
|
m.ClearDevice()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Session unique edge %s", name)
|
|
}
|
|
|
|
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
|
// It returns an error if the edge is not defined in the schema.
|
|
func (m *Mutation) ResetEdge(name string) error {
|
|
switch name {
|
|
case EdgeDevice:
|
|
m.ResetDevice()
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unknown Session edge %s", name)
|
|
}
|