zpg Logo thienpow / zpg Configuration

Configuration

Connection behavior is controlled using the zpg.Config struct passed during Connection or ConnectionPool initialization.

const zpg = @import("zpg");

const config = zpg.Config{
    .host = "localhost",
    .port = 5432,
    .username = "myuser",
    .database = "mydatabase",
    .password = "mypassword",
    .tls_mode = .prefer,
    .timeout = 15_000, // 15 seconds
};

// Use config to initialize a connection or pool
// var conn = try zpg.Connection.init(allocator, config);
// var pool = try zpg.ConnectionPool.init(allocator, config, 5);

Config Options

The zpg.Config struct has the following fields:

Validation

You can optionally call the validate method on a Config instance to check for basic configuration errors before attempting to connect:

const my_config = zpg.Config{ /* ... */ };
try my_config.validate(); // Returns an error on invalid configuration

On This Page