store

package
v3.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package store implements the Identity Server store interfaces using the bun library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear added in v3.24.0

func Clear(ctx context.Context, db *bun.DB) error

Clear database tables for all registered models. This should be used with caution.

func Initialize added in v3.24.0

func Initialize(ctx context.Context, db *bun.DB, dbName string) error

Initialize initializes the database.

func Migrate

func Migrate(ctx context.Context, db *bun.DB) error

Migrate migrates the database.

func Open added in v3.24.0

func Open(ctx context.Context, dsn string) (*bun.DB, error)

Open a new database connection.

Types

type APIKey

type APIKey struct {
	bun.BaseModel `bun:"table:api_keys,alias:key"`

	Model

	APIKeyID string `bun:"api_key_id,nullzero"`

	Key    string `bun:"key,nullzero"`
	Rights []int  `bun:"rights,array,nullzero"`
	Name   string `bun:"name,nullzero"`

	// EntityType is "application", "client", "end_device", "gateway", "organization" or "user".
	EntityType string `bun:"entity_type,notnull"`
	// EntityID is Application.ID, Client.ID, EndDevice.ID, Gateway.ID, Organization.ID or User.ID.
	EntityID string `bun:"entity_id,notnull"`

	ExpiresAt *time.Time `bun:"expires_at"`
}

APIKey is the API key model in the database.

func (*APIKey) BeforeAppendModel

func (m *APIKey) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type AccessToken

type AccessToken struct {
	bun.BaseModel `bun:"table:access_tokens,alias:oat"`

	Model

	Client   *Client `bun:"rel:belongs-to,join:client_id=id"`
	ClientID string  `bun:"client_id,notnull"`

	User   *User  `bun:"rel:belongs-to,join:user_id=id"`
	UserID string `bun:"user_id,notnull"`

	UserSession   *UserSession `bun:"rel:belongs-to,join:user_session_id=id"`
	UserSessionID string       `bun:"user_session_id,nullzero"`

	Rights []int `bun:"rights,array,nullzero"`

	TokenID string `bun:"token_id,notnull"`

	Previous   *AccessToken `bun:"rel:belongs-to,join:previous_id=id"`
	PreviousID string       `bun:"previous_id,nullzero"`

	AccessToken  string `bun:"access_token,notnull"`
	RefreshToken string `bun:"refresh_token,notnull"`

	ExpiresAt *time.Time `bun:"expires_at"`
}

AccessToken is the OAuth access token model in the database.

func (*AccessToken) BeforeAppendModel

func (m *AccessToken) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Account

type Account struct {
	bun.BaseModel `bun:"table:accounts,alias:acc"`

	Model
	SoftDelete

	UID string `bun:"uid,notnull"`

	AccountID   string `bun:"account_id,notnull"`
	AccountType string `bun:"account_type,notnull"` // user or organization
}

Account is the account model in the database.

func (*Account) BeforeAppendModel

func (m *Account) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

func (*Account) GetOrganizationOrUserIdentifiers

func (m *Account) GetOrganizationOrUserIdentifiers() *ttnpb.OrganizationOrUserIdentifiers

GetOrganizationOrUserIdentifiers returns organization or user identifiers for the account.

type Application

type Application struct {
	bun.BaseModel `bun:"table:applications,alias:app"`

	Model
	SoftDelete

	ApplicationID string `bun:"application_id,notnull"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	ContactInfo []*ContactInfo `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	AdministrativeContactID *string  `bun:"administrative_contact_id,type:uuid"`
	AdministrativeContact   *Account `bun:"rel:belongs-to,join:administrative_contact_id=id"`

	TechnicalContactID *string  `bun:"technical_contact_id,type:uuid"`
	TechnicalContact   *Account `bun:"rel:belongs-to,join:technical_contact_id=id"`

	NetworkServerAddress     string `bun:"network_server_address,nullzero"`
	ApplicationServerAddress string `bun:"application_server_address,nullzero"`
	JoinServerAddress        string `bun:"join_server_address,nullzero"`

	DevEUICounter int `bun:"dev_eui_counter,nullzero"`
}

Application is the application model in the database.

func (*Application) BeforeAppendModel

func (m *Application) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Attribute

type Attribute struct {
	bun.BaseModel `bun:"table:attributes,alias:attr"`

	UUID

	// EntityType is "application", "client", "end_device", "gateway", "organization" or "user".
	EntityType string `bun:"entity_type,notnull"`
	// EntityID is Application.ID, Client.ID, EndDevice.ID, Gateway.ID, Organization.ID or User.ID.
	EntityID string `bun:"entity_id,notnull"`

	Key   string `bun:"key,notnull"`
	Value string `bun:"value,notnull"`
}

Attribute is the attribute model in the database.

type AttributeSlice

type AttributeSlice []*Attribute

AttributeSlice is a slice of Attributes.

func (AttributeSlice) Len

func (a AttributeSlice) Len() int

func (AttributeSlice) Less

func (a AttributeSlice) Less(i, j int) bool

func (AttributeSlice) Swap

func (a AttributeSlice) Swap(i, j int)

type AuthorizationCode

type AuthorizationCode struct {
	bun.BaseModel `bun:"table:authorization_codes,alias:oac"`

	Model

	Client   *Client `bun:"rel:belongs-to,join:client_id=id"`
	ClientID string  `bun:"client_id,notnull"`

	User   *User  `bun:"rel:belongs-to,join:user_id=id"`
	UserID string `bun:"user_id,notnull"`

	UserSession   *UserSession `bun:"rel:belongs-to,join:user_session_id=id"`
	UserSessionID string       `bun:"user_session_id,nullzero"`

	Rights []int `bun:"rights,array,nullzero"`

	Code        string `bun:"code,notnull"`
	RedirectURI string `bun:"redirect_uri,nullzero"`
	State       string `bun:"state,nullzero"`

	ExpiresAt *time.Time `bun:"expires_at"`
}

AuthorizationCode is the OAuth authorization code model in the database.

func (*AuthorizationCode) BeforeAppendModel

func (m *AuthorizationCode) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Client

type Client struct {
	bun.BaseModel `bun:"table:clients,alias:cli"`

	Model
	SoftDelete

	ClientID string `bun:"client_id,notnull"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	ContactInfo []*ContactInfo `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	AdministrativeContactID *string  `bun:"administrative_contact_id,type:uuid"`
	AdministrativeContact   *Account `bun:"rel:belongs-to,join:administrative_contact_id=id"`

	TechnicalContactID *string  `bun:"technical_contact_id,type:uuid"`
	TechnicalContact   *Account `bun:"rel:belongs-to,join:technical_contact_id=id"`

	ClientSecret string `bun:"client_secret,nullzero"`

	RedirectURIs       []string `bun:"redirect_uris,array,nullzero"`
	LogoutRedirectURIs []string `bun:"logout_redirect_uris,array,nullzero"`

	State            int    `bun:"state,notnull"`
	StateDescription string `bun:"state_description,nullzero"`

	SkipAuthorization bool `bun:"skip_authorization,notnull"`
	Endorsed          bool `bun:"endorsed,notnull"`

	Grants []int `bun:"grants,array,nullzero"`
	Rights []int `bun:"rights,array,nullzero"`
}

Client is the client model in the database.

func (*Client) BeforeAppendModel

func (m *Client) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type ClientAuthorization

type ClientAuthorization struct {
	bun.BaseModel `bun:"table:client_authorizations,alias:oca"`

	Model

	Client   *Client `bun:"rel:belongs-to,join:client_id=id"`
	ClientID string  `bun:"client_id,notnull"`

	User   *User  `bun:"rel:belongs-to,join:user_id=id"`
	UserID string `bun:"user_id,notnull"`

	Rights []int `bun:"rights,array,nullzero"`
}

ClientAuthorization is the OAuth client authorization model in the database.

func (*ClientAuthorization) BeforeAppendModel

func (m *ClientAuthorization) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type ContactInfo

type ContactInfo struct {
	bun.BaseModel `bun:"table:contact_infos,alias:ci"`

	UUID

	// EntityType is "application", "client", "end_device", "gateway", "organization" or "user".
	EntityType string `bun:"entity_type,notnull"`
	// EntityID is Application.ID, Client.ID, EndDevice.ID, Gateway.ID, Organization.ID or User.ID.
	EntityID string `bun:"entity_id,notnull"`

	ContactType   int    `bun:"contact_type,notnull"`
	ContactMethod int    `bun:"contact_method,notnull"`
	Value         string `bun:"value,notnull"`

	Public bool `bun:"public"`

	ValidatedAt *time.Time `bun:"validated_at"`
}

ContactInfo is the contact info model in the database.

type ContactInfoSlice

type ContactInfoSlice []*ContactInfo

ContactInfoSlice is a slice of ContactInfo.

func (ContactInfoSlice) Len

func (a ContactInfoSlice) Len() int

func (ContactInfoSlice) Less

func (a ContactInfoSlice) Less(i, j int) bool

func (ContactInfoSlice) Swap

func (a ContactInfoSlice) Swap(i, j int)

type ContactInfoValidation

type ContactInfoValidation struct {
	bun.BaseModel `bun:"table:contact_info_validations,alias:civ"`

	Model

	Reference string `bun:"reference,nullzero"`
	Token     string `bun:"token,nullzero"`

	// EntityType is "application", "client", "gateway", "organization" or "user".
	EntityType string `bun:"entity_type,notnull"`
	// EntityID is Application.ID, Client.ID, Gateway.ID, Organization.ID or User.ID.
	EntityID string `bun:"entity_id,notnull"`

	ContactMethod int    `bun:"contact_method,notnull"`
	Value         string `bun:"value,nullzero"`

	Used bool `bun:"used,nullzero"`

	ExpiresAt *time.Time `bun:"expires_at"`
}

ContactInfoValidation is the contact info validation model in the database.

func (*ContactInfoValidation) BeforeAppendModel

func (m *ContactInfoValidation) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type DBMetadata added in v3.24.0

type DBMetadata struct {
	// Version is the database version.
	Version string

	// Type is the database type (PostgreSQL, CockroachDB).
	Type string
}

DBMetadata wraps the database metadata needed to distinguish between PostgreSQL and CockroachDB.

type EUIBlock

type EUIBlock struct {
	bun.BaseModel `bun:"table:eui_blocks,alias:euib"`

	Model

	// TODO: The database schema allows NULL for the fields below. We should fix the schema.
	// https://github.com/TheThingsNetwork/lorawan-stack/issues/5613
	Type           string `bun:"type,notnull"`
	StartEUI       string `bun:"start_eui,notnull"`
	EndCounter     int64  `bun:"end_counter,notnull"`
	CurrentCounter int64  `bun:"current_counter,notnull"`
}

EUIBlock is the EUI block model in the database.

func (*EUIBlock) BeforeAppendModel

func (m *EUIBlock) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type EmbeddedAccount

type EmbeddedAccount struct {
	ID string `bun:"id,notnull,scanonly"`

	CreatedAt time.Time  `bun:"created_at,notnull,scanonly"`
	UpdatedAt time.Time  `bun:"updated_at,notnull,scanonly"`
	DeletedAt *time.Time `bun:"deleted_at,scanonly"`

	UID string `bun:"uid,notnull,scanonly"`
}

EmbeddedAccount contains the account fields that are embedded into User and Organization when loading them through the user_accounts and organization_accounts views.

type EndDevice

type EndDevice struct {
	bun.BaseModel `bun:"table:end_devices,alias:dev"`

	Model

	ApplicationID string `bun:"application_id,notnull"`
	DeviceID      string `bun:"device_id,notnull"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic:device"`

	JoinEUI *string `bun:"join_eui"`
	DevEUI  *string `bun:"dev_eui"`

	BrandID         string `bun:"brand_id,nullzero"`
	ModelID         string `bun:"model_id,nullzero"`
	HardwareVersion string `bun:"hardware_version,nullzero"`
	FirmwareVersion string `bun:"firmware_version,nullzero"`
	BandID          string `bun:"band_id,nullzero"`

	NetworkServerAddress     string `bun:"network_server_address,nullzero"`
	ApplicationServerAddress string `bun:"application_server_address,nullzero"`
	JoinServerAddress        string `bun:"join_server_address,nullzero"`

	SerialNumber     string `bun:"serial_number,nullzero"`
	ServiceProfileID string `bun:"service_profile_id,nullzero"`

	VendorID        uint32 `bun:"vendor_id,nullzero"`
	VendorProfileID uint32 `bun:"vendor_profile_id,nullzero"`

	Locations []*EndDeviceLocation `bun:"rel:has-many,join:id=end_device_id"`

	PictureID *string  `bun:"picture_id"`
	Picture   *Picture `bun:"rel:belongs-to,join:picture_id=id"`

	ActivatedAt *time.Time `bun:"activated_at"`
	LastSeenAt  *time.Time `bun:"last_seen_at"`

	ClaimAuthenticationCodeSecret    []byte     `bun:"claim_authentication_code_secret"`
	ClaimAuthenticationCodeValidFrom *time.Time `bun:"claim_authentication_code_valid_from"`
	ClaimAuthenticationCodeValidTo   *time.Time `bun:"claim_authentication_code_valid_to"`
}

EndDevice is the end_device model in the database.

func (*EndDevice) BeforeAppendModel

func (m *EndDevice) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type EndDeviceLocation

type EndDeviceLocation struct {
	bun.BaseModel `bun:"table:end_device_locations,alias:edloc"`

	Model

	EndDeviceID string     `bun:"end_device_id,notnull"`
	EndDevice   *EndDevice `bun:"rel:belongs-to,join:end_device_id=id"`

	Service string `bun:"service,nullzero"`

	Location

	Source int `bun:"source"`
}

EndDeviceLocation is the end device location model in the database.

type EndDeviceLocationSlice

type EndDeviceLocationSlice []*EndDeviceLocation

EndDeviceLocationSlice is a slice of EndDeviceLocation.

func (EndDeviceLocationSlice) Len

func (a EndDeviceLocationSlice) Len() int

func (EndDeviceLocationSlice) Less

func (a EndDeviceLocationSlice) Less(i, j int) bool

func (EndDeviceLocationSlice) Swap

func (a EndDeviceLocationSlice) Swap(i, j int)

type Gateway

type Gateway struct {
	bun.BaseModel `bun:"table:gateways,alias:gtw"`

	Model
	SoftDelete

	GatewayID  string  `bun:"gateway_id,notnull"`
	GatewayEUI *string `bun:"gateway_eui"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	ContactInfo []*ContactInfo `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	AdministrativeContactID *string  `bun:"administrative_contact_id,type:uuid"`
	AdministrativeContact   *Account `bun:"rel:belongs-to,join:administrative_contact_id=id"`

	TechnicalContactID *string  `bun:"technical_contact_id,type:uuid"`
	TechnicalContact   *Account `bun:"rel:belongs-to,join:technical_contact_id=id"`

	BrandID         string `bun:"brand_id,nullzero"`
	ModelID         string `bun:"model_id,nullzero"`
	HardwareVersion string `bun:"hardware_version,nullzero"`
	FirmwareVersion string `bun:"firmware_version,nullzero"`

	GatewayServerAddress string `bun:"gateway_server_address,nullzero"`

	AutoUpdate    bool   `bun:"auto_update,notnull"`
	UpdateChannel string `bun:"update_channel,nullzero"`

	// Frequency Plan IDs separated by spaces.
	FrequencyPlanID string `bun:"frequency_plan_id,nullzero"`

	StatusPublic   bool `bun:"status_public,notnull"`
	LocationPublic bool `bun:"location_public,notnull"`

	ScheduleDownlinkLate   bool  `bun:"schedule_downlink_late,notnull"`
	EnforceDutyCycle       bool  `bun:"enforce_duty_cycle,notnull"`
	ScheduleAnytimeDelay   int64 `bun:"schedule_anytime_delay,notnull"`
	DownlinkPathConstraint int   `bun:"downlink_path_constraint,nullzero"`

	UpdateLocationFromStatus bool `bun:"update_location_from_status,notnull"`

	Antennas []*GatewayAntenna `bun:"rel:has-many,join:id=gateway_id"`

	LBSLNSSecret []byte `bun:"lbs_lns_secret,nullzero"`

	ClaimAuthenticationCodeSecret    []byte     `bun:"claim_authentication_code_secret"`
	ClaimAuthenticationCodeValidFrom *time.Time `bun:"claim_authentication_code_valid_from"`
	ClaimAuthenticationCodeValidTo   *time.Time `bun:"claim_authentication_code_valid_to"`

	TargetCUPSURI string `bun:"target_cups_uri,nullzero"`
	TargetCUPSKey []byte `bun:"target_cups_key"`

	RequireAuthenticatedConnection bool `bun:"require_authenticated_connection,nullzero"`

	SupportsLRFHSS bool `bun:"supports_lrfhss,notnull"`

	DisablePacketBrokerForwarding bool `bun:"disable_packet_broker_forwarding,notnull"`
}

Gateway is the gateway model in the database.

func (*Gateway) BeforeAppendModel

func (m *Gateway) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type GatewayAntenna

type GatewayAntenna struct {
	bun.BaseModel `bun:"table:gateway_antennas,alias:ant"`

	Model

	GatewayID string   `bun:"gateway_id,notnull"`
	Gateway   *Gateway `bun:"rel:belongs-to,join:gateway_id=id"`

	Index int `bun:"index,notnull"`

	Gain float32 `bun:"gain,nullzero"`

	Location

	Placement int `bun:"placement,nullzero"`
}

GatewayAntenna is the gateway antenna model in the database.

type GatewayAntennaSlice

type GatewayAntennaSlice []*GatewayAntenna

GatewayAntennaSlice is a slice of GatewayAntenna.

func (GatewayAntennaSlice) Len

func (a GatewayAntennaSlice) Len() int

func (GatewayAntennaSlice) Less

func (a GatewayAntennaSlice) Less(i, j int) bool

func (GatewayAntennaSlice) Swap

func (a GatewayAntennaSlice) Swap(i, j int)

type Invitation

type Invitation struct {
	bun.BaseModel `bun:"table:invitations,alias:inv"`

	Model

	Email string `bun:"email,notnull"`
	Token string `bun:"token,notnull"`

	ExpiresAt *time.Time `bun:"expires_at"`

	AcceptedBy   *User      `bun:"rel:belongs-to,join:accepted_by_id=id"`
	AcceptedByID *string    `bun:"accepted_by_id"`
	AcceptedAt   *time.Time `bun:"accepted_at"`
}

Invitation is the invitation model in the database.

func (*Invitation) BeforeAppendModel

func (m *Invitation) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Location

type Location struct {
	Latitude  float64 `bun:"latitude,nullzero"`
	Longitude float64 `bun:"longitude,nullzero"`
	Altitude  int32   `bun:"altitude,nullzero"`
	Accuracy  int32   `bun:"accuracy,nullzero"`
}

Location can be embedded in other models to add location columns.

type LoggerHook

type LoggerHook struct {
	// contains filtered or unexported fields
}

LoggerHook is a bun.QueryHook that logs the queries.

func NewLoggerHook

func NewLoggerHook(logger log.Interface, opts ...LoggerHookOption) *LoggerHook

NewLoggerHook returns a new LoggerHook that logs queries to the logger.

func (*LoggerHook) AfterQuery

func (h *LoggerHook) AfterQuery(_ context.Context, event *bun.QueryEvent)

AfterQuery is the hook that is executed after the query runs.

func (*LoggerHook) BeforeQuery

func (*LoggerHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.Context

BeforeQuery is the hook that is executed before the query runs.

type LoggerHookOption

type LoggerHookOption func(*LoggerHook)

LoggerHookOption is an option for the LoggerHook.

type LoginToken

type LoginToken struct {
	bun.BaseModel `bun:"table:login_tokens,alias:lt"`

	Model

	User   *User  `bun:"rel:belongs-to,join:user_id=id"`
	UserID string `bun:"user_id"`

	Token string `bun:"token,notnull"`

	ExpiresAt *time.Time `bun:"expires_at"`
	Used      bool       `bun:"used,nullzero"`
}

LoginToken is the login token model in the database.

func (*LoginToken) BeforeAppendModel

func (m *LoginToken) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Membership

type Membership struct {
	bun.BaseModel `bun:"table:memberships,alias:mem"`

	Model

	AccountID string   `bun:"account_id,notnull"`
	Account   *Account `bun:"rel:belongs-to,join:account_id=id"`

	Rights []int `bun:"rights,array,nullzero"`

	EntityID   string `bun:"entity_id,notnull"`
	EntityType string `bun:"entity_type,notnull"`
}

Membership is the membership model in the database.

func (*Membership) BeforeAppendModel

func (m *Membership) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Model

type Model struct {
	UUID

	CreatedAt time.Time `bun:"created_at,notnull"`
	UpdatedAt time.Time `bun:"updated_at,notnull"`
}

Model is the base model for most of our types.

func (*Model) BeforeAppendModel

func (m *Model) BeforeAppendModel(_ context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Notification

type Notification struct {
	bun.BaseModel `bun:"table:notifications,alias:not"`

	Model

	// EntityType is "application", "client", "end_device", "gateway", "organization" or "user".
	EntityType string `bun:"entity_type,notnull"`
	// EntityID is Application.ID, Client.ID, EndDevice.ID, Gateway.ID, Organization.ID or User.ID.
	EntityID string `bun:"entity_id,notnull"`

	// EntityUID is a copy of the human-readable entity ID, so that we can keep notifications for deleted entities.
	EntityUID string `bun:"entity_uid,notnull"`

	NotificationType string `bun:"notification_type,notnull"`

	Data json.RawMessage `bun:"data,nullzero"`

	SenderID *string `bun:"sender_id"`

	// SenderUID is a copy of the human-readable sender ID, so that we can keep notifications for deleted senders.
	SenderUID string `bun:"sender_uid,notnull"`

	Receivers []int `bun:"receivers,array,nullzero"`

	Email bool `bun:"email,notnull"`
}

Notification is the notification model in the database.

func (*Notification) BeforeAppendModel

func (m *Notification) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type NotificationReceiver

type NotificationReceiver struct {
	bun.BaseModel `bun:"table:notification_receivers,alias:rec"`

	Notification   *Notification `bun:"rel:belongs-to,join:notification_id=id"`
	NotificationID string        `bun:"notification_id,notnull"`

	Receiver   *User  `bun:"rel:belongs-to,join:receiver_id=id"`
	ReceiverID string `bun:"receiver_id,notnull"`

	Status          int       `bun:"status,notnull"`
	StatusUpdatedAt time.Time `bun:"status_updated_at,notnull"`
}

NotificationReceiver is the notification receiver model in the database.

type Organization

type Organization struct {
	bun.BaseModel `bun:"table:organizations,alias:org,select:organization_accounts"`

	Model
	SoftDelete

	Account EmbeddedAccount `bun:"embed:account_"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	ContactInfo []*ContactInfo `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	AdministrativeContactID *string  `bun:"administrative_contact_id,type:uuid"`
	AdministrativeContact   *Account `bun:"rel:belongs-to,join:administrative_contact_id=id"`

	TechnicalContactID *string  `bun:"technical_contact_id,type:uuid"`
	TechnicalContact   *Account `bun:"rel:belongs-to,join:technical_contact_id=id"`
}

Organization is the organization model in the database.

func (*Organization) BeforeAppendModel

func (m *Organization) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type Picture

type Picture struct {
	bun.BaseModel `bun:"table:pictures,alias:pic"`

	Model
	SoftDelete

	Data []byte `bun:"data,type:bytea"`
}

Picture is the picture model in the database.

func (*Picture) BeforeAppendModel

func (m *Picture) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type SoftDelete

type SoftDelete struct {
	DeletedAt *time.Time `bun:"deleted_at,soft_delete"`
}

SoftDelete can be embedded in models that should have soft delete functionality.

type Store

type Store struct {
	TxOptions sql.TxOptions
	// contains filtered or unexported fields
}

Store is the combined store of all the individual stores.

func NewStore

func NewStore(ctx context.Context, db *bun.DB) (*Store, error)

NewStore returns a new store that implements store.TransactionalStore.

func (Store) Authorize

func (s Store) Authorize(
	ctx context.Context, pb *ttnpb.OAuthClientAuthorization,
) (authorization *ttnpb.OAuthClientAuthorization, err error)

func (Store) BatchUpdateEndDeviceLastSeen

func (s Store) BatchUpdateEndDeviceLastSeen(
	ctx context.Context,
	devsLastSeen []*ttnpb.BatchUpdateEndDeviceLastSeenRequest_EndDeviceLastSeenUpdate,
) error

func (Store) ConsumeLoginToken

func (s Store) ConsumeLoginToken(ctx context.Context, token string) (*ttnpb.LoginToken, error)

func (Store) CountApplications

func (s Store) CountApplications(ctx context.Context) (uint64, error)

func (Store) CountClients

func (s Store) CountClients(ctx context.Context) (uint64, error)

func (Store) CountEndDevices

func (s Store) CountEndDevices(ctx context.Context, ids *ttnpb.ApplicationIdentifiers) (uint64, error)

func (Store) CountGateways

func (s Store) CountGateways(ctx context.Context) (uint64, error)

func (Store) CountMemberships

func (s Store) CountMemberships(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string,
) (uint64, error)

func (Store) CountOrganizations

func (s Store) CountOrganizations(ctx context.Context) (uint64, error)

func (Store) CountUsers

func (s Store) CountUsers(ctx context.Context) (uint64, error)

func (Store) CreateAPIKey

func (s Store) CreateAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, pb *ttnpb.APIKey,
) (*ttnpb.APIKey, error)

func (Store) CreateAccessToken

func (s Store) CreateAccessToken(
	ctx context.Context, pb *ttnpb.OAuthAccessToken, previousID string,
) (*ttnpb.OAuthAccessToken, error)

func (Store) CreateApplication

func (s Store) CreateApplication(
	ctx context.Context, pb *ttnpb.Application,
) (*ttnpb.Application, error)

func (Store) CreateAuthorizationCode

func (s Store) CreateAuthorizationCode(
	ctx context.Context, pb *ttnpb.OAuthAuthorizationCode,
) (*ttnpb.OAuthAuthorizationCode, error)

func (Store) CreateClient

func (s Store) CreateClient(
	ctx context.Context, pb *ttnpb.Client,
) (*ttnpb.Client, error)

func (Store) CreateEUIBlock

func (s Store) CreateEUIBlock(
	ctx context.Context, prefix types.EUI64Prefix, initCounter int64, euiType string,
) error

func (Store) CreateEndDevice

func (s Store) CreateEndDevice(
	ctx context.Context, pb *ttnpb.EndDevice,
) (*ttnpb.EndDevice, error)

func (Store) CreateGateway

func (s Store) CreateGateway(
	ctx context.Context, pb *ttnpb.Gateway,
) (*ttnpb.Gateway, error)

func (Store) CreateInvitation

func (s Store) CreateInvitation(
	ctx context.Context, pb *ttnpb.Invitation,
) (*ttnpb.Invitation, error)

func (Store) CreateLoginToken

func (s Store) CreateLoginToken(ctx context.Context, pb *ttnpb.LoginToken) (*ttnpb.LoginToken, error)

func (Store) CreateNotification

func (s Store) CreateNotification(
	ctx context.Context, pb *ttnpb.Notification, receiverIDs []*ttnpb.UserIdentifiers,
) (*ttnpb.Notification, error)

func (Store) CreateOrganization

func (s Store) CreateOrganization(
	ctx context.Context, pb *ttnpb.Organization,
) (*ttnpb.Organization, error)

func (Store) CreateSession

func (s Store) CreateSession(
	ctx context.Context, pb *ttnpb.UserSession,
) (*ttnpb.UserSession, error)

func (Store) CreateUser

func (s Store) CreateUser(ctx context.Context, pb *ttnpb.User) (*ttnpb.User, error)

func (Store) CreateValidation

func (s Store) CreateValidation(
	ctx context.Context, pb *ttnpb.ContactInfoValidation,
) (*ttnpb.ContactInfoValidation, error)

func (Store) DeleteAccessToken

func (s Store) DeleteAccessToken(ctx context.Context, id string) error

func (Store) DeleteAccountMembers

func (s Store) DeleteAccountMembers(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers,
) error

func (Store) DeleteAllUserSessions

func (s Store) DeleteAllUserSessions(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error

func (Store) DeleteApplication

func (s Store) DeleteApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (Store) DeleteAuthorization

func (s Store) DeleteAuthorization(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) error

func (Store) DeleteAuthorizationCode

func (s Store) DeleteAuthorizationCode(ctx context.Context, code string) error

func (Store) DeleteClient

func (s Store) DeleteClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (Store) DeleteClientAuthorizations

func (s Store) DeleteClientAuthorizations(ctx context.Context, clientIDs *ttnpb.ClientIdentifiers) error

func (Store) DeleteEndDevice

func (s Store) DeleteEndDevice(ctx context.Context, id *ttnpb.EndDeviceIdentifiers) error

func (Store) DeleteEntityAPIKeys

func (s Store) DeleteEntityAPIKeys(ctx context.Context, entityID *ttnpb.EntityIdentifiers) error

func (Store) DeleteEntityContactInfo

func (s Store) DeleteEntityContactInfo(ctx context.Context, entityID ttnpb.IDStringer) error

func (Store) DeleteEntityMembers

func (s Store) DeleteEntityMembers(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers,
) error

func (Store) DeleteGateway

func (s Store) DeleteGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (Store) DeleteInvitation

func (s Store) DeleteInvitation(ctx context.Context, email string) error

func (Store) DeleteOrganization

func (s Store) DeleteOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error

func (Store) DeleteSession

func (s Store) DeleteSession(ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string) error

func (Store) DeleteUser

func (s Store) DeleteUser(ctx context.Context, id *ttnpb.UserIdentifiers) error

func (Store) DeleteUserAuthorizations

func (s Store) DeleteUserAuthorizations(ctx context.Context, userIDs *ttnpb.UserIdentifiers) error

func (Store) FindAPIKeys

func (s Store) FindAPIKeys(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers,
) ([]*ttnpb.APIKey, error)

func (Store) FindAccountMembershipChains

func (s Store) FindAccountMembershipChains(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string, entityIDs ...string,
) ([]*store.MembershipChain, error)

func (Store) FindActiveLoginTokens

func (s Store) FindActiveLoginTokens(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.LoginToken, error)

func (Store) FindApplications

func (s Store) FindApplications(
	ctx context.Context, ids []*ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Application, error)

func (Store) FindClients

func (s Store) FindClients(
	ctx context.Context, ids []*ttnpb.ClientIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Client, error)

func (Store) FindEndDevices

func (s Store) FindEndDevices(
	ctx context.Context, ids []*ttnpb.EndDeviceIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.EndDevice, error)

func (Store) FindGateways

func (s Store) FindGateways(
	ctx context.Context, ids []*ttnpb.GatewayIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Gateway, error)

func (Store) FindInvitations

func (s Store) FindInvitations(ctx context.Context) ([]*ttnpb.Invitation, error)

func (Store) FindMembers

func (s Store) FindMembers(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers,
) ([]*store.MemberByID, error)

func (Store) FindMemberships

func (s Store) FindMemberships(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityType string, includeIndirect bool,
) ([]*ttnpb.EntityIdentifiers, error)

func (Store) FindOrganizations

func (s Store) FindOrganizations(
	ctx context.Context, ids []*ttnpb.OrganizationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.Organization, error)

func (Store) FindSessions

func (s Store) FindSessions(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.UserSession, error)

func (Store) FindUsers

func (s Store) FindUsers(
	ctx context.Context, ids []*ttnpb.UserIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.User, error)

func (Store) GetAPIKey

func (s Store) GetAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, id string,
) (*ttnpb.APIKey, error)

func (Store) GetAPIKeyByID

func (s Store) GetAPIKeyByID(
	ctx context.Context, id string,
) (*ttnpb.EntityIdentifiers, *ttnpb.APIKey, error)

func (Store) GetAccessToken

func (s Store) GetAccessToken(ctx context.Context, id string) (*ttnpb.OAuthAccessToken, error)

func (Store) GetApplication

func (s Store) GetApplication(
	ctx context.Context, id *ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Application, error)

func (Store) GetAuthorization

func (s Store) GetAuthorization(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) (*ttnpb.OAuthClientAuthorization, error)

func (Store) GetAuthorizationCode

func (s Store) GetAuthorizationCode(ctx context.Context, code string) (*ttnpb.OAuthAuthorizationCode, error)

func (Store) GetClient

func (s Store) GetClient(
	ctx context.Context, id *ttnpb.ClientIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Client, error)

func (Store) GetContactInfo

func (s Store) GetContactInfo(
	ctx context.Context, entityID ttnpb.IDStringer,
) ([]*ttnpb.ContactInfo, error)

func (Store) GetEndDevice

func (s Store) GetEndDevice(
	ctx context.Context, id *ttnpb.EndDeviceIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.EndDevice, error)

func (Store) GetGateway

func (s Store) GetGateway(
	ctx context.Context, id *ttnpb.GatewayIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Gateway, error)

func (Store) GetInvitation

func (s Store) GetInvitation(ctx context.Context, token string) (*ttnpb.Invitation, error)

func (Store) GetMember

func (s Store) GetMember(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, entityID *ttnpb.EntityIdentifiers,
) (*ttnpb.Rights, error)

func (Store) GetOrganization

func (s Store) GetOrganization(
	ctx context.Context, id *ttnpb.OrganizationIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.Organization, error)

func (Store) GetSession

func (s Store) GetSession(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, sessionID string,
) (*ttnpb.UserSession, error)

func (Store) GetSessionByID

func (s Store) GetSessionByID(ctx context.Context, sessionID string) (*ttnpb.UserSession, error)

func (Store) GetUser

func (s Store) GetUser(
	ctx context.Context, id *ttnpb.UserIdentifiers, fieldMask store.FieldMask,
) (*ttnpb.User, error)

func (Store) GetUserByPrimaryEmailAddress

func (s Store) GetUserByPrimaryEmailAddress(
	ctx context.Context, primaryEmailAddress string, fieldMask store.FieldMask,
) (*ttnpb.User, error)

func (Store) IssueDevEUIForApplication

func (s Store) IssueDevEUIForApplication(
	ctx context.Context, id *ttnpb.ApplicationIdentifiers, applicationLimit int,
) (*types.EUI64, error)

func (Store) ListAccessTokens

func (s Store) ListAccessTokens(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers, clientIDs *ttnpb.ClientIdentifiers,
) ([]*ttnpb.OAuthAccessToken, error)

func (Store) ListAdmins

func (s Store) ListAdmins(
	ctx context.Context, fieldMask store.FieldMask,
) ([]*ttnpb.User, error)

func (Store) ListAuthorizations

func (s Store) ListAuthorizations(
	ctx context.Context, userIDs *ttnpb.UserIdentifiers,
) ([]*ttnpb.OAuthClientAuthorization, error)

func (Store) ListEndDevices

func (s Store) ListEndDevices(
	ctx context.Context, ids *ttnpb.ApplicationIdentifiers, fieldMask store.FieldMask,
) ([]*ttnpb.EndDevice, error)

func (Store) ListNotifications

func (s Store) ListNotifications(
	ctx context.Context, receiverIDs *ttnpb.UserIdentifiers, statuses []ttnpb.NotificationStatus,
) ([]*ttnpb.Notification, error)

func (Store) PurgeApplication

func (s Store) PurgeApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (Store) PurgeClient

func (s Store) PurgeClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (Store) PurgeGateway

func (s Store) PurgeGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (Store) PurgeOrganization

func (s Store) PurgeOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error

func (Store) PurgeUser

func (s Store) PurgeUser(ctx context.Context, id *ttnpb.UserIdentifiers) error

func (Store) RestoreApplication

func (s Store) RestoreApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers) error

func (Store) RestoreClient

func (s Store) RestoreClient(ctx context.Context, id *ttnpb.ClientIdentifiers) error

func (Store) RestoreGateway

func (s Store) RestoreGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) error

func (Store) RestoreOrganization

func (s Store) RestoreOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) error

func (Store) RestoreUser

func (s Store) RestoreUser(ctx context.Context, id *ttnpb.UserIdentifiers) error

func (Store) SearchAccounts added in v3.21.1

func (s Store) SearchAccounts(
	ctx context.Context, req *ttnpb.SearchAccountsRequest,
) ([]*ttnpb.OrganizationOrUserIdentifiers, error)

func (Store) SearchApplications

func (s Store) SearchApplications(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchApplicationsRequest,
) ([]*ttnpb.ApplicationIdentifiers, error)

func (Store) SearchClients

func (s Store) SearchClients(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchClientsRequest,
) ([]*ttnpb.ClientIdentifiers, error)

func (Store) SearchEndDevices

func (s Store) SearchEndDevices(
	ctx context.Context, req *ttnpb.SearchEndDevicesRequest,
) ([]*ttnpb.EndDeviceIdentifiers, error)

func (Store) SearchGateways

func (s Store) SearchGateways(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchGatewaysRequest,
) ([]*ttnpb.GatewayIdentifiers, error)

func (Store) SearchOrganizations

func (s Store) SearchOrganizations(
	ctx context.Context, accountID *ttnpb.OrganizationOrUserIdentifiers, req *ttnpb.SearchOrganizationsRequest,
) ([]*ttnpb.OrganizationIdentifiers, error)

func (Store) SearchUsers

func (s Store) SearchUsers(
	ctx context.Context, req *ttnpb.SearchUsersRequest,
) ([]*ttnpb.UserIdentifiers, error)

func (Store) SetContactInfo

func (s Store) SetContactInfo(
	ctx context.Context, entityID ttnpb.IDStringer, pbs []*ttnpb.ContactInfo,
) ([]*ttnpb.ContactInfo, error)

func (Store) SetInvitationAcceptedBy

func (s Store) SetInvitationAcceptedBy(
	ctx context.Context, token string, accepter *ttnpb.UserIdentifiers,
) error

func (Store) SetMember

func (s Store) SetMember(
	ctx context.Context,
	accountID *ttnpb.OrganizationOrUserIdentifiers,
	entityID *ttnpb.EntityIdentifiers,
	rights *ttnpb.Rights,
) error

func (*Store) Transact

func (s *Store) Transact(ctx context.Context, fc func(context.Context, store.Store) error) (err error)

Transact implements the store.TransactionalStore interface.

func (Store) UpdateAPIKey

func (s Store) UpdateAPIKey(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers, pb *ttnpb.APIKey, fieldMask store.FieldMask,
) (*ttnpb.APIKey, error)

func (Store) UpdateApplication

func (s Store) UpdateApplication(
	ctx context.Context, pb *ttnpb.Application, fieldMask store.FieldMask,
) (*ttnpb.Application, error)

func (Store) UpdateClient

func (s Store) UpdateClient(
	ctx context.Context, pb *ttnpb.Client, fieldMask store.FieldMask,
) (*ttnpb.Client, error)

func (Store) UpdateEndDevice

func (s Store) UpdateEndDevice(
	ctx context.Context, pb *ttnpb.EndDevice, fieldMask store.FieldMask,
) (*ttnpb.EndDevice, error)

func (Store) UpdateGateway

func (s Store) UpdateGateway(
	ctx context.Context, pb *ttnpb.Gateway, fieldMask store.FieldMask,
) (*ttnpb.Gateway, error)

func (Store) UpdateNotificationStatus

func (s Store) UpdateNotificationStatus(
	ctx context.Context,
	receiverIDs *ttnpb.UserIdentifiers,
	notificationIDs []string,
	status ttnpb.NotificationStatus,
) error

func (Store) UpdateOrganization

func (s Store) UpdateOrganization(
	ctx context.Context, pb *ttnpb.Organization, fieldMask store.FieldMask,
) (*ttnpb.Organization, error)

func (Store) UpdateUser

func (s Store) UpdateUser(
	ctx context.Context, pb *ttnpb.User, fieldMask store.FieldMask,
) (*ttnpb.User, error)

func (Store) Validate

func (s Store) Validate(ctx context.Context, validation *ttnpb.ContactInfoValidation) error

type UUID

type UUID struct {
	ID string `bun:"id,type:uuid,pk,notnull,default:gen_random_uuid()"`
}

UUID can be embedded in models that should have a UUID field.

type User

type User struct {
	bun.BaseModel `bun:"table:users,alias:usr,select:user_accounts"`

	Model
	SoftDelete

	Account EmbeddedAccount `bun:"embed:account_"`

	Name        string `bun:"name,nullzero"`
	Description string `bun:"description,nullzero"`

	Attributes []*Attribute `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	ContactInfo []*ContactInfo `bun:"rel:has-many,join:type=entity_type,join:id=entity_id,polymorphic"`

	PrimaryEmailAddress            string     `bun:"primary_email_address,notnull"`
	PrimaryEmailAddressValidatedAt *time.Time `bun:"primary_email_address_validated_at"`

	Password              string    `bun:"password,notnull"`
	PasswordUpdatedAt     time.Time `bun:"password_updated_at,notnull"`
	RequirePasswordUpdate bool      `bun:"require_password_update,notnull"`

	State            int    `bun:"state,notnull"`
	StateDescription string `bun:"state_description,nullzero"`

	Admin bool `bun:"admin,notnull"`

	TemporaryPassword          string     `bun:"temporary_password,nullzero"`
	TemporaryPasswordCreatedAt *time.Time `bun:"temporary_password_created_at"`
	TemporaryPasswordExpiresAt *time.Time `bun:"temporary_password_expires_at"`

	ProfilePictureID *string  `bun:"profile_picture_id"`
	ProfilePicture   *Picture `bun:"rel:belongs-to,join:profile_picture_id=id"`
}

User is the user model in the database.

func (*User) BeforeAppendModel

func (m *User) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

type UserSession

type UserSession struct {
	bun.BaseModel `bun:"table:user_sessions,alias:sess"`

	Model

	User   *User  `bun:"rel:belongs-to,join:user_id=id"`
	UserID string `bun:"user_id,notnull"`

	SessionSecret string `bun:"session_secret,nullzero"`

	ExpiresAt *time.Time `bun:"expires_at"`
}

UserSession is the user session model in the database.

func (*UserSession) BeforeAppendModel

func (m *UserSession) BeforeAppendModel(ctx context.Context, query bun.Query) error

BeforeAppendModel is a hook that modifies the model on SELECT and UPDATE queries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL