duckdb 0.0.1

DuckDB client for D


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

d-duckdb

DuckDB client for D. This client is based on DuckDB's C API.

Usage

Iterate query result via foreach

import duckdb;
import std;

void main()
{
    auto db = new Database(null);  // null for in-memory database
    auto conn = db.connect();

    writeln(duckdbVersion);

    conn.queryWithoutResult("CREATE TABLE integers (i INTEGER, j INTEGER);");
    conn.queryWithoutResult("INSERT INTO integers VALUES (3, 4), (5, 6), (7, NULL);");
    auto r = conn.query("SELECT * FROM integers;");
    foreach (int a, Nullable!int b; r)  // Specify argument types implicitly
        writeln(a, ", ",  b);

    conn.disconnect();
    db.close();
}

DuckDB and D Types

DuckDB typeD typeDescription
BOOLEANbool
TINYINTbyte
SMALLINTshort
INTEGERint
BIGINTlong
HUGEINTBigInt
UTINYINTubyte
USMALLINTushort
UINTEGERuint
UBIGINTulong
UHUGEINTBigInt
FLOATfloat
DOUBLEdouble
DECIMALTODO: Phobos doesn't have BigFloat/BigDecimal, so support is limited
VARCHARstringwstring and dstring are also supported
BLOBbyte[]
BITSTRINGTODO
ENUMstring
DATEDate
TIMETODO but use TIMESTAMP instead
TIMESTAMPSysTimeTIMESTAMP_NS is not supported because SysTime is hnsecs precision
INTERVALTODO
ARRAYT[]
LISTT[]
MAPV[K]
STRUCTstructCurrent implementation doesn't check field names
UNIONTODO
UUIDTODO

Special cases

  • NULL

Use std.typecons.Nullable to accept NULL for basic types, e.g. Nullable!int.

  • Infinity for DATA and TIMESTAMP

Infinity/-Infinity is mapping to .init value, e.g. Date.init and SysTime.init.

TODO

  • Support TODO DuckDB types
  • Support more APIs
  • Prepared Statements
  • Appender
  • and more
  • Improve API design
  • Add unittests

DuckDB official site

DuckDB C API document

Copyright (c) 2024- Masahiro Nakagawa

License

Distributed under the Boost Software License, Version 1.0.

Authors:
  • Masahiro Nakagawa
Dependencies:
none
Versions:
0.2.0 2024-Oct-10
0.1.0 2024-Oct-07
0.0.1 2024-Oct-03
~main 2024-Oct-18
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 1 downloads total

Score:
0.4
Short URL:
duckdb.dub.pm