Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateTableOptions ¶
type CreateTableOptions struct {
// View specifies whether the created table is a view.
View bool
// If BeforeCreateFn is set, it will be executed before the create query is executed.
BeforeCreateFn func(ctx context.Context, conn *sqlx.Conn) error
// If AfterCreateFn is set, it will be executed after the create query is executed.
// This will execute even if the create query fails.
AfterCreateFn func(ctx context.Context, conn *sqlx.Conn) error
}
type DB ¶
type DB interface {
// Close closes the database.
Close() error
// AcquireReadConnection returns a connection to the database for reading.
// Once done the connection should be released by calling the release function.
// This connection must only be used for select queries or for creating and working with temporary tables.
AcquireReadConnection(ctx context.Context) (conn *sqlx.Conn, release func() error, err error)
// Size returns the size of the database in bytes.
// It is currently implemented as sum of the size of all serving `.db` files.
Size() int64
// CreateTableAsSelect creates a new table by name from the results of the given SQL query.
CreateTableAsSelect(ctx context.Context, name string, sql string, opts *CreateTableOptions) (*TableWriteMetrics, error)
// MutateTable allows mutating a table in the database by calling the mutateFn.
MutateTable(ctx context.Context, name string, mutateFn func(ctx context.Context, conn *sqlx.Conn) error) (*TableWriteMetrics, error)
// DropTable removes a table from the database.
DropTable(ctx context.Context, name string) error
// RenameTable renames a table in the database.
RenameTable(ctx context.Context, oldName, newName string) error
// Schema returns the schema of the database.
Schema(ctx context.Context, ilike, name string) ([]*Table, error)
}
type DBOptions ¶
type DBOptions struct {
// LocalPath is the path where local db files will be stored. Should be unique for each database.
LocalPath string
// Remote is the blob storage bucket where the database files will be stored. This is the source of truth.
// The local db will be eventually synced with the remote.
Remote *blob.Bucket
// CPU cores available for the DB. If no ratio is set then this is split evenly between read and write.
CPU int `mapstructure:"cpu"`
// MemoryLimitGB is the amount of memory available for the DB. If no ratio is set then this is split evenly between read and write.
MemoryLimitGB int `mapstructure:"memory_limit_gb"`
// ReadWriteRatio is the ratio of resources to allocate to the read DB. If set, CPU and MemoryLimitGB are distributed based on this ratio.
ReadWriteRatio float64 `mapstructure:"read_write_ratio"`
// ReadSettings are settings applied the read duckDB handle.
ReadSettings map[string]string
// WriteSettings are settings applied the write duckDB handle.
WriteSettings map[string]string
// DBInitQueries are run when the database is first created. These are typically global duckdb configurations.
DBInitQueries []string
// ConnInitQueries are run when a new connection is created. These are typically local duckdb configurations.
ConnInitQueries []string
Logger *zap.Logger
OtelAttributes []attribute.KeyValue
}
func (*DBOptions) ValidateSettings ¶
type TableWriteMetrics ¶ added in v0.57.0
type TableWriteMetrics struct {
// Duration records the time taken to execute all user queries.
Duration time.Duration
}
TableWriteMetrics summarizes executed CRUD operation.
Click to show internal directories.
Click to hide internal directories.