dbutil

package
v0.0.0-...-0123b22 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 8

Documentation

Overview

Deprecated: Use storj.io/common/dbutil instead.

Index

Constants

This section is empty.

Variables

View Source
var ErrNullTime = errs.Class("null time")

ErrNullTime defines error class for NullTime.

Functions

func Configure

func Configure(ctx context.Context, db ConfigurableDB, dbName string, mon *monkit.Scope)

Configure Sets Connection Boundaries and adds db_stats monitoring to monkit.

func EscapableCommaSplit

func EscapableCommaSplit(val string) []string

EscapableCommaSplit is like strings.Split(x, ","), but if it sees two ','s in a row, it will treat them like one unsplit comma. So "hello,there,,friend" will result in ["hello", "there,friend"].

func ParseDBMapping

func ParseDBMapping(urlSpec string) (map[string]string, error)

ParseDBMapping parses a mapping of database connection URLs, preceded by the default URL. An example that overrides the repairqueue looks like: cockroach://user:pw@host/database,repairqueue:postgres://user:pw@host/database. The default is stored in "".

func SchemeForImplementation

func SchemeForImplementation(implementation Implementation) string

SchemeForImplementation returns the scheme that is used for URLs that use the given Implementation.

Types

type ConfigurableDB

type ConfigurableDB interface {
	SetMaxIdleConns(int)
	SetMaxOpenConns(int)
	SetConnMaxLifetime(time.Duration)
	Stats() sql.DBStats
}

ConfigurableDB contains methods for configuring a database.

type Implementation

type Implementation int

Implementation type of valid DBs.

const (
	// Unknown is an unknown db type.
	Unknown Implementation = iota
	// Postgres is a Postgresdb type.
	Postgres
	// Cockroach is a Cockroachdb type.
	Cockroach
	// Bolt is a Bolt kv store.
	Bolt
	// Redis is a Redis kv store.
	Redis
	// SQLite3 is a sqlite3 database.
	SQLite3
)

func ImplementationForScheme

func ImplementationForScheme(scheme string) Implementation

ImplementationForScheme returns the Implementation that is used for the url with the provided scheme.

func SplitConnStr

func SplitConnStr(s string) (driver string, source string, implementation Implementation, err error)

SplitConnStr returns the driver and DSN portions of a URL, along with the db implementation.

func (Implementation) AsOfSystemInterval

func (impl Implementation) AsOfSystemInterval(interval time.Duration) string

AsOfSystemInterval returns a SQL query for the specifying the AS OF SYSTEM TIME using a relative interval. The interval should be negative.

func (Implementation) AsOfSystemTime

func (impl Implementation) AsOfSystemTime(t time.Time) string

AsOfSystemTime returns a SQL query for the specifying the AS OF SYSTEM TIME using a concrete time.

func (Implementation) String

func (impl Implementation) String() string

String returns the default name for a given implementation.

func (Implementation) WrapAsOfSystemInterval

func (impl Implementation) WrapAsOfSystemInterval(sql string, interval time.Duration) string

WrapAsOfSystemInterval converts a query to include AS OF SYSTEM TIME using a relative interval. The interval should be negative.

func (Implementation) WrapAsOfSystemTime

func (impl Implementation) WrapAsOfSystemTime(sql string, t time.Time) string

WrapAsOfSystemTime converts a query to include AS OF SYSTEM TIME using a concrete time.

type NullTime

type NullTime struct {
	time.Time
	Valid bool
}

NullTime time helps convert nil to time.Time.

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type TempDatabase

type TempDatabase struct {
	tagsql.DB
	ConnStr        string
	Schema         string
	Driver         string
	Implementation Implementation
	Cleanup        func(tagsql.DB) error
}

TempDatabase is a database (or something that works like an isolated database, such as a PostgreSQL schema) with a semi-unique name which will be cleaned up when closed. Mainly useful for testing purposes.

func (*TempDatabase) Close

func (db *TempDatabase) Close() error

Close closes the database and deletes the schema.

Directories

Path Synopsis
Deprecated: Use storj.io/common/cockroachutil instead.
Deprecated: Use storj.io/common/cockroachutil instead.
Deprecated: Use storj.io/common/dbschema instead.
Deprecated: Use storj.io/common/dbschema instead.
Deprecated: Use storj.io/common/pgtest instead.
Deprecated: Use storj.io/common/pgtest instead.
Deprecated: Use storj.io/common/pgutil instead.
Deprecated: Use storj.io/common/pgutil instead.
pgerrcode
Deprecated: Use storj.io/common/pgerrcode instead.
Deprecated: Use storj.io/common/pgerrcode instead.
Deprecated: Use storj.io/common/pgxutil instead.
Deprecated: Use storj.io/common/pgxutil instead.
Deprecated: Use storj.io/common/sqliteutil instead.
Deprecated: Use storj.io/common/sqliteutil instead.
Deprecated: Use storj.io/common/tempdb instead.
Deprecated: Use storj.io/common/tempdb instead.
Deprecated: Use storj.io/common/txutil instead.
Deprecated: Use storj.io/common/txutil instead.
Deprecated: Use storj.io/common/utccheck instead.
Deprecated: Use storj.io/common/utccheck instead.

Jump to

Keyboard shortcuts

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