Documentation
¶
Overview ¶
Package database provides a database abstraction layer for SQL and NoSQL databases.
Index ¶
- Constants
- Variables
- type Column
- type Dialect
- type IKeyValue
- type Option
- func WithMaxIdleConnections(value int) Option
- func WithMaxIdleTimeConnection(value time.Duration) Option
- func WithMaxLifetimeConnection(value time.Duration) Option
- func WithMaxOpenConnections(value int) Option
- func WithOptions(value types.Map[string]) Option
- func WithReplicasDsn(value types.Map[types.URI]) Option
- func WithSourcesDsn(value types.Map[types.URI]) Option
- type Options
- type Schema
- type Table
- type Version
Constants ¶
const ( // DefaultMaxOpenConnections represents the default max open connections. DefaultMaxOpenConnections = 5 DefaultMaxIdleConnections = 1 DefaultMaxLifetimeConnection = 65 * time.Second DefaultMaxIdleTimeConnection = 15 * time.Second )
Variables ¶
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.
type Dialect ¶
type Dialect uint8
Dialect represents the storage dialect.
func ParseDialect ¶
ParseDialect parses the Dialect from string.
func (Dialect) MarshalJSON ¶
MarshalJSON outputs the Dialect as a json.
func (*Dialect) UnmarshalJSON ¶
UnmarshalJSON parses the Dialect from json.
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 ¶
WithMaxIdleConnections sets the max idle connections for the storage.
func WithMaxIdleTimeConnection ¶
WithMaxIdleTimeConnection sets the max idle time connection for the storage.
func WithMaxLifetimeConnection ¶
WithMaxLifetimeConnection sets the max lifetime connection for the storage.
func WithMaxOpenConnections ¶
WithMaxOpenConnections sets the max open connections for the storage.
func WithOptions ¶
WithOptions sets the options for the storage.
func WithReplicasDsn ¶ added in v0.0.3
WithReplicasDsn sets the replicas 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.
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.
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.