DuckDBUtils
Database interface
DuckDBUtils.Repository — Type
Repository(db::DuckDB.DB)Construct a Repository object that holds a DuckDB.DB as well as a pool of connections.
Use DBInterface.execute(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.
DuckDBUtils.get_catalog — Function
get_catalog(repository::Repository; schema = nothing)Extract the catalog of available tables from a Repository repository.
DuckDBUtils.acquire_connection — Function
acquire_connection(repository::Repository)Acquire an open connection to the database repository.db from the pool repository.pool. See also release_connection.
DuckDBUtils.release_connection — Function
release_connection(repository::Repository, con)Release connection con to the pool repository.pool
DuckDBUtils.with_connection — Function
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).
DuckDBUtils.render_params — Function
render_params(catalog::SQLCatalog, node::SQLNode, params = (;))Return query string and parameter list from query expressed as node.
DuckDBUtils.to_sql — Function
to_sql(x)Convert a julia value x to its SQL representation.
Table tools
DuckDBUtils.load_table — Function
load_table(
repository::Repository,
table,
name::AbstractString;
schema = nothing
)Load a Julia table table as name in schema schema in repository.db.
DuckDBUtils.replace_table — Function
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.
DuckDBUtils.export_table — Function
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.
DuckDBUtils.delete_table — Function
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.
DuckDBUtils.with_table — Function
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.
DuckDBUtils.colnames — Function
colnames(repository::Repository, table::AbstractString; schema = nothing)Return list of columns for a given table.
Batched iteration
DuckDBUtils.Batches — Type
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.
Internal functions
DuckDBUtils._numobs — Function
_numobs(cols)Compute the number of rows of a column-based table cols.
DuckDBUtils._init — Function
_init(schm::Tables.Schema)Initialize an empty table with schema schm.
DuckDBUtils._append! — Function
_append!(batch::AbstractDict, cols, rg = Colon())Append rows rg of column-based table cols to the dict table batch.
DuckDBUtils.in_schema — Function
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"