huntlabs / hunt-database

Database abstraction layer library using pure D programing language, support PostgreSQL and MySQL.
https://www.huntlabs.net
Apache License 2.0
48 stars 5 forks source link
database dlang mysql native postgresql sqlite

Build Status

Database

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

Example


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")`);
    writeln(result);

    foreach(row; db.query("SELECT * FROM user LIMIT 10"))
    {
        writeln(row["username"]);
    }

    db.close();
}

Use DatabaseOption to instantiate a Database object

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

auto db = new Database(options);

db.execute("SET NAMES utf8");

API

See also