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.
sudo dnf install postgresql-server postgresql-contrib
sudo systemctl enable postgresql # to autostart on startup
sudo systemctl start postgresql
sudo apt-get install postgresql postgresql-client
sudo systemctl enable postgresql # to autostart on startup
sudo systemctl start postgresql
brew install postgresql
brew services start postgresql
fn connect(config Config) ?DB
struct Config {
pub:
host string
port int = 5432
user string
password string
dbname string
}
struct DB {
mut:
conn &C.PGconn
}
fn (db DB) close()
close frees the underlaying resource allocated by the database connection
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 DB) q_string(query string) ?string
q_int 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 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 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 DB) exec_one(query string) ?Row
fn (db DB) exec_param_many(query string, params []string) ?[]Row
exec_param_many executes a query with the provided parameters
fn (db DB) exec_param2(query string, param string, param2 string) ?[]Row
fn (db DB) exec_param(query string, param string) ?[]Row
struct Row {
pub mut:
vals []string
}