Skip to content

Latest commit

 

History

History
46 lines (38 loc) · 1.35 KB

File metadata and controls

46 lines (38 loc) · 1.35 KB

Lightweight native D client for PostgreSQL database

postgres-native is a native D implementation of the Postgres frontend/backend protocol. It is built in a way to pay attention to a memory allocations (memory will be reused, and only growing if the backend sends results that was larger than any of the results ever encountered). This way GC access can be completely avoided after some initial time.

Usage examples

    import postgres.connection;
    import postgres.row;
    import std.stdio;
    import std.algorighm;

    auto conn = Connection("127.0.0.1", 5432, "burgos", "pass",
            "dbname");
    conn.connect();

    struct ComicBook
    {
        int id;
        @as("comic_hero")
        string hero;
        string title;
    }

    // Using callback for every row
    conn.query("SELECT id, comic_hero, title FROM commics WHERE id > 1",
        (PostgresRow row)
        {
            import std.stdio;
            writeln(row.toStruct!Result);
        });

    // Using range interface
    conn.queryRange("SELECT * FROM comics WHERE id >= 1")
         .map!(toStruct!Result)
         .filter!(x => x.hero == "Tex Willer").each!writeln;

    // Using range interface with extended query
    conn.queryRange("SELECT * FROM comics WHERE id >= $1", 1)
         .map!(toStruct!Result)
         .filter!(x => x.hero == "Tex Willer").each!writeln;