datastore

package
v0.0.0-...-f761163 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SERVICES_ENV = "VCAP_SERVICES"
	STRATOS_TAG  = "stratos"
	URI_POSTGRES = "postgres://"
	URI_MYSQL    = "mysql://"
	TAG_MYSQL    = "mysql"
	TAG_POSTGRES = "postgresql"
	DB_URI       = "uri"
)
View Source
const (
	// SQLite DB Provider
	SQLITE string = "sqlite"
	// PGSQL DB Provider
	PGSQL = "pgsql"
	// MYSQL DB Provider
	MYSQL = "mysql"

	// TimeoutBoundary is the max time in minutes to wait for the DB Schema to be initialized
	TimeoutBoundary = 10
)
View Source
const (
	// PGSQL SSL Modes
	// SSLDisabled means no checking of SSL
	SSLDisabled SSLValidationMode = "disable"
	// SSLRequired requires SSL without validation
	SSLRequired SSLValidationMode = "require"
	// SSLVerifyCA verifies the CA certificate
	SSLVerifyCA SSLValidationMode = "verify-ca"
	// SSLVerifyFull verifies the certificate and hostname and the CA
	SSLVerifyFull SSLValidationMode = "verify-full"
	// SQLiteSchemaFile - SQLite schema file
	SQLiteSchemaFile = "./deploy/db/sqlite_schema.sql"
	// SQLiteDatabaseFile - SQLite database file
	SQLiteDatabaseFile = "console-database.db"
	// DefaultDatabaseProvider is the efault database provider when not specified
	DefaultDatabaseProvider = MYSQL
)
View Source
const (
	// UniqueConstraintViolation is the error code for a unique constraint violation
	UniqueConstraintViolation = 23505

	// DefaultConnectionTimeout is the default to timeout on connections
	DefaultConnectionTimeout = 10
)

Variables

This section is empty.

Functions

func ApplyMigrations

func ApplyMigrations(conf *goose.DBConf, db *sql.DB) error

ApplyMigrations will perform the migrations

func GetConnection

func GetConnection(dc DatabaseConfig, env *env.VarSet) (*sql.DB, *goose.DBConf, error)

GetConnection returns a database connection to either MySQL, PostgreSQL or SQLite

func GetInMemorySQLLiteConnection

func GetInMemorySQLLiteConnection() (*sql.DB, *goose.DBConf, error)

GetInMemorySQLLiteConnection returns an SQLite DB Connection

func ModifySQLStatement

func ModifySQLStatement(sql string, databaseProvider string) string

ModifySQLStatement - Modify the given DB statement for the specified provider, as appropraite e.g Postgres uses $1, $2 etc SQLite uses ?

func NewGooseDBConf

func NewGooseDBConf(dc DatabaseConfig, env *env.VarSet) (*goose.DBConf, error)

NewGooseDBConf creates a new Goose config for database migrations

func ParseCFEnvs

func ParseCFEnvs(db *DatabaseConfig, env *env.VarSet) (bool, error)

Discover cf db services via their 'uri' env var and apply settings to the DatabaseConfig objects

func Ping

func Ping(db *sql.DB) error

Ping - ping the database to ensure the connection/pool works.

func RegisterMigration

func RegisterMigration(version int64, name string, f StratosMigration)

RegisterMigration registers a migration step. This should be called from an init() function

func SetMigrations

func SetMigrations(steps []StratosMigrationStep)

SetMigrations replces the current list of migrations - used only by tests internally

func WaitForMigrations

func WaitForMigrations(db *sql.DB) error

WaitForMigrations will wait until all migrations have been applied

Types

type DatabaseConfig

type DatabaseConfig struct {
	DatabaseProvider        string `configName:"DATABASE_PROVIDER"`
	Username                string `configName:"DB_USER"`
	Password                string `configName:"DB_PASSWORD"`
	Database                string `configName:"DB_DATABASE_NAME"`
	Host                    string `configName:"DB_HOST"`
	Port                    int    `configName:"DB_PORT"`
	SSLMode                 string `configName:"DB_SSL_MODE"`
	ConnectionTimeoutInSecs int    `configName:"DB_CONNECT_TIMEOUT_IN_SECS"`
	SSLCertificate          string `configName:"DB_CERT"`
	SSLKey                  string `configName:"DB_CERT_KEY"`
	SSLRootCertificate      string `configName:"DB_ROOT_CERT"`
}

DatabaseConfig represents the connection configuration parameters

func NewDatabaseConnectionParametersFromConfig

func NewDatabaseConnectionParametersFromConfig(dc DatabaseConfig) (DatabaseConfig, error)

NewDatabaseConnectionParametersFromConfig setup database connection parameters based on contents of config struct

type SSLValidationMode

type SSLValidationMode string

SSLValidationMode is the PostgreSQL driver SSL validation modes

type StratosMigration

type StratosMigration func(txn *sql.Tx, conf *goose.DBConf) error

StratosMigration applies a migration step. Use with RegisterMigration()

type StratosMigrationStep

type StratosMigrationStep struct {
	Version int64
	Name    string
	Apply   StratosMigration
}

StratosMigrationStep represents a migaration step

func GetOrderedMigrations

func GetOrderedMigrations() []StratosMigrationStep

GetOrderedMigrations returns an order list of migrations to run

type VCAPService

type VCAPService struct {
	Credentials map[string]interface{} `json:"credentials"`
	Tags        []string               `json:"tags"`
	Name        string                 `json:"name"`
}

Jump to

Keyboard shortcuts

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