Documentation
¶
Index ¶
- Variables
- func AutoMigrate(db *gorm.DB) *gorm.DB
- func Check(db *gorm.DB) error
- func Clear(db *gorm.DB) error
- func GetAPIKeyStore(db *gorm.DB) store.APIKeyStore
- func GetApplicationStore(db *gorm.DB) store.ApplicationStore
- func GetClientStore(db *gorm.DB) store.ClientStore
- func GetContactInfoStore(db *gorm.DB) store.ContactInfoStore
- func GetEUIStore(db *gorm.DB) store.EUIStore
- func GetEndDeviceStore(db *gorm.DB) store.EndDeviceStore
- func GetEntitySearch(db *gorm.DB) store.EntitySearch
- func GetGatewayStore(db *gorm.DB) store.GatewayStore
- func GetInvitationStore(db *gorm.DB) store.InvitationStore
- func GetLoginTokenStore(db *gorm.DB) store.LoginTokenStore
- func GetMembershipCache(store store.MembershipStore, redis *redis.Client, ttl time.Duration) store.MembershipStore
- func GetMembershipStore(db *gorm.DB) store.MembershipStore
- func GetOAuthStore(db *gorm.DB) store.OAuthStore
- func GetOrganizationStore(db *gorm.DB) store.OrganizationStore
- func GetUserSessionStore(db *gorm.DB) store.UserSessionStore
- func GetUserStore(db *gorm.DB) store.UserStore
- func Initialize(db *gorm.DB) error
- func Open(ctx context.Context, dsn string) (*gorm.DB, error)
- func SetLogger(db *gorm.DB, log log.Interface)
- func Transact(ctx context.Context, db *gorm.DB, f func(db *gorm.DB) error) (err error)
- type APIKey
- type AccessToken
- type Account
- type Application
- type Attribute
- type AuthorizationCode
- type Client
- type ClientAuthorization
- type ContactInfo
- type ContactInfoValidation
- type EUI64
- type EUIBlock
- type EndDevice
- type EndDeviceLocation
- type Gateway
- type GatewayAntenna
- type Grants
- type Invitation
- type Location
- type LoginToken
- type Membership
- type Migration
- type MigrationStore
- type Model
- type Organization
- type Picture
- type Populator
- type Rights
- type SoftDelete
- type User
- type UserSession
Constants ¶
This section is empty.
Variables ¶
var ErrTransactionRecovered = errors.DefineInternal("transaction_recovered", "Internal Server Error")
ErrTransactionRecovered is returned when a panic is caught from a SQL transaction.
Functions ¶
func AutoMigrate ¶
AutoMigrate automatically migrates the database for the registered models.
func GetAPIKeyStore ¶
func GetAPIKeyStore(db *gorm.DB) store.APIKeyStore
GetAPIKeyStore returns an APIKeyStore on the given db (or transaction).
func GetApplicationStore ¶
func GetApplicationStore(db *gorm.DB) store.ApplicationStore
GetApplicationStore returns an ApplicationStore on the given db (or transaction).
func GetClientStore ¶
func GetClientStore(db *gorm.DB) store.ClientStore
GetClientStore returns an ClientStore on the given db (or transaction).
func GetContactInfoStore ¶
func GetContactInfoStore(db *gorm.DB) store.ContactInfoStore
GetContactInfoStore returns an ContactInfoStore on the given db (or transaction).
func GetEUIStore ¶
GetEUIStore returns an EUIStore on the given db (or transaction).
func GetEndDeviceStore ¶
func GetEndDeviceStore(db *gorm.DB) store.EndDeviceStore
GetEndDeviceStore returns an EndDeviceStore on the given db (or transaction).
func GetEntitySearch ¶
func GetEntitySearch(db *gorm.DB) store.EntitySearch
GetEntitySearch returns an EntitySearch on the given db (or transaction).
func GetGatewayStore ¶
func GetGatewayStore(db *gorm.DB) store.GatewayStore
GetGatewayStore returns an GatewayStore on the given db (or transaction).
func GetInvitationStore ¶
func GetInvitationStore(db *gorm.DB) store.InvitationStore
GetInvitationStore returns an InvitationStore on the given db (or transaction).
func GetLoginTokenStore ¶
func GetLoginTokenStore(db *gorm.DB) store.LoginTokenStore
GetLoginTokenStore returns an LoginTokenStore on the given db (or transaction).
func GetMembershipCache ¶
func GetMembershipCache(store store.MembershipStore, redis *redis.Client, ttl time.Duration) store.MembershipStore
GetMembershipCache wraps the MembershipStore with a cache. Make sure to not call FindIndirectMemberships or GetMember after calling SetMember in the same transaction, this may result in an inconsistent cache.
func GetMembershipStore ¶
func GetMembershipStore(db *gorm.DB) store.MembershipStore
GetMembershipStore returns an MembershipStore on the given db (or transaction).
func GetOAuthStore ¶
func GetOAuthStore(db *gorm.DB) store.OAuthStore
GetOAuthStore returns an OAuthStore on the given db (or transaction).
func GetOrganizationStore ¶
func GetOrganizationStore(db *gorm.DB) store.OrganizationStore
GetOrganizationStore returns an OrganizationStore on the given db (or transaction).
func GetUserSessionStore ¶
func GetUserSessionStore(db *gorm.DB) store.UserSessionStore
GetUserSessionStore returns an UserSessionStore on the given db (or transaction).
func GetUserStore ¶
GetUserStore returns an UserStore on the given db (or transaction).
Types ¶
type APIKey ¶
type APIKey struct { Model APIKeyID string `gorm:"type:VARCHAR;unique_index:api_key_id_index"` Key string `gorm:"type:VARCHAR"` Rights Rights `gorm:"type:INT ARRAY"` Name string `gorm:"type:VARCHAR"` EntityID string `gorm:"type:UUID;index:api_key_entity_index;not null"` EntityType string `gorm:"type:VARCHAR(32);index:api_key_entity_index;not null"` ExpiresAt *time.Time }
APIKey model.
type AccessToken ¶
type AccessToken struct { Model Client *Client ClientID string `gorm:"type:UUID;index;not null"` User *User UserID string `gorm:"type:UUID;index;not null"` UserSessionID *string `gorm:"type:UUID;index"` Rights Rights `gorm:"type:INT ARRAY"` TokenID string `gorm:"type:VARCHAR;unique_index:access_token_id_index;not null"` Previous *AccessToken `gorm:"foreignkey:PreviousID;association_foreignkey:TokenID"` PreviousID string `gorm:"type:VARCHAR;index:access_token_previous_index"` AccessToken string `gorm:"type:VARCHAR;not null"` RefreshToken string `gorm:"type:VARCHAR;not null"` ExpiresAt *time.Time }
AccessToken model.
type Account ¶
type Account struct { Model SoftDelete UID string `gorm:"type:VARCHAR(36);unique_index:account_uid_index"` AccountID string `gorm:"type:UUID;index:account_id_index;not null"` AccountType string `gorm:"type:VARCHAR(32);index:account_id_index;not null"` // user or organization Memberships []*Membership }
Account model.
func (Account) OrganizationOrUserIdentifiers ¶
func (a Account) OrganizationOrUserIdentifiers() *ttnpb.OrganizationOrUserIdentifiers
OrganizationOrUserIdentifiers for the account, depending on its type.
type Application ¶
type Application struct { Model SoftDelete // BEGIN common fields ApplicationID string `gorm:"unique_index:application_id_index;type:VARCHAR(36);not null"` Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:application"` APIKeys []APIKey `gorm:"polymorphic:Entity;polymorphic_value:application"` Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:application"` AdministrativeContactID *string `gorm:"type:UUID;index"` AdministrativeContact *Account `gorm:"save_associations:false"` TechnicalContactID *string `gorm:"type:UUID;index"` TechnicalContact *Account `gorm:"save_associations:false"` DevEUICounter int `gorm:"<-:create;type:INT;default:'0';column:dev_eui_counter"` }
Application model.
type Attribute ¶
type Attribute struct { ID string `gorm:"type:UUID;primary_key;default:gen_random_uuid()"` EntityID string `gorm:"type:UUID;index:attribute_entity_index;not null"` EntityType string `gorm:"type:VARCHAR(32);index:attribute_entity_index;not null"` Key string `gorm:"type:VARCHAR"` Value string `gorm:"type:VARCHAR"` }
Attribute model.
type AuthorizationCode ¶
type AuthorizationCode struct { Model Client *Client ClientID string `gorm:"type:UUID;index;not null"` User *User UserID string `gorm:"type:UUID;index;not null"` UserSessionID *string `gorm:"type:UUID;index"` Rights Rights `gorm:"type:INT ARRAY"` Code string `gorm:"type:VARCHAR;unique_index:authorization_code_code_index;not null"` RedirectURI string `gorm:"type:VARCHAR;column:redirect_uri"` State string `gorm:"type:VARCHAR"` ExpiresAt *time.Time }
AuthorizationCode model.
type Client ¶
type Client struct { Model SoftDelete // BEGIN common fields ClientID string `gorm:"unique_index:client_id_index;type:VARCHAR(36);not null"` Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:client"` Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:client"` AdministrativeContactID *string `gorm:"type:UUID;index"` AdministrativeContact *Account `gorm:"save_associations:false"` TechnicalContactID *string `gorm:"type:UUID;index"` TechnicalContact *Account `gorm:"save_associations:false"` ClientSecret string `gorm:"type:VARCHAR"` RedirectURIs pq.StringArray `gorm:"type:VARCHAR ARRAY;column:redirect_uris"` LogoutRedirectURIs pq.StringArray `gorm:"type:VARCHAR ARRAY;column:logout_redirect_uris"` State int `gorm:"not null"` StateDescription string `gorm:"type:VARCHAR"` SkipAuthorization bool `gorm:"not null"` Endorsed bool `gorm:"not null"` Grants Grants `gorm:"type:INT ARRAY"` Rights Rights `gorm:"type:INT ARRAY"` }
Client model.
type ClientAuthorization ¶
type ClientAuthorization struct { Model Client *Client ClientID string `gorm:"type:UUID;index;not null"` User *User UserID string `gorm:"type:UUID;index;not null"` Rights Rights `gorm:"type:INT ARRAY"` }
ClientAuthorization model. Is also embedded by other OAuth models.
type ContactInfo ¶
type ContactInfo struct { ID string `gorm:"type:UUID;primary_key;default:gen_random_uuid()"` ContactType int `gorm:"not null"` ContactMethod int `gorm:"not null"` Value string `gorm:"type:VARCHAR"` Public bool ValidatedAt *time.Time EntityID string `gorm:"type:UUID;index:contact_info_entity_index;not null"` EntityType string `gorm:"type:VARCHAR(32);index:contact_info_entity_index;not null"` }
ContactInfo model.
type ContactInfoValidation ¶
type ContactInfoValidation struct { Model Reference string `gorm:"type:VARCHAR;index:contact_info_validation_id_index"` Token string `gorm:"type:VARCHAR;index:contact_info_validation_id_index"` EntityID string `gorm:"type:UUID;index:contact_info_validation_entity_index;not null"` EntityType string `gorm:"type:VARCHAR(32);index:contact_info_validation_entity_index;not null"` ContactMethod int `gorm:"not null"` Value string `gorm:"type:VARCHAR"` Used bool ExpiresAt *time.Time }
ContactInfoValidation model.
type EUI64 ¶
EUI64 adds methods on a types.EUI64 so that it can be stored in an SQL database.
type EUIBlock ¶
type EUIBlock struct { Model Type string `gorm:"type:VARCHAR(10);"` StartEUI EUI64 `gorm:"type:VARCHAR(16);column:start_eui"` MaxCounter int64 `gorm:"type:BIGINT;column:end_counter"` CurrentCounter int64 `gorm:"type:BIGINT;column:current_counter"` }
EUIBlock is the model for a block of EUIs.
type EndDevice ¶
type EndDevice struct { Model ApplicationID string `gorm:"unique_index:end_device_id_index;type:VARCHAR(36);not null;index:end_device_application_index"` Application *Application // BEGIN common fields DeviceID string `gorm:"unique_index:end_device_id_index;type:VARCHAR(36);not null"` Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:device"` JoinEUI *EUI64 `gorm:"unique_index:end_device_eui_index;index:end_device_join_eui_index;type:VARCHAR(16);column:join_eui"` DevEUI *EUI64 `gorm:"unique_index:end_device_eui_index;index:end_device_dev_eui_index;type:VARCHAR(16);column:dev_eui"` BrandID string `gorm:"type:VARCHAR"` ModelID string `gorm:"type:VARCHAR"` HardwareVersion string `gorm:"type:VARCHAR"` FirmwareVersion string `gorm:"type:VARCHAR"` BandID string `gorm:"type:VARCHAR"` NetworkServerAddress string `gorm:"type:VARCHAR"` ApplicationServerAddress string `gorm:"type:VARCHAR"` JoinServerAddress string `gorm:"type:VARCHAR"` ServiceProfileID string `gorm:"type:VARCHAR"` Locations []EndDeviceLocation Picture *Picture PictureID *string `gorm:"type:UUID;index:end_device_picture_index"` ActivatedAt *time.Time `gorm:"default:null"` }
EndDevice model.
type EndDeviceLocation ¶
type EndDeviceLocation struct { Model EndDeviceID string `gorm:"type:UUID;unique_index:end_device_location_id_index;index:end_device_device_index;not null"` Service string `gorm:"unique_index:end_device_location_id_index"` Location Source int `gorm:"not null"` }
EndDeviceLocation model.
type Gateway ¶
type Gateway struct { Model SoftDelete GatewayEUI *EUI64 `gorm:"unique_index:gateway_eui_index;type:VARCHAR(16);column:gateway_eui"` // BEGIN common fields GatewayID string `gorm:"unique_index:gateway_id_index;type:VARCHAR(36);not null"` Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:gateway"` APIKeys []APIKey `gorm:"polymorphic:Entity;polymorphic_value:gateway"` Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:gateway"` AdministrativeContactID *string `gorm:"type:UUID;index"` AdministrativeContact *Account `gorm:"save_associations:false"` TechnicalContactID *string `gorm:"type:UUID;index"` TechnicalContact *Account `gorm:"save_associations:false"` BrandID string `gorm:"type:VARCHAR"` ModelID string `gorm:"type:VARCHAR"` HardwareVersion string `gorm:"type:VARCHAR"` FirmwareVersion string `gorm:"type:VARCHAR"` GatewayServerAddress string `gorm:"type:VARCHAR"` AutoUpdate bool `gorm:"not null"` UpdateChannel string `gorm:"type:VARCHAR"` // Frequency Plan IDs separated by spaces. FrequencyPlanID string `gorm:"type:VARCHAR"` StatusPublic bool `gorm:"not null"` LocationPublic bool `gorm:"not null"` ScheduleDownlinkLate bool `gorm:"not null"` EnforceDutyCycle bool `gorm:"not null"` ScheduleAnytimeDelay int64 `gorm:"default:0 not null"` DownlinkPathConstraint int UpdateLocationFromStatus bool `gorm:"default:false not null"` Antennas []GatewayAntenna LBSLNSSecret []byte `gorm:"type:BYTEA;column:lbs_lns_secret"` ClaimAuthenticationCodeSecret []byte `gorm:"type:BYTEA"` ClaimAuthenticationCodeValidFrom *time.Time ClaimAuthenticationCodeValidTo *time.Time TargetCUPSURI string `gorm:"type:VARCHAR"` TargetCUPSKey []byte `gorm:"type:BYTEA"` RequireAuthenticatedConnection bool SupportsLRFHSS bool `gorm:"default:false not null"` DisablePacketBrokerForwarding bool `gorm:"default:false not null"` }
Gateway model.
type GatewayAntenna ¶
type GatewayAntenna struct { Model Gateway *Gateway GatewayID string `gorm:"type:UUID;unique_index:gateway_antenna_id_index;index:gateway_antenna_gateway_index;not null"` Index int `gorm:"unique_index:gateway_antenna_id_index;not null"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:gateway"` Gain float32 Location Placement int }
GatewayAntenna model.
type Grants ¶
Grants adds methods on a []ttnpb.GrantType so that it can be stored in an SQL database.
type Invitation ¶
type Invitation struct { Model Email string `gorm:"type:VARCHAR;unique_index:invitation_email_index;not null"` Token string `gorm:"type:VARCHAR;unique_index:invitation_token_index;not null"` ExpiresAt *time.Time AcceptedBy *User AcceptedByID *string `gorm:"type:UUID"` AcceptedAt *time.Time }
Invitation model.
type LoginToken ¶
type LoginToken struct { Model User *User UserID string `gorm:"type:UUID"` Token string `gorm:"type:VARCHAR;unique_index:login_token_index;not null"` ExpiresAt *time.Time Used bool }
LoginToken model.
type Membership ¶
type Membership struct { Model Account *Account AccountID string `gorm:"type:UUID;index:membership_account_index;not null"` Rights Rights `gorm:"type:INT ARRAY"` EntityID string `gorm:"type:UUID;index:membership_entity_index;not null"` EntityType string `gorm:"type:VARCHAR(32);index:membership_entity_index;not null"` }
Membership model.
type MigrationStore ¶
type MigrationStore interface { CreateMigration(ctx context.Context, migration *Migration) error FindMigrations(ctx context.Context) ([]*Migration, error) GetMigration(ctx context.Context, id string) (*Migration, error) DeleteMigration(ctx context.Context, id string) error }
MigrationStore interface for migration history.
func GetMigrationStore ¶
func GetMigrationStore(db *gorm.DB) MigrationStore
GetMigrationStore returns a MigrationStore on the given db (or transaction).
type Model ¶
type Model struct { ID string `gorm:"type:UUID;primary_key;default:gen_random_uuid()"` CreatedAt time.Time `gorm:"not null"` UpdatedAt time.Time `gorm:"not null"` // contains filtered or unexported fields }
Model is the base of database models.
func (Model) PrimaryKey ¶
PrimaryKey returns the primary key of the model.
func (*Model) SetContext ¶
SetContext needs to be called before creating models.
type Organization ¶
type Organization struct { Model SoftDelete Account Account `gorm:"polymorphic:Account;polymorphic_value:organization"` // BEGIN common fields Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:organization"` APIKeys []APIKey `gorm:"polymorphic:Entity;polymorphic_value:organization"` Memberships []Membership `gorm:"polymorphic:Entity;polymorphic_value:organization"` AdministrativeContactID *string `gorm:"type:UUID;index"` AdministrativeContact *Account `gorm:"save_associations:false"` TechnicalContactID *string `gorm:"type:UUID;index"` TechnicalContact *Account `gorm:"save_associations:false"` }
Organization model.
func (*Organization) SetContext ¶
func (org *Organization) SetContext(ctx context.Context)
SetContext sets the context on the organization model and the embedded account model.
type Picture ¶
type Picture struct { Model SoftDelete // Filter on deleted_at not being NULL to clean up storage bucket. Data []byte `gorm:"type:BYTEA"` }
Picture model.
type Populator ¶
type Populator struct { Applications []*ttnpb.Application Clients []*ttnpb.Client Gateways []*ttnpb.Gateway Organizations []*ttnpb.Organization Users []*ttnpb.User EndDevices []*ttnpb.EndDevice APIKeys map[*ttnpb.EntityIdentifiers][]*ttnpb.APIKey Memberships map[*ttnpb.EntityIdentifiers][]*ttnpb.Collaborator }
Populator is intended to populate a database with test data.
func NewPopulator ¶
NewPopulator returns a new database populator with a population of the given size. It is seeded by the given seed.
type Rights ¶
Rights adds methods on a ttnpb.Rights so that it can be stored in an SQL database.
type SoftDelete ¶
SoftDelete makes a Delete operation set a DeletedAt instead of actually deleting the model.
type User ¶
type User struct { Model SoftDelete Account Account `gorm:"polymorphic:Account;polymorphic_value:user"` // BEGIN common fields Name string `gorm:"type:VARCHAR"` Description string `gorm:"type:TEXT"` Attributes []Attribute `gorm:"polymorphic:Entity;polymorphic_value:user"` APIKeys []APIKey `gorm:"polymorphic:Entity;polymorphic_value:user"` Sessions []*UserSession PrimaryEmailAddress string `gorm:"type:VARCHAR;not null;unique_index"` PrimaryEmailAddressValidatedAt *time.Time // should be cleared when email changes Password string `gorm:"type:VARCHAR;not null"` // this is the hash PasswordUpdatedAt time.Time `gorm:"not null"` RequirePasswordUpdate bool `gorm:"not null"` State int `gorm:"not null"` StateDescription string `gorm:"type:VARCHAR"` Admin bool `gorm:"not null"` TemporaryPassword string `gorm:"type:VARCHAR"` TemporaryPasswordCreatedAt *time.Time TemporaryPasswordExpiresAt *time.Time ProfilePicture *Picture ProfilePictureID *string `gorm:"type:UUID;index:user_profile_picture_index"` }
User model.
func (*User) SetContext ¶
SetContext sets the context on both the Model and Account.
Source Files
¶
- account.go
- api_key.go
- api_key_store.go
- application.go
- application_store.go
- attribute.go
- attribute_store.go
- client.go
- client_store.go
- contact_info.go
- contact_info_store.go
- contact_info_validation.go
- end_device.go
- end_device_location.go
- end_device_location_store.go
- end_device_store.go
- entity_search.go
- eui_block.go
- eui_block_store.go
- fieldmask_paths.go
- gateway.go
- gateway_antenna.go
- gateway_antenna_store.go
- gateway_store.go
- hooks.go
- invitation.go
- invitation_store.go
- login_token.go
- login_token_store.go
- membership.go
- membership_cache.go
- membership_store.go
- migration.go
- migration_store.go
- model.go
- model_context.go
- oauth.go
- oauth_store.go
- organization.go
- organization_store.go
- picture.go
- populate.go
- registry.go
- scope.go
- soft_delete.go
- store.go
- store_interfaces.go
- types.go
- user.go
- user_session.go
- user_session_store.go
- user_store.go