database

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CREATE_TABLE_ADVISORY = 3141592653589793
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppDb

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

func GetDb

func GetDb(name string, cfg *config.DBConfig, tables DbTables) (*AppDb, error)

func NewAppDb

func NewAppDb(name string, tables DbTables) (adb *AppDb)

func (*AppDb) Close

func (adb *AppDb) Close() error

func (*AppDb) Conn

func (adb *AppDb) Conn() *DbConnection

func (*AppDb) Connect

func (adb *AppDb) Connect() (err error)

func (*AppDb) EnsureTablesExist

func (adb *AppDb) EnsureTablesExist() (err error)

func (*AppDb) Init

func (adb *AppDb) Init(name string, tables DbTables)

func (*AppDb) Name

func (adb *AppDb) Name() string

func (*AppDb) Ping

func (adb *AppDb) Ping() error

func (*AppDb) Setup

func (adb *AppDb) Setup(dbcfg *config.DBConfig) error

func (*AppDb) String

func (adb *AppDb) String() string

type ClientsRow

type ClientsRow struct {
	// include common table row fields
	TableRowCommon

	Id               int64  `json:"id"`
	ClientId         string `json:"clientId"`
	SystemUUID       string `json:"systemUUID"`
	ClientTimestamp  string `json:"clientTimestamp"`
	RegistrationDate string `json:"registrationDate"`
	AuthToken        string `json:"authToken"`
}

func (*ClientsRow) ClientIdExists

func (c *ClientsRow) ClientIdExists() bool

func (*ClientsRow) Delete

func (c *ClientsRow) Delete() (err error)

func (*ClientsRow) Exists

func (c *ClientsRow) Exists() bool

func (*ClientsRow) GetClientRegistration

func (c *ClientsRow) GetClientRegistration() *types.ClientRegistration

func (*ClientsRow) InitAuthentication

func (c *ClientsRow) InitAuthentication(caReq *restapi.ClientAuthenticationRequest)

func (*ClientsRow) InitClientId

func (c *ClientsRow) InitClientId(crReq *restapi.ClientRegistrationRequest)

func (*ClientsRow) InitClientRegistration

func (c *ClientsRow) InitClientRegistration(reg *types.ClientRegistration)

func (*ClientsRow) InitRegistration

func (c *ClientsRow) InitRegistration(crReq *restapi.ClientRegistrationRequest)

func (*ClientsRow) InitRegistrationId

func (c *ClientsRow) InitRegistrationId(registrationId int64)

func (*ClientsRow) Insert

func (c *ClientsRow) Insert() (err error)

func (*ClientsRow) RegistrationExists

func (c *ClientsRow) RegistrationExists() bool

func (*ClientsRow) RowId

func (c *ClientsRow) RowId() int64

func (*ClientsRow) SetupDB

func (c *ClientsRow) SetupDB(adb *AppDb) (err error)

func (*ClientsRow) String

func (c *ClientsRow) String() string

func (*ClientsRow) TableName

func (c *ClientsRow) TableName() string

func (*ClientsRow) Update

func (c *ClientsRow) Update() (err error)

type CustomersRow

type CustomersRow struct {
	// include common table row fields
	TableRowCommon

	Id         int64  `json:"id"`
	CustomerId string `json:"customerId"`
	Deleted    bool   `json:"deleted"`
	DeletedAt  string `json:"deletedAt"`
}

func (*CustomersRow) Delete

func (r *CustomersRow) Delete() (err error)

func (*CustomersRow) Exists

func (r *CustomersRow) Exists() bool

func (*CustomersRow) IdExists

func (r *CustomersRow) IdExists() bool

func (*CustomersRow) Init

func (r *CustomersRow) Init(customerId string)

func (*CustomersRow) Insert

func (r *CustomersRow) Insert() (err error)

func (*CustomersRow) RowId

func (r *CustomersRow) RowId() int64

func (*CustomersRow) SetupDB

func (r *CustomersRow) SetupDB(adb *AppDb) (err error)

func (*CustomersRow) String

func (r *CustomersRow) String() string

func (*CustomersRow) TableName

func (r *CustomersRow) TableName() string

func (*CustomersRow) Update

func (r *CustomersRow) Update() (err error)

type DbConnection

type DbConnection struct {
	Placeholder dialect.PlaceholderGenerator
	// contains filtered or unexported fields
}

DbConnection is a struct tracking a DB connection and associated DB settings

func (*DbConnection) AcquireAdvisoryLock

func (d *DbConnection) AcquireAdvisoryLock(lockId int64, tx *sql.Tx, shared bool) (err error)

func (*DbConnection) AcquireAdvisoryLockPostgres

func (d *DbConnection) AcquireAdvisoryLockPostgres(lockId int64, tx *sql.Tx, shared bool) (err error)

func (*DbConnection) CheckTableExists

func (d *DbConnection) CheckTableExists(table *TableSpec) (bool, error)

func (DbConnection) Close

func (d DbConnection) Close() (err error)

func (*DbConnection) Connect

func (d *DbConnection) Connect() (err error)

func (*DbConnection) CreateTableFromSpec

func (d *DbConnection) CreateTableFromSpec(table *TableSpec) (err error)

func (*DbConnection) DB

func (d *DbConnection) DB() *sql.DB

func (DbConnection) DbMgr

func (d DbConnection) DbMgr() dbmanager.DbManager

func (*DbConnection) EnsureTableSpecsExist

func (d *DbConnection) EnsureTableSpecsExist(tables []*TableSpec) (err error)

func (DbConnection) Name

func (d DbConnection) Name() string

func (*DbConnection) Ping

func (d *DbConnection) Ping() (err error)

func (*DbConnection) ReleaseAdvisdoryLock

func (d *DbConnection) ReleaseAdvisdoryLock(lockId int64, tx *sql.Tx, shared bool) (err error)

func (*DbConnection) ReleaseAdvisoryLockPostgres

func (d *DbConnection) ReleaseAdvisoryLockPostgres(lockId int64, tx *sql.Tx, shared bool) (err error)

func (*DbConnection) Setup

func (d *DbConnection) Setup(name string, dbcfg *config.DBConfig) error

func (DbConnection) String

func (d DbConnection) String() string

type DbTables

type DbTables []*TableSpec

func (DbTables) String

func (dts DbTables) String() string

type ReportStagingTableRow

type ReportStagingTableRow struct {
	TableRowCommon

	Id          int64  `json:"id"`
	ClientId    string `json:"clientId"`
	ReportId    string `json:"reportId"`
	Data        any    `json:"data"`
	ReceivedAt  string `json:"receivedAt"`
	Allocated   bool   `json:"allocated"`
	AllocatedAt string `json:"allocatedAt"`
}

func (*ReportStagingTableRow) Delete

func (r *ReportStagingTableRow) Delete() (err error)

func (*ReportStagingTableRow) Exists

func (r *ReportStagingTableRow) Exists() bool

func (*ReportStagingTableRow) FirstUnallocated

func (r *ReportStagingTableRow) FirstUnallocated() bool

func (*ReportStagingTableRow) Init

func (r *ReportStagingTableRow) Init(clientId, reportId string, data any)

func (*ReportStagingTableRow) Insert

func (r *ReportStagingTableRow) Insert() (stagingId int64, err error)

func (*ReportStagingTableRow) ReportIdentifer

func (r *ReportStagingTableRow) ReportIdentifer() string

func (*ReportStagingTableRow) SetupDB

func (r *ReportStagingTableRow) SetupDB(adb *AppDb) error

type SelectOpts

type SelectOpts struct {
	Count      bool
	Distinct   bool
	Limit      uint
	OrderBy    string
	Descending bool
}

type TableRowCommon

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

func (*TableRowCommon) ColumnName

func (t *TableRowCommon) ColumnName(ind int) string

func (*TableRowCommon) Columns

func (t *TableRowCommon) Columns(inputColumns ...string) (columns []string, err error)

func (*TableRowCommon) DB

func (t *TableRowCommon) DB() *sql.DB

func (*TableRowCommon) DeleteStmt

func (t *TableRowCommon) DeleteStmt(whereCols []string) (stmt string, err error)

func (*TableRowCommon) GetTableSpec

func (t *TableRowCommon) GetTableSpec() *TableSpec

func (*TableRowCommon) InsertStmt

func (t *TableRowCommon) InsertStmt(insertCols []string, returning string) (stmt string, err error)

func (*TableRowCommon) SelectStmt

func (t *TableRowCommon) SelectStmt(selectCols, whereCols []string, opts SelectOpts) (stmt string, err error)

func (*TableRowCommon) SetTableSpec

func (t *TableRowCommon) SetTableSpec(ts *TableSpec)

func (*TableRowCommon) SetupDB

func (t *TableRowCommon) SetupDB(adb *AppDb) (err error)

func (*TableRowCommon) TableName

func (t *TableRowCommon) TableName() string

func (*TableRowCommon) UpdateStmt

func (t *TableRowCommon) UpdateStmt(updateCols, whereCols []string) (stmt string, err error)

type TableRowHandler

type TableRowHandler interface {
	// Set the associated TableSpec
	SetTableSpec(ts *TableSpec)

	// Get the associated TableSpec
	GetTableSpec() *TableSpec

	// Setup DB access
	SetupDB(*AppDb) error

	// Retrieve the TableName
	TableName() string

	// Retrieve the RowId
	RowId() int64

	// Return string representation of the row
	String() string

	// Check if the row exists in the DB, and if so populate it
	Exists() bool

	// Insert row into the table
	Insert() error

	// Update row in the table
	Update() error

	// Delete row from the table
	Delete() error
}

type TableSpec

type TableSpec struct {
	Name        string
	Columns     []TableSpecColumn
	ForeignKeys []TableSpecForeignKey
	Extras      []string
}

func GetClientsTableSpec

func GetClientsTableSpec() *TableSpec

func GetCustomersTableSpec

func GetCustomersTableSpec() *TableSpec

func GetReportsStagingTableSpec

func GetReportsStagingTableSpec() *TableSpec

func GetTagSetsTableSpec

func GetTagSetsTableSpec() *TableSpec

func GetTelemetryTableSpec

func GetTelemetryTableSpec() *TableSpec

func (*TableSpec) CheckColumnNames

func (ts *TableSpec) CheckColumnNames(colNames []string) (err error)

func (*TableSpec) ColumnName

func (ts *TableSpec) ColumnName(ind int) (name string, err error)

func (*TableSpec) CreateCmd

func (ts *TableSpec) CreateCmd(db *DbConnection) (string, error)

type TableSpecColumn

type TableSpecColumn struct {
	Name       string
	Type       string
	Nullable   bool
	Default    string
	PrimaryKey bool
	Identity   bool
	Unique     bool
}

func (*TableSpecColumn) Create

func (c *TableSpecColumn) Create(db *DbConnection) string

type TableSpecForeignKey

type TableSpecForeignKey struct {
	Name             string
	Column           string
	ReferencedTable  string
	ReferencedColumn string
}

func (*TableSpecForeignKey) Create

func (fk *TableSpecForeignKey) Create(db *DbConnection) string

type TagSetRow

type TagSetRow struct {
	TableRowCommon

	Id     int64  `json:"id"`
	TagSet string `json:"tagSet"`
}

func (*TagSetRow) Delete

func (t *TagSetRow) Delete() (err error)

func (*TagSetRow) Exists

func (t *TagSetRow) Exists() bool

func (*TagSetRow) Init

func (t *TagSetRow) Init(tagSet string)

func (*TagSetRow) Insert

func (t *TagSetRow) Insert() (err error)

func (*TagSetRow) RowId

func (t *TagSetRow) RowId() int64

func (*TagSetRow) SetupDB

func (t *TagSetRow) SetupDB(adb *AppDb) error

func (*TagSetRow) String

func (t *TagSetRow) String() string

func (*TagSetRow) Update

func (t *TagSetRow) Update() (err error)

type TelemetryDataRow

type TelemetryDataRow struct {
	TableRowCommon

	// public table fields
	Id            int64  `json:"id"`
	ClientId      string `json:"clientId"`
	CustomerRefId int64  `json:"customerRefId"`
	TelemetryId   string `json:"telemetryId"`
	TelemetryType string `json:"telemetryType"`
	Timestamp     string `json:"timestamp"`
	TagSetId      int64  `json:"tagSetId"`
	DataItem      []byte `json:"dataItem"`
}

func (*TelemetryDataRow) Delete

func (t *TelemetryDataRow) Delete() (err error)

func (*TelemetryDataRow) Exists

func (t *TelemetryDataRow) Exists() bool

func (*TelemetryDataRow) Init

func (t *TelemetryDataRow) Init(
	dItm *telemetrylib.TelemetryDataItem,
	bHdr *telemetrylib.TelemetryBundleHeader,
	tagSetId int64,
	customerRefId int64,
) (err error)

func (*TelemetryDataRow) Insert

func (t *TelemetryDataRow) Insert() (err error)

func (*TelemetryDataRow) RowId

func (t *TelemetryDataRow) RowId() int64

func (*TelemetryDataRow) SetupDB

func (t *TelemetryDataRow) SetupDB(adb *AppDb) (err error)

func (*TelemetryDataRow) String

func (t *TelemetryDataRow) String() string

func (*TelemetryDataRow) TableName

func (t *TelemetryDataRow) TableName() string

func (*TelemetryDataRow) Update

func (t *TelemetryDataRow) Update() (err error)

type TelemetryDataRowHandler

type TelemetryDataRowHandler interface {
	// TelemetryDataRow is a superset of TableRow
	TableRowHandler

	// Initialise the row fields
	Init(
		dItm *telemetrylib.TelemetryDataItem,
		bHdr *telemetrylib.TelemetryBundleHeader,
		tagSetId int64,
		customerRefId int64,
	) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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