DuckDBUtils
Database interface
DuckDBUtils.Repository
— TypeRepository(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.
DuckDBUtils.get_catalog
— Functionget_catalog(repository::Repository; schema = nothing)
Extract the catalog of available tables from a Repository
repository
.
DuckDBUtils.acquire_connection
— Functionacquire_connection(repository::Repository)
Acquire an open connection to the database repository.db
from the pool repository.pool
. See also release_connection
.
DuckDBUtils.release_connection
— Functionrelease_connection(repository::Repository, con)
Release connection con
to the pool repository.pool
DuckDBUtils.with_connection
— Functionwith_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
— Functionrender_params(catalog::SQLCatalog, node::SQLNode, params = (;))
Return query string and parameter list from query expressed as node
.
DuckDBUtils.to_sql
— Functionto_sql(x)
Convert a julia value x
to its SQL representation.
Table tools
DuckDBUtils.load_table
— Functionload_table(
repository::Repository,
table,
name::AbstractString;
schema = nothing
)
Load a Julia table table
as name
in schema schema
in repository.db
.
DuckDBUtils.replace_table
— Functionreplace_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
— Functionexport_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
— Functiondelete_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
— Functionwith_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
— Functioncolnames(repository::Repository, table::AbstractString; schema = nothing)
Return list of columns for a given table.
Batched iteration
DuckDBUtils.Batches
— TypeBatches(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
— Functionin_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"