View Source educkdb (educkdb v0.9.10)

Low level erlang API for duckdb databases.

Summary

Types

struct, making up a 128 bit signed integer.
DuckDB index type
DuckDB tinyint
DuckDB shortint
DuckDB integer
DuckDB bigint
In the range 0.0..60.0
Note: decimal, timestamp_s, timestamp_ms, timestamp_ns and interval's are not supported yet.
struct, making up a 128 bit unsigned integer.
DuckDB duckdb utinyint
DuckDB ushortint
DuckDB uinteger
DuckDB ubigint

Functions

Append a boolean value to the current location in the row.
Append a data to the current location in the row.
Append a double to the current location in the row. Note: duckdb double's are the same as erlang floats.
Append a float to the current location in the row. Note: duckdb floats are different than erlang floats. When you add an erlang float to a duckdb float column, you will loose precision.
Append a tinyint to the current location in the row.
Append a smallint to the current location in the row.
Append an integer (32 bit) to the current location in the row.
Append a bigint to the current location in the row.
Append a null value to the current location in the row.
Append a time to the current location in the row.
Append a timestamp to the current location in the row.
Append a utinyint to the current location in the row.
Append a usmallint to the current location in the row.
Append an unsigned integer (32 bit) to the current location in the row.
Append a ubigint to the current location in the row.
Append a varchar to the current location in the row.
Create an appender. Appenders allow for high speed bulk insertions into the database. See DuckDB Appender for more information.
Finalize the current row, and start a new one.
Flush the appender to the table, forcing the cache of the appender to be cleared and the data to be appended to the base table.
Bind a boolean to the prepared statement at the specified index.
Bind a date to the prepared statement at the specified index. The date can be either given as a calendar:date() tuple, or an integer with the number of days since the first of January in the year 0.
Bind an uint64 to the prepared statement at the specified index. Note: Erlang's float datatype is a DuckDB double. Using this function allows you to keep the precision.
Bind an float to the prepared statement at the specified index. Note: Erlang's float() datatype is actually a DuckDB double. When binding an Erlang float variable you will lose precision.
Bind an int8 to the prepared statement at the specified index.
Bind an int16 to the prepared statement at the specified index.
Bind an int32 to the prepared statement at the specified index.
Bind an int64 to the prepared statement at the specified index.
Bind a null value to the prepared statement at the specified index.
Bind a time to the prepared statement at the specified index. The time can be either given as an {hour, minute, second} tuple (similar to calendar:time()), or as an integer with the number of microseconds since midnight.
Bind a timestamp to the prepared statement at the specified index. The timestamp can be either a datetime tuple, or an integer with the microseconds since 1-Jan in the year 0.
Bind an uint8 to the prepared statement at the specified index.
Bind an uint8 to the prepared statement at the specified index.
Bind an uint32 to the prepared statement at the specified index.
Bind an uint64 to the prepared statement at the specified index.
Bind a iolist as varchar to the prepared statement at the specified index. Note: This function is meant to bind null terminated strings in the database. Not arbitrary binary data.
Return the number of columns in the data chunk.
Get the column types of the chunk [todo] spec..
Get the columns data of the chunk [todo] spec
Return the number of tuples in th data chunk.
Return the parameter type of the prepared statement at the specified index.
Close the database. All open connections will become unusable.
Get the column names from the query result.
Return a map with config flags, and explanations. The options can vary depending on the underlying DuckDB version used. For more information about DuckDB configuration options, see: DuckDB Configuration.
Connect to the database. Note: It is adviced to use the connection in a single process.
Disconnect from the database.
Execute a prepared statement, and retrieve the first result from the first data chunk.
Execute a prepared statement. The answer is returned.
Fetches a data chunk from a result. The function should be called repeatedly until the result is exhausted.
Get all data chunks from a query result.
Convert a duckdb hugeint record to an erlang integer.

Convert an erlang integer to a DuckDB hugeint.

Open, or create a duckdb database with default options.
Open, or create a duckdb file
Return the number of parameters in a prepared statement.
Return the parameter name of the prepared statement at the specified index.
Return the parameter type of the prepared statement at the specified index.
Compile, and prepare a statement for later execution.
Query the database. The answer the answer is returned immediately.
Do a simple sql query without parameters, and retrieve the result from the first data chunk.
Return the statement type of a prepared statement.
Convert a duckdb uhugeint record to an erlang integer.
Convert a binary represented UUID to a printable hex representation.
Convert a printable UUID to a binary representation.

Types

-type append_response() :: ok | {error, _}.
-type appender() :: reference().
-type bind_response() :: ok | {error, _}.
-type connection() :: reference().
-type data() ::
    boolean() |
    int8() |
    int16() |
    int32() |
    int64() |
    uint8() |
    uint16() |
    uint32() |
    uint64() |
    float() |
    hugeint() |
    calendar:date() |
    time() |
    datetime() |
    binary() |
    [data()] |
    #{binary() => data()} |
    {map, [data()], [data()]}.
-type data_chunk() :: reference().
-type database() :: reference().
-type datetime() :: {calendar:date(), time()}.
-type hugeint() :: #hugeint{}.
struct, making up a 128 bit signed integer.
-type idx() :: uint64().
DuckDB index type
-type int8() :: -127..127.
DuckDB tinyint
-type int16() :: -32767..32767.
DuckDB shortint
-type int32() :: -2147483647..2147483647.
DuckDB integer
-type int64() :: -9223372036854775807..9223372036854775807.
DuckDB bigint
-type named_column() :: #{name := binary(), data := [data()], type := type_name()}.
-type prepared_statement() :: reference().
-type result() :: reference().
-type second() :: calendar:time() | float().
In the range 0.0..60.0
-type sql() :: iodata().
-type statement_type() ::
    invalid | select | insert | update | explain | delete | prepare | create | execute | alter |
    transaction | copy | analyze | variable_set | create_func | drop | export | pragma | vacuum |
    call | set | load | relation | extension | logical_plan | attach | detach | multi | unknown.
-type time() :: {calendar:hour(), calendar:minute(), second()}.
-type type_name() ::
    boolean | tinyint | smallint | integer | bigint | utinyint | usmallint | uinteger | ubigint |
    float | double | hugeint | uhugeint | timestamp | date | time | interval | varchar | blob |
    decimal | timestamp_s | timestamp_ms | timestamp_ns | enum | interval | list | struct | map |
    uuid | json.
Note: decimal, timestamp_s, timestamp_ms, timestamp_ns and interval's are not supported yet.
-type uhugeint() :: #uhugeint{}.
struct, making up a 128 bit unsigned integer.
-type uint8() :: 0..255.
DuckDB duckdb utinyint
-type uint16() :: 0..65535.
DuckDB ushortint
-type uint32() :: 0..4294967295.
DuckDB uinteger
-type uint64() :: 0..18446744073709551615.
DuckDB ubigint

Functions

Link to this function

append_boolean(Appender, Boolean)

View Source
-spec append_boolean(Appender, Boolean) -> AppendResponse
                  when
                      Appender :: appender(),
                      Boolean :: boolean(),
                      AppendResponse :: append_response().
Append a boolean value to the current location in the row.
Link to this function

append_date(Appender, Date)

View Source
-spec append_date(Appender, Date) -> AppendResponse
               when
                   Appender :: appender(),
                   Date :: calendar:date() | integer(),
                   AppendResponse :: append_response().
Append a data to the current location in the row.
Link to this function

append_double(Appender, Double)

View Source
-spec append_double(Appender, Double) -> AppendResponse
                 when
                     Appender :: appender(),
                     Double :: float(),
                     AppendResponse :: append_response().
Append a double to the current location in the row. Note: duckdb double's are the same as erlang floats.
Link to this function

append_float(Appender, Float)

View Source
-spec append_float(Appender, Float) -> AppendResponse
                when Appender :: appender(), Float :: float(), AppendResponse :: append_response().
Append a float to the current location in the row. Note: duckdb floats are different than erlang floats. When you add an erlang float to a duckdb float column, you will loose precision.
Link to this function

append_int8(Appender, TinyInt)

View Source
-spec append_int8(Appender, TinyInt) -> AppendResponse
               when Appender :: appender(), TinyInt :: int8(), AppendResponse :: append_response().
Append a tinyint to the current location in the row.
Link to this function

append_int16(Appender, SmallInt)

View Source
-spec append_int16(Appender, SmallInt) -> AppendResponse
                when
                    Appender :: appender(),
                    SmallInt :: int16(),
                    AppendResponse :: append_response().
Append a smallint to the current location in the row.
Link to this function

append_int32(Appender, Integer)

View Source
-spec append_int32(Appender, Integer) -> AppendResponse
                when
                    Appender :: appender(),
                    Integer :: int32(),
                    AppendResponse :: append_response().
Append an integer (32 bit) to the current location in the row.
Link to this function

append_int64(Appender, BigInt)

View Source
-spec append_int64(Appender, BigInt) -> AppendResponse
                when
                    Appender :: appender(), BigInt :: int64(), AppendResponse :: append_response().
Append a bigint to the current location in the row.
-spec append_null(Appender) -> AppendResponse
               when Appender :: appender(), AppendResponse :: append_response().
Append a null value to the current location in the row.
Link to this function

append_time(Appender, Time)

View Source
-spec append_time(Appender, Time) -> AppendResponse
               when
                   Appender :: appender(),
                   Time :: calendar:time() | time() | non_neg_integer(),
                   AppendResponse :: append_response().
Append a time to the current location in the row.
Link to this function

append_timestamp(Appender, Timestamp)

View Source
-spec append_timestamp(Appender, Timestamp) -> AppendResponse
                    when
                        Appender :: appender(),
                        Timestamp ::
                            calendar:datetime() | erlang:timestamp() | datetime() | integer(),
                        AppendResponse :: append_response().
Append a timestamp to the current location in the row.
Link to this function

append_uint8(Appender, UTinyInt)

View Source
-spec append_uint8(Appender, UTinyInt) -> AppendResponse
                when
                    Appender :: appender(),
                    UTinyInt :: uint8(),
                    AppendResponse :: append_response().
Append a utinyint to the current location in the row.
Link to this function

append_uint16(Appender, USmallInt)

View Source
-spec append_uint16(Appender, USmallInt) -> AppendResponse
                 when
                     Appender :: appender(),
                     USmallInt :: uint16(),
                     AppendResponse :: append_response().
Append a usmallint to the current location in the row.
Link to this function

append_uint32(Appender, UInteger)

View Source
-spec append_uint32(Appender, UInteger) -> AppendResponse
                 when
                     Appender :: appender(),
                     UInteger :: uint32(),
                     AppendResponse :: append_response().
Append an unsigned integer (32 bit) to the current location in the row.
Link to this function

append_uint64(Appender, UBigInt)

View Source
-spec append_uint64(Appender, UBigInt) -> AppendResponse
                 when
                     Appender :: appender(),
                     UBigInt :: uint64(),
                     AppendResponse :: append_response().
Append a ubigint to the current location in the row.
Link to this function

append_varchar(Appender, IOData)

View Source
-spec append_varchar(Appender, IOData) -> AppendResponse
                  when
                      Appender :: appender(),
                      IOData :: iodata(),
                      AppendResponse :: append_response().
Append a varchar to the current location in the row.
Link to this function

appender_create(Connection, Schema, Table)

View Source
-spec appender_create(Connection, Schema, Table) -> Result
                   when
                       Connection :: connection(),
                       Schema :: undefined | binary(),
                       Table :: binary,
                       Result :: {ok, appender()} | {error, _}.
Create an appender. Appenders allow for high speed bulk insertions into the database. See DuckDB Appender for more information.
Link to this function

appender_end_row(Appender)

View Source
-spec appender_end_row(Appender) -> AppendResponse
                    when Appender :: appender(), AppendResponse :: append_response().
Finalize the current row, and start a new one.
Link to this function

appender_flush(Appender)

View Source
-spec appender_flush(Appender) -> AppendResult
                  when Appender :: appender(), AppendResult :: append_response().
Flush the appender to the table, forcing the cache of the appender to be cleared and the data to be appended to the base table.
Link to this function

bind_boolean(PreparedStatement, Index, Boolean)

View Source
-spec bind_boolean(PreparedStatement, Index, Boolean) -> BindResponse
                when
                    PreparedStatement :: prepared_statement(),
                    Index :: idx(),
                    Boolean :: boolean(),
                    BindResponse :: bind_response().
Bind a boolean to the prepared statement at the specified index.
Link to this function

bind_date(PreparedStatement, Index, Date)

View Source
-spec bind_date(PreparedStatement, Index, Date) -> BindResponse
             when
                 PreparedStatement :: prepared_statement(),
                 Index :: idx(),
                 Date :: calendar:date() | integer(),
                 BindResponse :: bind_response().
Bind a date to the prepared statement at the specified index. The date can be either given as a calendar:date() tuple, or an integer with the number of days since the first of January in the year 0.
Link to this function

bind_double(PreparedStatement, Index, Double)

View Source
-spec bind_double(PreparedStatement, Index, Double) -> BindResponse
               when
                   PreparedStatement :: prepared_statement(),
                   Index :: idx(),
                   Double :: float(),
                   BindResponse :: bind_response().
Bind an uint64 to the prepared statement at the specified index. Note: Erlang's float datatype is a DuckDB double. Using this function allows you to keep the precision.
Link to this function

bind_float(PreparedStatement, Index, Float)

View Source
-spec bind_float(PreparedStatement, Index, Float) -> BindResponse
              when
                  PreparedStatement :: prepared_statement(),
                  Index :: idx(),
                  Float :: float(),
                  BindResponse :: bind_response().
Bind an float to the prepared statement at the specified index. Note: Erlang's float() datatype is actually a DuckDB double. When binding an Erlang float variable you will lose precision.
Link to this function

bind_int8(PreparedStatement, Index, Int8)

View Source
-spec bind_int8(PreparedStatement, Index, Int8) -> BindResponse
             when
                 PreparedStatement :: prepared_statement(),
                 Index :: idx(),
                 Int8 :: int8(),
                 BindResponse :: bind_response().
Bind an int8 to the prepared statement at the specified index.
Link to this function

bind_int16(PreparedStatement, Index, Int16)

View Source
-spec bind_int16(PreparedStatement, Index, Int16) -> BindResponse
              when
                  PreparedStatement :: prepared_statement(),
                  Index :: idx(),
                  Int16 :: int16(),
                  BindResponse :: bind_response().
Bind an int16 to the prepared statement at the specified index.
Link to this function

bind_int32(PreparedStatement, Index, Int32)

View Source
-spec bind_int32(PreparedStatement, Index, Int32) -> BindResponse
              when
                  PreparedStatement :: prepared_statement(),
                  Index :: idx(),
                  Int32 :: int32(),
                  BindResponse :: bind_response().
Bind an int32 to the prepared statement at the specified index.
Link to this function

bind_int64(PreparedStatement, Index, Int64)

View Source
-spec bind_int64(PreparedStatement, Index, Int64) -> BindResponse
              when
                  PreparedStatement :: prepared_statement(),
                  Index :: idx(),
                  Int64 :: int64(),
                  BindResponse :: bind_response().
Bind an int64 to the prepared statement at the specified index.
Link to this function

bind_null(PreparedStatement, Index)

View Source
-spec bind_null(PreparedStatement, Index) -> BindResponse
             when
                 PreparedStatement :: prepared_statement(),
                 Index :: idx(),
                 BindResponse :: bind_response().
Bind a null value to the prepared statement at the specified index.
Link to this function

bind_time(PreparedStatement, Index, Time)

View Source
-spec bind_time(PreparedStatement, Index, Time) -> BindResponse
             when
                 PreparedStatement :: prepared_statement(),
                 Index :: idx(),
                 Time :: calendar:time() | time() | non_neg_integer(),
                 BindResponse :: bind_response().
Bind a time to the prepared statement at the specified index. The time can be either given as an {hour, minute, second} tuple (similar to calendar:time()), or as an integer with the number of microseconds since midnight.
Link to this function

bind_timestamp(PreparedStatement, Index, TimeStamp)

View Source
-spec bind_timestamp(PreparedStatement, Index, TimeStamp) -> BindResponse
                  when
                      PreparedStatement :: prepared_statement(),
                      Index :: idx(),
                      TimeStamp :: calendar:datetime() | datetime() | integer(),
                      BindResponse :: bind_response().
Bind a timestamp to the prepared statement at the specified index. The timestamp can be either a datetime tuple, or an integer with the microseconds since 1-Jan in the year 0.
Link to this function

bind_uint8(PreparedStatement, Index, UInt8)

View Source
-spec bind_uint8(PreparedStatement, Index, UInt8) -> BindResponse
              when
                  PreparedStatement :: prepared_statement(),
                  Index :: idx(),
                  UInt8 :: uint8(),
                  BindResponse :: bind_response().
Bind an uint8 to the prepared statement at the specified index.
Link to this function

bind_uint16(PreparedStatement, Index, UInt16)

View Source
-spec bind_uint16(PreparedStatement, Index, UInt16) -> BindResponse
               when
                   PreparedStatement :: prepared_statement(),
                   Index :: idx(),
                   UInt16 :: uint16(),
                   BindResponse :: bind_response().
Bind an uint8 to the prepared statement at the specified index.
Link to this function

bind_uint32(PreparedStatement, Index, UInt32)

View Source
-spec bind_uint32(PreparedStatement, Index, UInt32) -> BindResponse
               when
                   PreparedStatement :: prepared_statement(),
                   Index :: idx(),
                   UInt32 :: uint32(),
                   BindResponse :: bind_response().
Bind an uint32 to the prepared statement at the specified index.
Link to this function

bind_uint64(PreparedStatement, Index, UInt64)

View Source
-spec bind_uint64(PreparedStatement, Index, UInt64) -> BindResponse
               when
                   PreparedStatement :: prepared_statement(),
                   Index :: idx(),
                   UInt64 :: uint64(),
                   BindResponse :: bind_response().
Bind an uint64 to the prepared statement at the specified index.
Link to this function

bind_varchar(PreparedStatement, Index, IOData)

View Source
-spec bind_varchar(PreparedStatement, Index, IOData) -> BindResponse
                when
                    PreparedStatement :: prepared_statement(),
                    Index :: idx(),
                    IOData :: iodata(),
                    BindResponse :: bind_response().
Bind a iolist as varchar to the prepared statement at the specified index. Note: This function is meant to bind null terminated strings in the database. Not arbitrary binary data.
Link to this function

chunk_column_count(DataChunk)

View Source
-spec chunk_column_count(DataChunk) -> ColumnCount
                      when DataChunk :: data_chunk(), ColumnCount :: uint64().
Return the number of columns in the data chunk.
Link to this function

chunk_column_types(Chunk)

View Source
Get the column types of the chunk [todo] spec..
Get the columns data of the chunk [todo] spec
-spec chunk_size(DataChunk) -> TupleCount when DataChunk :: data_chunk(), TupleCount :: uint64().
Return the number of tuples in th data chunk.
Link to this function

clear_bindings(PreparedStatement)

View Source
-spec clear_bindings(PreparedStatement) -> ok | error when PreparedStatement :: prepared_statement().
Return the parameter type of the prepared statement at the specified index.
-spec close(Database) -> Result when Database :: database(), Result :: ok | {error, _}.
Close the database. All open connections will become unusable.
Link to this function

column_names(QueryResult)

View Source
-spec column_names(QueryResult) -> Names when QueryResult :: result(), Names :: [binary()].
Get the column names from the query result.
-spec config_flag_info() -> map().
Return a map with config flags, and explanations. The options can vary depending on the underlying DuckDB version used. For more information about DuckDB configuration options, see: DuckDB Configuration.
-spec connect(Database) -> Result when Database :: database(), Result :: {ok, connection()} | {error, _}.
Connect to the database. Note: It is adviced to use the connection in a single process.
-spec disconnect(Connection) -> Result when Connection :: connection(), Result :: ok | {error, _}.
Disconnect from the database.
Link to this function

execute(PreparedStatement)

View Source
-spec execute(PreparedStatement) -> Result
           when
               PreparedStatement :: prepared_statement(),
               Result :: {ok, [named_column()]} | {error, _}.
Execute a prepared statement, and retrieve the first result from the first data chunk.
Link to this function

execute_prepared(PreparedStatement)

View Source
-spec execute_prepared(PreparedStatement) -> Result
                    when
                        PreparedStatement :: prepared_statement(),
                        Result :: {ok, result()} | {error, _}.
Execute a prepared statement. The answer is returned.
Link to this function

fetch_chunk(QueryResult)

View Source
-spec fetch_chunk(QueryResult) -> DataChunk | '$end'
               when QueryResult :: result(), DataChunk :: data_chunk().
Fetches a data chunk from a result. The function should be called repeatedly until the result is exhausted.
-spec get_chunks(QueryResult) -> DataChunks when QueryResult :: result(), DataChunks :: [data_chunk()].
Get all data chunks from a query result.
Link to this function

hugeint_to_integer(Hugeint)

View Source
-spec hugeint_to_integer(Hugeint) -> Integer when Hugeint :: hugeint(), Integer :: integer().
Convert a duckdb hugeint record to an erlang integer.
Link to this function

integer_to_hugeint(Integer)

View Source
-spec integer_to_hugeint(Integer) -> Hugeint when Integer :: integer(), Hugeint :: hugeint().

Convert an erlang integer to a DuckDB hugeint.

For more information on DuckDB numeric types: See DuckDB Numeric Data Types.
Link to this function

integer_to_uhugeint(NonNegInteger)

View Source
-spec integer_to_uhugeint(NonNegInteger) -> UHugeint
                       when NonNegInteger :: non_neg_integer(), UHugeint :: uhugeint().
-spec open(Filename) -> Result when Filename :: string(), Result :: {ok, database()} | {error, _}.
Open, or create a duckdb database with default options.
-spec open(Filename, Options) -> Result
        when Filename :: string(), Options :: map(), Result :: {ok, database()} | {error, _}.
Open, or create a duckdb file
Link to this function

parameter_count(PreparedStatement)

View Source
-spec parameter_count(PreparedStatement) -> non_neg_integer()
                   when PreparedStatement :: prepared_statement().
Return the number of parameters in a prepared statement.
Link to this function

parameter_index(PreparedStatement, Name)

View Source
-spec parameter_index(PreparedStatement, Name) -> non_neg_integer()
                   when PreparedStatement :: prepared_statement(), Name :: atom() | binary().
Link to this function

parameter_name(PreparedStatement, Index)

View Source
-spec parameter_name(PreparedStatement, Index) -> ParameterName
                  when
                      PreparedStatement :: prepared_statement(),
                      Index :: idx(),
                      ParameterName :: binary().
Return the parameter name of the prepared statement at the specified index.
Link to this function

parameter_type(PreparedStatement, Index)

View Source
-spec parameter_type(PreparedStatement, Index) -> ParameterType
                  when
                      PreparedStatement :: prepared_statement(),
                      Index :: idx(),
                      ParameterType :: type_name().
Return the parameter type of the prepared statement at the specified index.
-spec prepare(connection(), sql()) -> {ok, prepared_statement()} | {error, _}.
Compile, and prepare a statement for later execution.
-spec query(Connection, Sql) -> Result
         when Connection :: connection(), Sql :: sql(), Result :: {ok, result()} | {error, _}.
Query the database. The answer the answer is returned immediately.
-spec squery(Connection, Sql) -> Result
          when
              Connection :: connection(),
              Sql :: sql(),
              Result :: {ok, [named_column()]} | {error, _}.
Do a simple sql query without parameters, and retrieve the result from the first data chunk.
Link to this function

statement_type(PreparedStatement)

View Source
-spec statement_type(PreparedStatement) -> Result
                  when PreparedStatement :: prepared_statement(), Result :: statement_type().
Return the statement type of a prepared statement.
Link to this function

uhugeint_to_integer(UHugeint)

View Source
-spec uhugeint_to_integer(UHugeint) -> Integer when UHugeint :: uhugeint(), Integer :: integer().
Convert a duckdb uhugeint record to an erlang integer.
Link to this function

uuid_binary_to_uuid_string(Bin)

View Source
Convert a binary represented UUID to a printable hex representation.
Link to this function

uuid_string_to_uuid_binary(U)

View Source
Convert a printable UUID to a binary representation.