Documentation
¶
Index ¶
- Constants
- Variables
- func GetNamed(p NamedPreparer, dest interface{}, query string, arg interface{}) error
- func GetNamedContext(ctx context.Context, p NamedPreparerContext, dest interface{}, query string, ...) error
- func InfiniteRange() pgtype.Tstzrange
- func Migrate(db *sql.DB) error
- func MustTimestamp(from interface{}) pgtype.Timestamptz
- func NewDBx(db *sql.DB) *sqlx.DB
- func Open(dataSourceName string) (*sql.DB, error)
- func Openx(dataSourceName string) (*sqlx.DB, error)
- func Pending(db *sql.DB) ([]*migrator.Migration, error)
- func RunInTransaction(ctx context.Context, db *sqlx.DB, cb func(tx *sqlx.Tx) error) error
- func Seed(db *sql.DB) error
- func SeedQueries(db *sql.DB, queries []Query) error
- func SelectNamed(p sqlx.Ext, dest interface{}, query string, arg interface{}) error
- func SelectNamedContext(ctx context.Context, p sqlx.ExtContext, dest interface{}, query string, ...) error
- func Timerange(lower, upper pgtype.Timestamptz) pgtype.Tstzrange
- func Timestamp(from interface{}) (pgtype.Timestamptz, error)
- type Category
- type DateTime
- type Discount
- type Fact
- type Model
- type NamedPreparer
- type NamedPreparerContext
- type Product
- type Query
- type Tenant
Constants ¶
const PGTimestampFormat = "2006-01-02 15:04:05-07"
PGTimestampFormat is the string representation of PostgreSQL's `timestamptz`.
Variables ¶
var DefaultQueries = []Query{ { Name: "appuio_cloud_memory", Description: "Memory usage (maximum of requested and used memory) aggregated by namespace", Query: appuioCloudMemoryQuery, Unit: "MiB", // contains filtered or unexported fields }, { Name: "appuio_cloud_loadbalancer", Description: "Number of services of type load balancer", Query: appuioCloudLoadbalancerQuery, }, { Name: "appuio_cloud_persistent_storage", Description: "Persistent storage usage aggregated by namespace and storageclass", Query: appuioCloudPersistentStorageQuery, Unit: "GiB", }, { Name: "appuio_managed_openshift_vcpu", Description: "vCPU aggregated by cluster, node (app, storage), and service level", Query: appuioManagedOpenShiftvCPUQuery, Unit: "vCPU", }, { Name: "appuio_managed_openshift_clusters", Description: "Cluster base fee", Query: appuioManagedOpenShiftClusterQuery, Unit: "Clusters", }, { Name: "appuio_managed_kubernetes_vcpu", Description: "vCPU aggregated by cluster, node (app, storage), and service level", Query: appuioManagedKubernetesvCPUQuery, Unit: "vCPU", }, { Name: "appcat_services", Description: "AppCat service instances query", Query: appcatQuery, Unit: "instances", }, }
DefaultQueries consists of default starter queries.
var Migrations = func() []interface{} { m, err := loadMigrations() if err != nil { panic(fmt.Errorf("failed to load migrations: %w", err)) } return m }()
Migrations returns all registered migrations.
Functions ¶
func GetNamed ¶
func GetNamed(p NamedPreparer, dest interface{}, query string, arg interface{}) error
GetNamed is like sqlx.Get but for named statements.
func GetNamedContext ¶
func GetNamedContext(ctx context.Context, p NamedPreparerContext, dest interface{}, query string, arg interface{}) error
GetNamedContext is like sqlx.GetContext but for named statements.
func InfiniteRange ¶
InfiniteRange returns an infinite PostgreSQL timerange [-Inf,Inf).
func MustTimestamp ¶
func MustTimestamp(from interface{}) pgtype.Timestamptz
MustTimestamp creates a Postgres timestamp from the given value. Valid values are nil, pgtype.Infinity/pgtype.NegativeInfinity, and a time.Time object. Panics if given an unsupported type.
func RunInTransaction ¶
RunInTransaction runs the given cb func in a transaction. If the func returns an error, the transaction is rolled back, otherwise committed.
func Seed ¶
Seed seeds the database with "starter" data. Is idempotent and thus can be executed multiple times in one database.
func SelectNamed ¶
SelectNamed is like sqlx.Select but for named statements.
func SelectNamedContext ¶
func SelectNamedContext(ctx context.Context, p sqlx.ExtContext, dest interface{}, query string, arg interface{}) error
SelectNamedContext is like sqlx.SelectContext but for named statements.
func Timerange ¶
func Timerange(lower, upper pgtype.Timestamptz) pgtype.Tstzrange
Timerange creates a Postgres timerange from two Postgres timestamps with [lower,upper) bounds.
func Timestamp ¶
func Timestamp(from interface{}) (pgtype.Timestamptz, error)
Timestamp creates a Postgres timestamp from the given value. Valid values are nil, pgtype.Infinity/pgtype.NegativeInfinity, and a time.Time object.
Types ¶
type Category ¶
type Category struct { Id string // Source consists of the cluster id and namespace in the form of "zone:namespace". Source string Target sql.NullString }
func (Category) ForeignKeyName ¶ added in v0.10.0
type DateTime ¶
func BuildDateTime ¶
BuildDateTime builds a DateTime object from the given timestamp.
func (DateTime) ForeignKeyName ¶ added in v0.10.0
type Discount ¶
type Discount struct { Id string // Source is a string consisting of "query:zone:tenant:namespace:class" and can contain wildcards. // See package `sourcekey` for more information. Source string Discount float64 During pgtype.Tstzrange }
func CreateDiscount ¶ added in v0.5.0
func CreateDiscount(p NamedPreparer, in Discount) (Discount, error)
CreateDiscount creates the given discount
func (Discount) ForeignKeyName ¶ added in v0.10.0
type Fact ¶
type Fact struct { Id string DateTimeId string `db:"date_time_id"` QueryId string `db:"query_id"` TenantId string `db:"tenant_id"` CategoryId string `db:"category_id"` ProductId string `db:"product_id"` DiscountId string `db:"discount_id"` Quantity float64 }
func (Fact) ForeignKeyName ¶ added in v0.10.0
type NamedPreparer ¶
NamedPreparer is an interface used by GetNamed.
type NamedPreparerContext ¶
type NamedPreparerContext interface {
PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
}
NamedPreparerContext is an interface used by GetNamedContext.
type Product ¶
type Product struct { Id string // Source is a string consisting of "query:zone:tenant:namespace:class" and can contain wildcards. // See package `sourcekey` for more information. Source string Target sql.NullString Amount float64 Unit string During pgtype.Tstzrange }
func CreateProduct ¶ added in v0.5.0
func CreateProduct(p NamedPreparer, in Product) (Product, error)
CreateProduct creates the given product
func (Product) ForeignKeyName ¶ added in v0.10.0
type Query ¶
type Query struct { Id string ParentID sql.NullString `db:"parent_id"` Name string Description string Query string Unit string During pgtype.Tstzrange // contains filtered or unexported fields }
func CreateQuery ¶ added in v0.5.0
func CreateQuery(p NamedPreparer, in Query) (Query, error)
CreateQuery creates the given query
func (Query) ForeignKeyName ¶ added in v0.10.0
type Tenant ¶
type Tenant struct { Id string // Source is the tenant string read from the 'appuio.io/organization' label. Source string Target sql.NullString During pgtype.Tstzrange }
func CreateTenant ¶ added in v0.11.0
func CreateTenant(p NamedPreparer, in Tenant) (Tenant, error)
CreateTenant creates the given tenant