Documentation ¶
Overview ¶
Package sqlstore contains an SQL database backed storage implementation
Index ¶
- Constants
- func NewDownstreamStore(kg storage.SequenceStore, params Parameters, dcID uint8, workerID uint16) (storage.DownstreamStore, error)
- func NewMemoryAPNStore() storage.APNStore
- func NewMemoryStore() storage.DataStore
- func NewSQLAPNStore(driver string, connectionString string, create bool) (storage.APNStore, error)
- func NewSQLMutexStore(driver, connectionString string, create bool, dataCenterID uint8, ...) (storage.DataStore, error)
- func NewSQLStore(driver string, connectionString string, create bool, dataCenterID uint8, ...) (storage.DataStore, error)
- func NewSQLStoreWithConnection(db *sql.DB, dataCenterID uint8, workerID uint16) (storage.DataStore, error)
- func SQLAPNConnection(store storage.APNStore) *sql.DB
- func SQLConnection(store storage.DataStore) *sql.DB
- func SetInternalLookups(store storage.DataStore, newLookups InternalLookups) error
- type InternalLookups
- type Parameters
- type SQLCounterStore
- type Schema
Constants ¶
const DBAPNSchema = `` /* 1572-byte string literal not displayed */
DBAPNSchema is a big string with the DDL for the APN tables
const DBDataStoreSchema = `` /* 660-byte string literal not displayed */
DBDataStoreSchema is the data store schema
const DBSchema = `` /* 9091-byte string literal not displayed */
DBSchema is just a big schema string - this is split automagically into separate statements by the Statements function. Data types are converted on the fly for SQLite3
Variables ¶
This section is empty.
Functions ¶
func NewDownstreamStore ¶
func NewDownstreamStore(kg storage.SequenceStore, params Parameters, dcID uint8, workerID uint16) (storage.DownstreamStore, error)
NewDownstreamStore returns a new downstream message store. The SQL parameters are typically the same as for the regular backend store.
func NewMemoryAPNStore ¶
NewMemoryAPNStore returns a memory-based alloc store
func NewMemoryStore ¶
NewMemoryStore creates a memory-backed SQLite3 instance. Panics if the store can't be created. Use for testing
func NewSQLAPNStore ¶
NewSQLAPNStore creates a new APN store implementation
func NewSQLMutexStore ¶
func NewSQLMutexStore(driver, connectionString string, create bool, dataCenterID uint8, workerID uint16) (storage.DataStore, error)
NewSQLMutexStore wraps a SQL store instance in mutexes, particularly SQLLite3 needs this
func NewSQLStore ¶
func NewSQLStore(driver string, connectionString string, create bool, dataCenterID uint8, workerID uint16) (storage.DataStore, error)
NewSQLStore creates a new SequenceStore for a SQL backend
func NewSQLStoreWithConnection ¶
func NewSQLStoreWithConnection(db *sql.DB, dataCenterID uint8, workerID uint16) (storage.DataStore, error)
NewSQLStoreWithConnection creates a DataStore instance with an existing sql.DB connection.
func SQLAPNConnection ¶
SQLAPNConnection returns the internal *sql.DB connection used by the data store. This is not thread safe and the connection should be used with care. It will return nil if the store isn't a sql data store.
func SQLConnection ¶
SQLConnection returns the internal *sql.DB connection used by the data store. This is not thread safe and the connection should be used with care. It will return nil if the store isn't a sql data store.
func SetInternalLookups ¶
func SetInternalLookups(store storage.DataStore, newLookups InternalLookups) error
SetInternalLookups replaces the current utility lookups with another. This is not thread safe. Returns an error if the store isn't a SQL-backed data store.
Types ¶
type InternalLookups ¶
type InternalLookups interface { // Prepare the internal lookups for execution. Typically prepare sql // statements for execution Prepare(db *sql.DB) error // EnsureAdminOfTeam ensures that the user is an admin member of the team EnsureAdminOfTeam(tx *sql.Tx, userID model.UserKey, teamID model.TeamKey) error // EnsureAdminOfCollection ensures that the user is an admin of the team // that owns the collection EnsureAdminOfCollection(tx *sql.Tx, userID model.UserKey, collectionID model.CollectionKey) (model.TeamKey, error) // EnsureAdminOfDevice ensures that the user is an admin of the team that // owns the collection the device is a part of. EnsureAdminOfDevice(tx *sql.Tx, userID model.UserKey, collectionID model.CollectionKey, deviceID model.DeviceKey) error // EnsureAdminOfOutput ensures that the user is an admin of the team that // owns the collection that contains the output. EnsureAdminOfOutput(tx *sql.Tx, userID model.UserKey, collectionID model.CollectionKey, outputID model.OutputKey) error // EnsureNotPrivateTeam ensures that the team is not a private team EnsureNotPrivateTeam(tx *sql.Tx, teamID model.TeamKey) error // EsnureAdminOfFirmware ensures that the user is a member of a team that // owns the collection that the firmware is a part of. EnsureAdminOfFirmware(tx *sql.Tx, userID model.UserKey, fwID model.FirmwareKey) error // EnsureCollectionFirmware ensures that the collection contains the firmware EnsureCollectionFirmware(tx *sql.Tx, collectionID model.CollectionKey, fwID model.FirmwareKey) error }
InternalLookups is an interface for internal database lookups that are reads. When using a caching backend these lookups can be done in the cache rather than in the database itself. There are cases where there will be race conditions and integrity violations (f.e. if someone removes an admin from a team while the same member does a change on one of the resources the team owns) but this is an acceptable tradeoff.
func GetInternalLookups ¶
func GetInternalLookups(store storage.DataStore) InternalLookups
GetInternalLookups returns the current utility lookup implementation. This is not thread safe. Returns nil if the store isn't a SQL-backed data store
func NewInternalLookup ¶
func NewInternalLookup() InternalLookups
NewInternalLookup creates a SQL-backed utility lookup
type Parameters ¶
type Parameters struct { Type string `param:"desc=Database type;options=postgres,sqlite3;default=sqlite3"` ConnectionString string `param:"desc=Connection string for database;default=:memory:"` CreateSchema bool `param:"desc=Create database schema;default=true"` }
Parameters holds the configuration for the backend store
type SQLCounterStore ¶
type SQLCounterStore struct {
// contains filtered or unexported fields
}
SQLCounterStore is used to retrieve entity counts. The counts are read at creation.
func NewCounterStore ¶
func NewCounterStore(dbParams Parameters) (*SQLCounterStore, error)
NewCounterStore creates a CounterStore implemention
func (*SQLCounterStore) Collections ¶
func (s *SQLCounterStore) Collections() int64
Collections returns the current number of collections in the store
func (*SQLCounterStore) Devices ¶
func (s *SQLCounterStore) Devices() int64
Devices returns the current number of devices in the store
func (*SQLCounterStore) Outputs ¶
func (s *SQLCounterStore) Outputs() int64
Outputs returns the current number of outputs in the store
func (*SQLCounterStore) Teams ¶
func (s *SQLCounterStore) Teams() int64
Teams returns the current number of teams in the store
func (*SQLCounterStore) Users ¶
func (s *SQLCounterStore) Users() int64
Users returns the current number of users in the store
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema contains a database schema.
func (*Schema) Statements ¶
Statements returns an array of DDL statements