modulepackage
0.0.0-20240425173419-f6a4c3210da4
Repository: https://github.com/usace/goquery.git
Documentation: pkg.go.dev
# README
goquery is a small library to simplify commodity database operations.
Warning: This library is in an experimental phase
Connecting to a RDBMS:
- populate a rdbms configuration struct with the following info:
type RdbmsConfig struct {
Dbuser string
Dbpass string
Dbhost string
Dbport string
Dbname string //db instance or name
ExternalLib string //any external libraries required by the underlying db driver. for example the instance client location for oracle connections
DbDriver string //db driver reference
DbStore string //goquery store type. Currently choices are 'pgx' or 'sqlx'
}
- Driver Stores
- pgx: uses the pgx driver and is postgres only
- sqlx: uses sqlx and all sql compliant db drivers
Create the connection
store,err:=NewRdbmsDataStore(&config)
Querying
- Minimal example into a slice
dest:=[]mystruct{}
id:=10
err:=store.Select("select * from mytable where id>$id").
Params(id).
Dest(&dest).
Fetch()
- Kitchen sink examples into a slice
type MyFields struct{
field1 string
field2 float64
}
dest:=[]MyFields{}
id:=10
myTable:=data.TableDataset{
Name:"mytable",
Schema:"myschema",
Statements:map[string]string{
"select-all":`select * from mytable`,
"select-none":`select * from mytable where false`,
},
Fields:MyFields{}, //depricated...do not use
}
err:=store.Select().
Dataset(myTable).
Dest(&dest).
Fetch()
//or
err:=store.Select().
Dataset(myTable).
StatementKey("select-all")
Dest(&dest).
Fetch()
//or
err:=store.Select().
Dataset(myTable).
StatementKey("select-all").
Suffix("where id<$1").
Params(id).
Dest(&dest).
Fetch()
//or
err:=store.Select("select %s from %s").
Suffix("where %s<$1").
Appends("*","mytable","id"). //this is just string concatonation. Never append user input.
Params(id).
Dest(&dest).
Fetch()
//finally you can query against transactions, and can optionally panic on err
err:=store.Select().
Dataset(myTable).
Tx(&tx) //transaction reference
Dest(&dest).
PanicOnErr(true).
Fetch()
- As JSON
id:=10
jsonb,err:=store.Select("select * from mytable where id>$id").
Params(id).
OmitNull(false). //will include null keys in output
ForceArray(true). //will force output to a json array regardless of the number of records
ToCamelCase(true). //will convert snake case to camel case
DateFormat("02-Jan-2006"). //convert dates to formatted strings
FetchJSON()
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PoolMaxConnLifetime and PoolMaxConnIdle are string time duration representations as defined in ParseDuration in the stdlib time package the format consists of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m".
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
@TODO figure out how to handle command tags and then we only need a single Execr interface.
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author