XU XUv0.8.8
中文

API

#github.com/xulang-org/packages/postgres

import: postgres #github.com/xulang-org/packages/postgres

counts: 8 fns, 0 methods, 3 types, 0 consts, 0 ifaces

PostgreSQL database/sql driver. This is a small, dependency-free wire driver. It deliberately uses the extended query protocol for arguments (parameters never get interpolated into SQL) and supports the authentication methods that PostgreSQL servers commonly advertise: trust, cleartext, MD5 and SCRAM-SHA-256. TLS is not negotiated by this first version; use sslmode=disable explicitly when the server has SSL enabled but does not require it. DSNs accepted by parse_dsn/open postgres://user:password@host:5432/database?sslmode=disable host=127.0.0.1 port=5432 user=postgres password=secret dbname=postgres Defaults are host=127.0.0.1, port=5432, database=user, sslmode=disable.

github.com/xulang-org/packages · 0.1.1 · Install and use

driver

XuAPI
pub fn driver() driver.Driver

Purpose

PostgreSQL database/sql driver. This is a small, dependency-free wire driver. It deliberately uses the extended query protocol for arguments (parameters never get interpolated into SQL) and supports the authentication methods that PostgreSQL servers commonly advertise: trust, cleartext, MD5 and SCRAM-SHA-256. TLS is not negotiated by this first version; use sslmode=disable explicitly when the server has SSL enabled but does not require it. DSNs accepted by parse_dsn/open postgres://user:password@host:5432/database?sslmode=disable host=127.0.0.1 port=5432 user=postgres password=secret dbname=postgres Defaults are host=127.0.0.1, port=5432, database=user, sslmode=disable.

Parameters

none

Returns

driver.Driver — a value of this type

open

XuAPI
pub fn open(dsn string) driver.Conn

Purpose

Open.

Parameters

dsn string
dsn (string)

Returns

driver.Conn — a value of this type

struct Config

XuAPI
pub struct Config {
    pub host string
    pub port int
    pub user string
    pub password string
    pub database string
    pub ssl_mode string
}

Purpose

Public struct `Config`.

Parameters

host string
host
port int
port
user string
field (string)
password string
field (string)
database string
field (string)
ssl_mode string
field (string)

new_config

XuAPI
pub fn new_config() Config

Purpose

Construct config.

Parameters

none

Returns

Config — a value of this type

parse_dsn

XuAPI
pub fn parse_dsn(dsn string) Config

Purpose

Parse as dsn. Throws on failure.

Parameters

dsn string
dsn (string)

Returns

Config — a value of this type

struct PostgresDriver

XuAPI
pub struct PostgresDriver {
    pub tag int
    pub dsn string
}

Purpose

Public struct `PostgresDriver`.

Parameters

tag int
field (int)
dsn string
field (string)

open_db

XuAPI
pub fn open_db(dsn string) sql.DB

Purpose

PostgreSQL connection pool helpers. Configures reusable connections over database/sql connection pool.

Parameters

dsn string
dsn (string)

Returns

sql.DB — a value of this type

open_pool

XuAPI
pub fn open_pool(dsn string, max_open int, max_idle int) sql.DB

Purpose

Open pool.

Parameters

dsn string
dsn (string)
max_open int
max_open (int)
max_idle int
max_idle (int)

Returns

sql.DB — a value of this type

struct WireResult

XuAPI
pub struct WireResult {
    pub columns []string
    pub cells []string
    pub ncols int
    pub rows_affected int
    pub err string
}

Purpose

Direct wire helpers — no database/sql pool, no driver.Conn interface. The sql.DB pool corrupts Conn interfaces in large binaries; these open a TCP connection, run one statement, and close.

Parameters

columns []string
field ([]string)
cells []string
field ([]string)
ncols int
field (int)
rows_affected int
field (int)
err string
error

query_sql

XuAPI
pub fn query_sql(dsn string, q string) WireResult

Purpose

Query sql.

Parameters

dsn string
dsn (string)
q string
q (string)

Returns

WireResult — a value of this type

exec_sql

XuAPI
pub fn exec_sql(dsn string, q string) WireResult

Purpose

Exec sql.

Parameters

dsn string
dsn (string)
q string
q (string)

Returns

WireResult — a value of this type