data

package module
v0.0.0-...-4c33cbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2016 License: MIT Imports: 5 Imported by: 4

README

data

A simple postgres database driver extension to provide simplified query and transaction execution

Created for the sake of learning and memes

Usage

Using this is actually really simple, you just need to follow these steps:

Connect

Connect to the database. There's an exported Connect function just pass in the url string form.

Prepare

You can either manually roll your own Statement objects, or use the Prepare function.
The prepare function takes in your query along with any arguments which should be injected into it.

Execute

Either execute your transactions, i.e. your inserts, updates, deletes, Or your queries which return data.
For single statement operations, you may prepare and execute/query in one step using the PrepareAnd... methods.
You can either query for a single row, or multiple. It's up to you.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(connection string)

Connect takes in a valid psql connection string and opens the connection

func ExecuteTransaction

func ExecuteTransaction(stmts ...Statement) error

ExecuteTransaction allows the user to execute >= 1 statement in a single sql transaction

func GetDateString

func GetDateString(i interface{}) string

GetDateString returns a formatted date string

func GetDateTimeString

func GetDateTimeString(i interface{}) string

GetDateTimeString returns a formatted date-time string

func PrepareAndExecute

func PrepareAndExecute(query string, args ...interface{}) error

PrepareAndExecute performs the actions of Prepare and Execute a single statement in one step rather than forcing the user to manually Prepare a statement.

func PrepareAndQuery

func PrepareAndQuery(query string, args ...interface{}) (*sql.Rows, error)

PrepareAndQuery performs the actions of Prepare and Query a single statement in one step rather than forcing the user to manually Prepare a statement.

func Query

func Query(stmt Statement) (*sql.Rows, error)

Query allows the user to perform a query where >= 1 rows are expected back It simply returns the rows so that the user may manipulate the data as they please

func QueryRow

func QueryRow(stmt Statement, data ...interface{}) error

QueryRow allows the user to perform an sql query where only one row is expected The results of the query are put into the passed in data interfaces

func SetInt

func SetInt(i interface{}, otherwise int) int

SetInt returns the value of i if it isn't null, otherwise returns otherwise

func SetString

func SetString(i interface{}, otherwise string) string

SetString returns the value of i if it isn't null, otherwise returns otherwise

Types

type Statement

type Statement struct {
	Query string
	Args  []interface{}
}

Statement is a struct which represents a prepared statement. Calling Prepare allows the user to not have to construct this manually.

func Prepare

func Prepare(query string, args ...interface{}) Statement

Prepare creates a Statement which may be used in any of the Execute or Query functions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL