mysql-lited 0.2.6

Lightweight native MySQL protocol implementation


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:

mysql-lited

A lightweight native mysql driver written in D

The goal is a native driver that re-uses the same buffers and the stack as much as possible, avoiding unnecessary allocations and work for the garbage collector

notes

  • supports all MySQL types with conversion from/to D types
  • results are retrieved through a flexible callback interface
  • socket type is a template parameter - currently only a vibesocket is implemented
  • only the binary protocol is supported

example

conn.connect("host=sql.moo.com;user=root;pwd=god;db=mew");
//conn.use("mewmew");

// re-usable prepared statements
auto upd = conn.prepare("update manytypes set int_ = ?, timestamp_ = ?, blob_ = ?");
foreach(int_; 0..100) {
    conn.execute(upd, int_, Clock.currTime, MySQLBinary(sha1Of(int_)));
}

// passing variable or large number of arguments
string placeholders(size_t x) {
    return "(" ~ ("?".repeat().take(x).join(",")) ~ ")";
}

int[] ids = [1, 1, 3, 5, 8, 13];
string[] names;
db.execute("select name from items where id in " ~ ids.length.placeholders, ids, (MySQLRow row) {
    writeln(row.name.peek!(char[])); // peek() avoids allocation - cannot use result outside delegate
    names ~= row.name.get!string; // get() duplicates - safe to use result outside delegate
});

// one-shot query
conn.execute("select * from manytypes where id > ?", 13, (size_t index /*optional*/, MySQLHeader header /*optional*/, MySQLRow row) {
    writeln(header[0].name, ": ", row.int_.get!int);
    if (index == 5)
        return false; // optionally return false to discard remaining results
});

// structured row
struct Point {
    int x, y, z;
};

conn.execute("select x, y, z from points where x > y and y > z", (MySQLRow row) {
    auto p = row.toStruct!Point; // default is strict mode, where a missing or null field in the row will throw
    // auto p = row.toStruct!(Point, Strict.no); // missing or null will just be ignored
    writeln(p);
});

todo

  • add proper unit tests
  • implement COM_STMT_SEND_LONG_DATA, and a single parameter binding interface
  • make vibe-d dependency optional
Authors:
  • Márcio Martins
Dependencies:
vibe-d
Versions:
0.4.9 2019-Aug-01
0.4.8 2019-Apr-10
0.4.7 2019-Feb-01
0.4.6 2018-Nov-07
0.4.5 2018-Sep-07
Show all 68 versions
Download Stats:
  • 0 downloads today

  • 1 downloads this week

  • 3 downloads this month

  • 4761 downloads total

Score:
1.8
Short URL:
mysql-lited.dub.pm