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

enum Oid #

enum Oid {
	t_bool = 16
	t_bytea = 17
	t_char = 18
	t_name = 19
	t_int8 = 20
	t_int2 = 21
	t_int2vector = 22
	t_int4 = 23
	t_regproc = 24
	t_text = 25
	t_oid = 26
	t_tid = 27
	t_xid = 28
	t_cid = 29
	t_vector = 30
	t_pg_ddl_command = 32
	t_pg_type = 71
	t_pg_attribute = 75
	t_pg_proc = 81
	t_pg_class = 83
	t_json = 114
	t_xml = 142
	t__xml = 143
	t_pg_node_tree = 194
	t__json = 199
	t_smgr = 210
	t_index_am_handler = 325
	t_point = 600
	t_lseg = 601
	t_path = 602
	t_box = 603
	t_polygon = 604
	t_line = 628
	t__line = 629
	t_cidr = 650
	t__cidr = 651
	t_float4 = 700
	t_float8 = 701
	t_abstime = 702
	t_reltime = 703
	t_tinterval = 704
	t_unknown = 705
	t_circle = 718
	t__circle = 719
	t_money = 790
	t__money = 791
	t_macaddr = 829
	t_inet = 869
	t__bool = 1000
	t__bytea = 1001
	t__char = 1002
	t__name = 1003
	t__int2 = 1005
	t__int2vector = 1006
	t__int4 = 1007
	t__regproc = 1008
	t__text = 1009
	t__tid = 1010
	t__xid = 1011
	t__cid = 1012
	t__vector = 1013
	t__bpchar = 1014
	t__varchar = 1015
	t__int8 = 1016
	t__point = 1017
	t__lseg = 1018
	t__path = 1019
	t__box = 1020
	t__float4 = 1021
	t__float8 = 1022
	t__abstime = 1023
	t__reltime = 1024
	t__tinterval = 1025
	t__polygon = 1027
	t__ = 1028
	t_aclitem = 1033
	t__aclitem = 1034
	t__macaddr = 1040
	t__inet = 1041
	t_bpchar = 1042
	t_varchar = 1043
	t_date = 1082
	t_time = 1083
	t_timestamp = 1114
	t__timestamp = 1115
	t__date = 1182
	t__time = 1183
	t_timestamptz = 1184
	t__timestamptz = 1185
	t_interval = 1186
	t__interval = 1187
	t__numeric = 1231
	t_pg_database = 1248
	t__cstring = 1263
	t_timetz = 1266
	t__timetz = 1270
	t_bit = 1560
	t__bit = 1561
	t_varbit = 1562
	t__varbit = 1563
	t_numeric = 1700
	t_refcursor = 1790
	t__refcursor = 2201
	t_regprocedure = 2202
	t_regoper = 2203
	t_regoperator = 2204
	t_regclass = 2205
	t_regtype = 2206
	t__regprocedure = 2207
	t__regoper = 2208
	t__regoperator = 2209
	t__regclass = 2210
	t__regtype = 2211
	t_record = 2249
	t_cstring = 2275
	t_any = 2276
	t_anyarray = 2277
	t_v = 2278
	t_trigger = 2279
	t_language_handler = 2280
	t_internal = 2281
	t_opaque = 2282
	t_anyelement = 2283
	t__record = 2287
	t_anynonarray = 2776
	t_pg_authid = 2842
	t_pg_auth_members = 2843
	t__txid_snapshot = 2949
	t_uuid = 2950
	t__uuid = 2951
	t_txid_snapshot = 2970
	t_fdw_handler = 3115
	t_pg_lsn = 3220
	t__pg_lsn = 3221
	t_tsm_handler = 3310
	t_anyenum = 3500
	t_tsvector = 3614
	t_tsquery = 3615
	t_gtsvector = 3642
	t__tsvector = 3643
	t__gtsvector = 3644
	t__tsquery = 3645
	t_regconfig = 3734
	t__regconfig = 3735
	t_regdictionary = 3769
	t__regdictionary = 3770
	t_jsonb = 3802
	t__jsonb = 3807
	t_anyrange = 3831
	t_event_trigger = 3838
	t_int4range = 3904
	t__int4range = 3905
	t_numrange = 3906
	t__numrange = 3907
	t_tsrange = 3908
	t__tsrange = 3909
	t_tstzrange = 3910
	t__tstzrange = 3911
	t_daterange = 3912
	t__daterange = 3913
	t_int8range = 3926
	t__int8range = 3927
	t_pg_shseclabel = 4066
	t_regnamespace = 4089
	t__regnamespace = 4090
	t_regrole = 4096
	t__regrole = 4097
}

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) @select #

fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.QueryData) ?[][]orm.Primitive

sql expr

fn (DB) close #

fn (db DB) close()

close frees the underlying resource allocated by the database connection

fn (DB) copy_expert #

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

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

fn (DB) create #

fn (db DB) create(table string, fields []orm.TableField) ?

table

fn (DB) delete #

fn (db DB) delete(table string, where orm.QueryData) ?

fn (DB) drop #

fn (db DB) drop(table string) ?

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 #

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

fn (DB) exec_param2 #

fn (db DB) exec_param2(query string, param string, param2 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) insert #

fn (db DB) insert(table string, data orm.QueryData) ?

sql stmt

fn (DB) last_id #

fn (db DB) last_id() orm.Primitive

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) update #

fn (db DB) update(table string, data orm.QueryData, where orm.QueryData) ?

struct Row #

struct Row {
pub mut:
	vals []string
}