pg #

Before you can use this module, you must first have PostgreSQL installed on your system. To do this, find your OS and perform the actions listed.

NOTE: These instructions are meant only as a convenience. If your OS is not listed or you need extra help, go here.

Fedora 31

sudo dnf install postgresql-server postgresql-contrib
sudo systemctl enable postgresql # to autostart on startup
sudo systemctl start  postgresql

Debian 10/11

sudo apt-get install postgresql postgresql-client
sudo systemctl enable postgresql # to autostart on startup
sudo systemctl start  postgresql

MacOSX (Homebrew)

brew install postgresql
brew services start postgresql

fn connect #

fn connect(config Config) ?DB

struct Config #

struct Config {
pub:
	host     string
	port     int = 5432
	user     string
	password string
	dbname   string
}

struct DB #

struct DB {
mut:
	conn &C.PGconn
}

fn (DB) close #

fn (db DB) close()

close frees the underlying resource allocated by the database connection

fn (DB) q_int #

fn (db DB) q_int(query string) ?int

q_int submit a command to the database server and returns an the first field in the first tuple converted to an int. If no row is found or on command failure, an error is returned

fn (DB) q_string #

fn (db DB) q_string(query string) ?string

q_string submit a command to the database server and returns an the first field in the first tuple as a string. If no row is found or on command failure, an error is returned

fn (DB) q_strings #

fn (db DB) q_strings(query string) ?[]Row

q_strings submit a command to the database server and returns the resulting row set. Alias of exec

fn (DB) exec #

fn (db DB) exec(query string) ?[]Row

exec submit a command to the database server and wait for the result, returning an error on failure and a row set on success

fn (DB) exec_one #

fn (db DB) exec_one(query string) ?Row

fn (DB) exec_param_many #

fn (db DB) exec_param_many(query string, params []string) ?[]Row

exec_param_many executes a query with the provided parameters

fn (DB) exec_param2 #

fn (db DB) exec_param2(query string, param string, param2 string) ?[]Row

fn (DB) exec_param #

fn (db DB) exec_param(query string, param string) ?[]Row

fn (DB) copy_expert #

fn (db DB) copy_expert(query string, file io.ReaderWriter) ?int

copy_expert execute COPY commands https://www.postgresql.org/docs/9.5/libpq-copy.html

struct Row #

struct Row {
pub mut:
	vals []string
}