I haven't used the derelict version but I have used the C library itself and wrapped it briefly in my postgres.d here:

https://github.com/adamdruppe/arsd/blob/master/postgres.d

(implements an interface from database.d in the same repo)



I used very, very little of the library, but it is enough to get basic results.


Your connection string can just be "dbname=NAME_HERE". Given your command line, "dbname=testdb" would be the first one I try.

Here's the docs on those strings:
http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS


Your host and port are the default, so no need to list them. You might need to set the user, but a better option there might be to grant your regular user (whatever one you are logged into the operating system as) permission to access the database, then the default will work for that too.



The second class in my file shows how to get basic results.

        string[] row;
        for(int i = 0; i < numFields; i++) {
             string a;
             if(PQgetisnull(res, position, i))
                 a = null;
             else {
a = to!string(PQgetvalue(res, position, i), PQgetlength(res, position, i));
              }
             row ~= a;
         }


gets it as an array of strings. This simple option loses the type checking you can get from the database but it works for a lot of stuff too.

Reply via email to