DuckDBUtils

Database interface

DuckDBUtils.RepositoryType
Repository(db::DuckDB.DB)

Construct a Repository object that holds a DuckDB.DB as well as a pool of connections.

Use DBInterface.(f::Base.Callable, repository::Repository, sql::AbstractString, [params]) to run a function on the result of a query sql on an available connection in the pool.

source
DuckDBUtils.get_catalogFunction
get_catalog(repository::Repository; schema = nothing)

Extract the catalog of available tables from a Repository repository.

source
DuckDBUtils.acquire_connectionFunction
acquire_connection(repository::Repository)

Acquire an open connection to the database repository.db from the pool repository.pool. See also release_connection.

Note

A command con = acquire_connection(repository) must always be followed by a matching command release_connection(repository, con) (after the connection has been used).

source
DuckDBUtils.with_connectionFunction
with_connection(f, repository::Repository, [N])

Acquire a connection con from the pool repository.pool. Then, execute f(con) and release the connection to the pool. An optional parameter N can be passed to determine the number of connections to be acquired (defaults to 1).

source
DuckDBUtils.render_paramsFunction
render_params(catalog::SQLCatalog, node::SQLNode, params = (;))

Return query string and parameter list from query expressed as node.

source

Table tools

DuckDBUtils.load_tableFunction
load_table(
    repository::Repository,
    table,
    name::AbstractString;
    schema = nothing
)

Load a Julia table table as name in schema schema in repository.db.

source
DuckDBUtils.replace_tableFunction
replace_table(
    repository::Repository,
    query::Union{AbstractString, SQLNode}
    [params,]
    name::AbstractString;
    schema = nothing,
    virtual::Bool = false
)

Replace table name in schema schema in repository.db with the result of a given query with optional parameters params.

Use virtual = true to replace a view instead of a table.

source
DuckDBUtils.export_tableFunction
export_table(
    repository::Repository,
    query::Union{AbstractString, SQLNode}
    [params,]
    path::AbstractString;
    schema = nothing,
    options...
)

Export to path (with options options) the result of a given query with optional parameters params in schema schema in repository.db.

source
DuckDBUtils.delete_tableFunction
delete_table(
    repository::Repository,
    name::AbstractString;
    schema = nothing,
    virtual::Bool = false
)

Delete table name in schema schema in repository.db.

Use virtual = true to delete a view instead of a table.

source
DuckDBUtils.with_tableFunction
with_table(f, repository::Repository, table; schema = nothing)

Register a table under a random unique name name, apply f(name), and then unregister the table.

source
DuckDBUtils.colnamesFunction
colnames(repository::Repository, table::AbstractString; schema = nothing)

Return list of columns for a given table.

source

Batched iteration

DuckDBUtils.BatchesType
Batches(tbl, batchsize::Integer, nrows::Integer)

Construct a Batches iterator based on a table tbl with nrows in total. The resulting object iterates column-based tables with batchsize rows each.

source

Internal functions

DuckDBUtils._append!Function
_append!(batch::AbstractDict, cols, rg = Colon())

Append rows rg of column-based table cols to the dict table batch.

source
DuckDBUtils.in_schemaFunction
in_schema(name::AbstractString, schema::Union{AbstractString, Nothing})

Utility to create a name to refer to a table within the schema.

For instance

julia> print(in_schema("tbl", nothing))
"tbl"
julia> print(in_schema("tbl", "schm"))
"schm"."tbl"
source