vibe-d-postgresql ~master
PostgreSQL support for Vibe.d
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:
PostgreSQL support for Vibe.d
Please help us to make documentation better!
Example:
module vibe.db.postgresql.example;
import std.getopt;
import vibe.d;
import vibe.db.postgresql;
PostgresClient client;
void performDbRequest()
{
immutable result = client.pickConnection(
(scope LockedConnection conn)
{
return conn.exec(
"SELECT 123 as first_num, 567 as second_num, 'abc'::text as third_text "~
"UNION ALL "~
"SELECT 890, 233, 'fgh'::text as third_text",
ValueFormat.BINARY
);
}
);
assert(result[0]["second_num"].as!int == 567);
assert(result[1]["third_text"].as!string == "fgh");
foreach (val; rangify(result[0]))
logInfo("Found entry: %s", val.as!Bson.toJson);
}
void main(string[] args)
{
string connString;
getopt(args, "conninfo", &connString);
void initConnectionDg(Connection conn)
{
// D uses UTF8, but Postgres settings may differ. If you want to
// use text strings it is recommended to force set up UTF8 encoding
conn.exec(`set client_encoding to 'UTF8'`);
// Canceling a statement execution due to a timeout implies
// re-initialization of the connection. Therefore, it is
// recommended to additionally set a smaller statement
// execution time limit on the server side so that server can
// quickly interrupt statement processing on its own
// initiative without connection re-initialization.
conn.exec(`set statement_timeout to '15 s'`);
}
// params: conninfo string, maximum number of connections in
// the connection pool and connection initialization delegate
client = new PostgresClient(connString, 4, &initConnectionDg);
// This function can be invoked in parallel from different Vibe.d processes or threads
performDbRequest();
logInfo("Done!");
}
Output:
[main(----) INF] Found entry: 123
[main(----) INF] Found entry: 567
[main(----) INF] Found entry: "abc"
[main(----) INF] Done!
- ~master released 13 days ago
- denizzzka/vibe.d.db.postgresql
- MIT
- Copyright © 2016
- Authors:
- Sub packages:
- vibe-d-postgresql:integration_tests, vibe-d-postgresql:example, vibe-d-postgresql:example_pipelining
- Dependencies:
- dpq2, vibe-core
- Versions:
-
3.3.0-alpha.1 2025-Sep-03 3.2.1 2025-Aug-26 3.2.0 2025-May-31 3.2.0-rc1 2025-May-31 3.1.3 2023-Apr-13 - Download Stats:
-
-
105 downloads today
-
593 downloads this week
-
781 downloads this month
-
58784 downloads total
-
- Score:
- 4.5
- Short URL:
- vibe-d-postgresql.dub.pm