database

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package database provides a database abstraction layer for SQL and NoSQL databases.

Index

Constants

View Source
const (
	// DefaultMaxOpenConnections represents the default max open connections.
	DefaultMaxOpenConnections    = 5
	DefaultMaxIdleConnections    = 1
	DefaultMaxLifetimeConnection = 65 * time.Second
	DefaultMaxIdleTimeConnection = 15 * time.Second
)

Variables

View Source
var (
	DialectNames = map[Dialect]string{
		DialectGraphQL:    "graphql",
		DialectMysql:      "mysql",
		DialectPostgreSQL: "postgresql",
		DialectClickhouse: "clickhouse",
		DialectBigQuery:   "bigquery",
	}
)

Functions

This section is empty.

Types

type Column

type Column struct {
	Name          string     `json:"name"`
	Description   string     `json:"description"`
	Deprecated    string     `json:"deprecated"`
	Replacement   string     `json:"replacement"`
	Type          types.Type `json:"type"`
	NativeType    string     `json:"native_type"`
	Codec         string     `json:"codec"`
	Collation     string     `json:"collation"`
	Default       string     `json:"default"`
	Validation    string     `json:"validation"`
	Sensitive     bool       `json:"sensitive"`
	AutoIncrement bool       `json:"auto_increment"`
	Primary       bool       `json:"primary"`
	Index         bool       `json:"index"`
	Unique        bool       `json:"unique"`
	Nullable      bool       `json:"nullable"`
	Creatable     bool       `json:"creatable"`
	Updatable     bool       `json:"updatable"`
	Readable      bool       `json:"readable"`
}

Column defines a single Table field structure.

func NewColumn

func NewColumn(t types.Type, name, description, nativeType string) *Column

NewColumn creates a new Column instance

type Dialect

type Dialect uint8

Dialect represents the storage dialect.

const (
	DialectInvalid Dialect = iota + 1 //
	DialectGraphQL
	DialectMysql
	DialectPostgreSQL
	DialectClickhouse
	DialectBigQuery
)

func ParseDialect

func ParseDialect(value string) Dialect

ParseDialect parses the Dialect from string.

func (Dialect) MarshalJSON

func (d Dialect) MarshalJSON() ([]byte, error)

MarshalJSON outputs the Dialect as a json.

func (Dialect) String

func (d Dialect) String() string

String outputs the Dialect as a string.

func (*Dialect) UnmarshalJSON

func (d *Dialect) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the Dialect from json.

func (Dialect) Validate

func (d Dialect) Validate() bool

Validate returns true if the Dialect is valid.

type IKeyValue

type IKeyValue interface {
	// Get gets the value for the given key.
	// `nil, nil` is returned when the key does not exist
	Get(key string) ([]byte, error)

	// Set stores the given value for the given key along with an expiration value, 0 means no expiration.
	// Empty key or value will be ignored without an error.
	Set(key string, val []byte, exp time.Duration) error

	// Delete deletes the value for the given key.
	// It returns no error if the storage does not contain the key,
	Delete(key string) error

	// Reset resets the storage and delete all keys.
	Reset() error

	// Close closes the storage and will stop any running garbage collectors and open connections.
	Close() error
}

IKeyValue interface for communicating with different database/key-value providers

type Option

type Option func(o *Options)

Option represents the storage option.

func WithMaxIdleConnections

func WithMaxIdleConnections(value int) Option

WithMaxIdleConnections sets the max idle connections for the storage.

func WithMaxIdleTimeConnection

func WithMaxIdleTimeConnection(value time.Duration) Option

WithMaxIdleTimeConnection sets the max idle time connection for the storage.

func WithMaxLifetimeConnection

func WithMaxLifetimeConnection(value time.Duration) Option

WithMaxLifetimeConnection sets the max lifetime connection for the storage.

func WithMaxOpenConnections

func WithMaxOpenConnections(value int) Option

WithMaxOpenConnections sets the max open connections for the storage.

func WithOptions

func WithOptions(value types.Map[string]) Option

WithOptions sets the options for the storage.

func WithReplicasDsn added in v0.0.3

func WithReplicasDsn(value types.Map[types.URI]) Option

WithReplicasDsn sets the replicas dsn for the storage.

func WithSourcesDsn added in v0.0.3

func WithSourcesDsn(value types.Map[types.URI]) Option

WithSourcesDsn sets the sources dsn for the storage.

type Options

type Options struct {
	SourcesDsn            types.Map[types.URI] `json:"sources_dsn"              env:"SOURCES_DSN"`
	ReplicasDsn           types.Map[types.URI] `json:"replicas_dsn"             env:"REPLICAS_DSN"`
	MaxOpenConnections    int                  `json:"max_open_connections"     env:"MAX_OPEN_CONNECTIONS"`
	MaxIdleConnections    int                  `json:"max_idle_connections"     env:"MAX_IDLE_CONNECTIONS"`
	MaxLifetimeConnection time.Duration        `json:"max_lifetime_connection"  env:"MAX_LIFETIME_CONNECTION"`
	MaxIdleTimeConnection time.Duration        `json:"max_idle_time_connection" env:"MAX_IDLE_TIME_CONNECTION"`
	Options               types.Map[string]    `json:"options"`
}

Options represents the storage options.

func NewOptions

func NewOptions(options ...Option) *Options

NewOptions returns new options.

type Schema

type Schema struct {
	Name          string            `json:"name"`
	Description   string            `json:"description"`
	Deprecated    string            `json:"deprecated"`
	Replacement   string            `json:"replacement"`
	Documentation string            `json:"documentation"`
	Collation     string            `json:"collation"`
	Tables        types.Map[*Table] `json:"tables"`
}

Schema defines a single storage schema structure.

func NewSchema

func NewSchema(name, description string, tables ...*Table) *Schema

NewSchema creates a new Schema instance

type Table

type Table struct {
	Name        string             `json:"name"`
	Description string             `json:"description"`
	Deprecated  string             `json:"deprecated"`
	Replacement string             `json:"replacement"`
	Type        string             `json:"type"`
	Engine      string             `json:"engine"`
	RowFormat   string             `json:"row_format"`
	Codec       string             `json:"codec"`
	Collation   string             `json:"collation"`
	ReadOnly    bool               `json:"read_only"`
	Columns     types.Map[*Column] `json:"columns"`
}

Table defines a single Schema table structure.

func NewTable

func NewTable(name, description string, columns ...*Column) *Table

NewTable creates a new Table instance

type Version

type Version struct {
	Database       string  `json:"database"`
	Dialect        Dialect `json:"dialect"`
	Version        string  `json:"version"`
	Description    string  `json:"description"`
	CompileMachine string  `json:"compile_machine"`
	CompileOs      string  `json:"compile_os"`
}

Version represents a storage version

Jump to

Keyboard shortcuts

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