src/query

Search:
Group by:

Types

Appender = distinct ptr duckdb_appender
AppenderColumn = object
  idx*: int
  tpy*: LogicalType
Parameter = object
  name*: string
  idx*: int
  tpy*: DuckType
Prepared Statement parameters
Query = distinct string

Procs

proc `=copy`(dest: var Appender; source: Appender) {.
    error: "Appender cannot be copied".}
proc `=destroy`(appender: Appender) {....raises: [], tags: [], forbids: [].}
Destroys an appender instance if it exists
proc `=dup`(appender: Appender): Appender {.
    error: "Appender cannot be duplicated".}
proc bindParameter(statement: Statement; name: string): int {.
    ...raises: [OperationError], tags: [], forbids: [].}
Retrieve the index of the parameter for the prepared statement, identified by name

Example:

import nimdrake

let conn = newDatabase().connect()

var statement = conn.newStatement(
  "SELECT CAST($my_val AS BIGINT), CAST($my_second_val AS VARCHAR);"
)
let indexes =
  @[statement.bindParameter("my_second_val"), statement.bindParameter("my_val")]
assert indexes == @[2, 1]
proc close(appender: Appender) {.discardable, ...raises: [OperationError],
                                 tags: [], forbids: [].}
proc endRow(appender: Appender) {.discardable, ...raises: [OperationError],
                                  tags: [], forbids: [].}
proc execute(con: Connection; query: Query): QueryResult {.discardable,
    ...raises: [OperationError], tags: [], forbids: [].}
Executes a raw query without any prepared arguments
proc execute(con: Connection; statement: Statement): QueryResult {.discardable,
    ...raises: [OperationError], tags: [], forbids: [].}
Executes a prepared statement with provided arguments
proc execute(pending: PendingQueryResult): QueryResult {.discardable,
    ...raises: [OperationError], tags: [], forbids: [].}
proc execute[T: Values](con: Connection; query: Query; args: T): QueryResult {.
    discardable.}
Executes a query with arguments by first preparing a statement
proc execute[T: Values](con: Connection; statement: Statement; args: T): QueryResult {.
    discardable.}
Executes a prepared statement with provided arguments
proc executeTask(pending: PendingQueryResult): duckdb_pending_state {.
    ...raises: [], tags: [], forbids: [].}
proc flush(appender: Appender) {.discardable, ...raises: [OperationError],
                                 tags: [], forbids: [].}
proc newAppender(con: Connection; table: string): Appender {.
    ...raises: [OperationError], tags: [], forbids: [].}
Creates a new appender for a specified table
proc newAppender[T](con: Connection; table: string; ent: seq[seq[Option[T]]])
Appends a sequence of sequences of OptionsT to a specified table in a DuckDB database.
proc newAppender[T](con: Connection; table: string; ent: seq[seq[T]])
Appends a sequence of sequences of type T to a specified table in a DuckDB database.
proc newStatement(con: Connection; query: Query): Statement {.
    ...raises: [OperationError], tags: [], forbids: [].}
Creates a new prepared statement from a connection and query

Iterators

iterator columns(appender: Appender): AppenderColumn {....raises: [], tags: [],
    forbids: [].}
Returns the columns in the table that belongs to the appender.
iterator parameters(statement: Statement): Parameter {....raises: [ValueError],
    tags: [], forbids: [].}
There are three syntaxes for denoting parameters in prepared statements: auto-incremented (?), positional ($1), and named ($param). Note that not all clients support all of these syntaxes, e.g., the JDBC client only supports auto-incremented parameters in prepared statements.

Example:

import std/sequtils
import nimdrake

let conn = newDatabase().connect()

conn.execute("CREATE TABLE a (i INTEGER, j VARCHAR);")
var statement = conn.newStatement("INSERT INTO a VALUES (?, ?);")
let parameters = statement.parameters.toSeq()
assert len(parameters) == 2
assert parameters[0].name == "1"
assert parameters[0].idx == 1
assert parameters[0].tpy == DuckType.Integer
assert parameters[1].name == "2"
assert parameters[1].idx == 2
assert parameters[1].tpy == DuckType.VARCHAR

Converters

converter toBase(a: Appender): duckdb_appender {....raises: [], tags: [],
    forbids: [].}
converter toBase(a: ptr Appender): ptr duckdb_appender {....raises: [], tags: [],
    forbids: [].}
converter toBase(q: Query): cstring {....raises: [], tags: [], forbids: [].}
converter toBase(s: string): Query {....raises: [], tags: [], forbids: [].}

Templates

template append(appender: Appender): untyped
Appends a default value to the appender.
template append(appender: Appender; val: bool): untyped
Appends a bool value to the appender.
template append(appender: Appender; val: DataChunk): untyped
Appends a DataChunk value to the appender.

Example:

import nimdrake

let db = newDatabase()
let conn = db.connect()

conn.execute(
  "CREATE TABLE appender_table (int_val INTEGER, varchar_val VARCHAR, bool_val BOOLEAN);"
)
var appender = newAppender(conn, "appender_table")

let types = @[DuckType.Integer, DuckType.Varchar, DuckType.Boolean]
var chunk = newDataChunk(types)
let
  intValues = @[1'i32, 2'i32, 3'i32]
  strValues = @["foo", "bar", "baz"]
  boolValues = @[true, false, true]

chunk[0] = intValues
chunk[1] = strValues
chunk[2] = boolValues

appender.append(chunk)
appender.flush()

let outcome = conn.execute("SELECT * FROM appender_table;").fetchall()
assert outcome[0].valueInteger == intValues
assert outcome[1].valueVarchar == strValues
assert outcome[2].valueBoolean == boolValues
template append(appender: Appender; val: DateTime): untyped
Appends a DateTime value to the appender.
template append(appender: Appender; val: float32): untyped
Appends a float value to the appender.
template append(appender: Appender; val: float64): untyped
Appends a double value to the appender.
template append(appender: Appender; val: int): untyped
Appends an int value to the appender (converted to int64).
template append(appender: Appender; val: int8): untyped
Appends an int8_t value to the appender.
template append(appender: Appender; val: int16): untyped
Appends an int16_t value to the appender.
template append(appender: Appender; val: int32): untyped
Appends an int32_t value to the appender.
template append(appender: Appender; val: int64): untyped
Appends an int64_t value to the appender.
template append(appender: Appender; val: Int128): untyped
Appends a HugeInt value to the appender.
template append(appender: Appender; val: seq[byte]): untyped
Appends a blob value to the appender.
template append(appender: Appender; val: string): untyped
Appends a varchar value to the appender. Empty strings are treated as NULL values.
template append(appender: Appender; val: Time): untyped
Appends a Time value to the appender.
template append(appender: Appender; val: TimeInterval): untyped
Appends a TimeInterval value to the appender.
template append(appender: Appender; val: Timestamp): untyped
Appends a Timestamp value to the appender.
template append(appender: Appender; val: uint8): untyped
Appends an uint8_t value to the appender.
template append(appender: Appender; val: uint16): untyped
Appends an uint16_t value to the appender.
template append(appender: Appender; val: uint32): untyped
Appends an uint32_t value to the appender.
template append(appender: Appender; val: uint64): untyped
Appends an uint64_t value to the appender.
template append(appender: Appender; val: UInt128): untyped
Appends an unsigned HugeInt value to the appender.
template append(appender: Appender; val: Value): untyped
Appends a Value to the appender.
template append[T](appender: var Appender; val: Option[T])
template bindVal(statement: Statement; i: int; val: bool): Error
Binds a bool value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: DateTime): Error
Binds a Datetime value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: float32): Error
Binds a float value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: float64): Error
Binds a double value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: int): Error
Binds an int64_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: int8): Error
Binds an int8_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: int16): Error
Binds an int16_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: int32): Error
Binds an int32_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: int64): Error
Binds an int64_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: Int128): Error
Binds a HugeInt value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: seq[byte]): Error
Binds a blob value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: string): Error
Binds a varchar value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: Time): Error
Binds a Time value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: TimeInterval): Error
Binds a TimeInterval value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: Timestamp): Error
Binds a Timestamp value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: uint8): Error
Binds an uint8_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: uint16): Error
Binds an uint16_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: uint32): Error
Binds an uint32_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: uint64): Error
Binds an uint64_t value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: UInt128): Error
Binds a unsigned HugeInt value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: Value): Error
Binds a value to the prepared statement at the specified index.
template bindVal(statement: Statement; i: int; val: void): Error
Binds a NULL value to the prepared statement at the specified index