Documentation ¶
Overview ¶
Package postgres provides a collection of functions that are primarily geared towards use by a simple CLI tool, and secondarily serve as example code for how to use the Azure Database for PostgreSQL (Flexible Server).
Index ¶
- func CreateTable(name, valueType string) error
- func DbFromEnv() (*sql.DB, error)
- func Delete(table, key string) error
- func DeleteTable(name string) error
- func Exec(sql string, args ...interface{}) (int64, error)
- func InsertKeyValue(table, key, value string) error
- func InsertStdin(table string) error
- func InsertStdinBulk(table string, batchSize int) error
- func ListTables() error
- func QueryJSON(query string) error
- func QueryKeyValue(query string) error
- func QueryString(query string) error
- func Test() error
- type KeyValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTable ¶
CreateTable creates a table in the database with columns key of type varchar(256) and value of type valueType which defaults to jsonb.
func DeleteTable ¶
DeleteTable deletes a table from the database
func Exec ¶
Exec excutes a command and returns the rows affected, or an error. This is primarily to show RowsAffected() which we have ommitted in other places where Exec is used.
func InsertKeyValue ¶
InsertKeyValue inserts a key/value pair into a table. The name of the table defaults to kv.
func InsertStdin ¶
InsertStdin takes one or more records from the standard input and inserts them individually using insertJSON which is similar to InsertJSON but reuses the database connection so we avoid exhausting them in a loop.
func InsertStdinBulk ¶
InsertStdinBulk takes one or more records from the standard input and inserts them individually using insertBulkJSON rather than InsertStdin's insertJSON. This uses the bulk import approach outlined in the pq docs: https://pkg.golang.ir/github.com/lib/pq#hdr-Bulk_imports We set a batchSize, which defaults to 100 if batchSize == 0
func ListTables ¶
func ListTables() error
ListTables selects all tables from the current database and outputs them in JSON format.
func QueryJSON ¶
QueryJSON selects performs a select from the database (with a default) and builds a JSON map which we write to the standard output.
func QueryKeyValue ¶
QueryKeyValue is a function that is designed to return a Key/Value pair which we marshal to JSON and write to the standard output. It is partially designed to be an example, and to guarantee output shape when we pair with InsertKeyValue. We also default the query to: select key, value from kv
func QueryString ¶
QueryString performs a query (with a default) which returns a single string, which we then print to the standard output. This function is designed for queries that have a single return value (e.g. a json/jsonb column)