Skip to content
Database abstraction layer for D programing language, support PostgreSQL / MySQL / SQLite.
Branch: master
Clone or download
Latest commit ef85844 May 5, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples fixed sqlite escape bug Mar 18, 2019
.gitignore Upgrade to Hunt 1.2.x Feb 14, 2019
.travis.yml Update .travis.yml Apr 10, 2019
LICENSE first commit Jun 22, 2017 Handle 'String' & 'Nullable Nov 16, 2018
dub.json Update dub.json May 5, 2019
dub.local.json Add getAs in Row Apr 3, 2019 Update Mar 25, 2019
meson_options.txt Add support for Meson Aug 19, 2018

Build Status


Database abstraction layer for D programing language, support PostgreSQL / MySQL / SQLite.


import std.stdio;

import hunt.database;

void main()
    writeln("run database MySQL demo.");

    auto db = new Database("mysql://root:123456@localhost:3306/test?charset=utf8mb4");

    int result = db.execute(`INSERT INTO user(username) VALUES("test")`);

    foreach(row; db.query("SELECT * FROM user LIMIT 10"))


Use DatabaseOption to instantiate a Database object

auto options = new DatabaseOption("mysql://root:123456@localhost:3306/test");

auto db = new Database(options);

db.execute("SET NAMES utf8");


  • int Database.execute(string sql) Return number of execute result.
int result = db.execute('INSERT INTO user(username) VALUES("Brian")');
// if execute error ,db will throw an DatabaseException
  • ResultSet Database.query(sql) Return ResultSet object for query(SELECT).
ResultSet rs = db.query("SELECT * FROM user LIMIT 10");
  • Statement Database.prepare(sql) Create a prepared Statement object.
Statement stmt = db.prepare("SELECT * FROM user where username = :username and age = :age LIMIT 10");
  • Statement.setParameter(param, value) : bind param's value to :param for sql.
stmt.setParameter("username", "viile");
stmt.setParameter("age", 18);
  • ResultSet Statement.query() Return ResultSet
ResultSet rs = stmt.query();
foreach(row; rs)
  • Row Statement.fetch() Return Row
Row row = stmt.fetch();
  • int Statement.execute() : return execute status for prepared Statement object.
int result = stmt.execute();
  • Statement.lastInsertId() : Statement.execute() for insert sql, return lastInsertId.
You can’t perform that action at this time.