postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2017 License: MIT Imports: 5 Imported by: 3

README

PostGres

The PostGres dialect uses the github.com/lib/pq driver, which passes the compatibility test suite.

Testing

A valid PostGres connection string should be set on the environmental variable SOL_TEST_POSTGRES. An example:

SOL_TEST_POSTGRES="host=localhost port=5432 dbname=sol_test user=postgres password=secret sslmode=disable" go test

If the environmental variable is empty, the test will default to a Travis CI connection string, which will likely panic on your local system.

Docker

Docker hub provides an official PostGres image. A container can be started with:

docker run -p 5432:5432 --name postgres \
-e "POSTGRES_PASSWORD=" \
-e "POSTGRES_DB=sol_test" -d postgres:latest

Then change the host of the connection string to the default Docker machine and run tests, for example:

SOL_TEST_POSTGRES="host=<DOCKER HOST> port=5432 dbname=sol_test user=postgres sslmode=disable" go test

Documentation

Index

Constants

View Source
const (
	Contains                  = "@>"
	ContainedBy               = "<@"
	Overlap                   = "&&"
	StrictlyLeftOf            = "<<"
	StrictlyRightOf           = ">>"
	DoesNotExtendToTheRightOf = "&<"
	DoesNotExtendToTheLeftOf  = "&>"
	IsAdjacentTo              = "-|-"
	Union                     = "+"
	Intersection              = "*"
	Difference                = "-"
)
View Source
const (
	NowUTC = "now() at time zone 'utc'"
	Now    = "now()"
)
View Source
const GenerateV4 = `uuid_generate_v4()`

TODO Don't hardcode utc?

Variables

This section is empty.

Functions

func Cidr

func Cidr() types.BaseType

func Date

func Date() (t timestamp)

TODO Date cannot have a time zone

func DateRange

func DateRange() (t rangeType)

func Inet

func Inet() types.BaseType

func Int4Range

func Int4Range() (t rangeType)

func Int8Range

func Int8Range() (t rangeType)

func JSON

func JSON() (t json)

func Macaddr

func Macaddr() types.BaseType

func NumRange

func NumRange() (t rangeType)

func Serial

func Serial() (t serial)

Serial creates a new serial type

func Time

func Time() (t timestamp)

func Timestamp

func Timestamp() (t timestamp)

func TimestampRange

func TimestampRange() (t rangeType)

func TimestampWithTimezoneRange

func TimestampWithTimezoneRange() (t rangeType)

func UUID

func UUID() (t uuid)

Types

type ColumnElem

type ColumnElem struct {
	sol.ColumnElem
}

ColumnElem is the postgres dialect's implementation of a SQL column

func (ColumnElem) ContainedBy

func (col ColumnElem) ContainedBy(param interface{}) sol.BinaryClause

func (ColumnElem) Contains

func (col ColumnElem) Contains(param interface{}) sol.BinaryClause

func (ColumnElem) Difference

func (col ColumnElem) Difference(param interface{}) sol.BinaryClause

func (ColumnElem) DoesNotExtendToTheLeftOf

func (col ColumnElem) DoesNotExtendToTheLeftOf(param interface{}) sol.BinaryClause

func (ColumnElem) DoesNotExtendToTheRightOf

func (col ColumnElem) DoesNotExtendToTheRightOf(param interface{}) sol.BinaryClause

func (ColumnElem) Intersection

func (col ColumnElem) Intersection(param interface{}) sol.BinaryClause

func (ColumnElem) IsAdjacentTo

func (col ColumnElem) IsAdjacentTo(param interface{}) sol.BinaryClause

func (ColumnElem) Overlap

func (col ColumnElem) Overlap(param interface{}) sol.BinaryClause

func (ColumnElem) StrictlyLeftOf

func (col ColumnElem) StrictlyLeftOf(param interface{}) sol.BinaryClause

func (ColumnElem) StrictlyRightOf

func (col ColumnElem) StrictlyRightOf(param interface{}) sol.BinaryClause

func (ColumnElem) Union

func (col ColumnElem) Union(param interface{}) sol.BinaryClause

type InsertStmt

type InsertStmt struct {
	sol.InsertStmt
	// contains filtered or unexported fields
}

InsertStmt is the internal representation of an INSERT ... RETURNING statement.

func Insert

func Insert(selections ...sol.Selectable) InsertStmt

Insert creates an INSERT ... RETURNING statement for the given columns. There must be at least one column and all columns must belong to the same table.

func (InsertStmt) Compile

func (stmt InsertStmt) Compile(d dialect.Dialect, ps *sol.Parameters) (string, error)

Compile outputs the INSERT ... RETURNING statement using the given dialect and parameters. An error may be returned because of a pre-existing error or because an error occurred during compilation.

func (InsertStmt) DoNothing

func (stmt InsertStmt) DoNothing() InsertStmt

DoNothing sets the ON CONFLICT behavior to DO NOTHING

func (InsertStmt) DoUpdate

func (stmt InsertStmt) DoUpdate(values sol.Values) InsertStmt

DoUpdate sets the ON CONFLICT behavior to DO UPDATE if at least one value is given

func (InsertStmt) OnConflict

func (stmt InsertStmt) OnConflict(targets ...string) InsertStmt

OnConflict adds UPSERT behavior to the INSERT. By Default, it will DO NOTHING.

func (InsertStmt) RemoveOnConflict

func (stmt InsertStmt) RemoveOnConflict() InsertStmt

RemoveOnConflict will remove the ON CONFLICT behavior

func (InsertStmt) Returning

func (stmt InsertStmt) Returning(selections ...sol.Selectable) InsertStmt

Returning adds a RETURNING clause to the statement. TODO How to remove a returning?

func (InsertStmt) String

func (stmt InsertStmt) String() string

String outputs the parameter-less INSERT ... RETURNING statement in the PostGres dialect.

func (InsertStmt) Values

func (stmt InsertStmt) Values(args interface{}) InsertStmt

Values proxies to the inner InsertStmt's Values method

func (InsertStmt) Where

func (stmt InsertStmt) Where(conditions ...sol.Clause) InsertStmt

Where should only be used alongside OnConflict. Only one WHERE is allowed per statement. Additional calls to Where will overwrite the existing WHERE clause.

type PostGres

type PostGres struct{}

PostGres implements the Dialect interface for postgres databases.

func Dialect

func Dialect() *PostGres

Dialect is a constructor for the PostGres Dialect

func (*PostGres) Param

func (d *PostGres) Param(i int) string

Param returns the postgres specific parameterization scheme.

type TableElem

type TableElem struct {
	*sol.TableElem
}

TableElem is a postgres specific implementation of a table. Major differences include: * Column and C methods returns postgres specific columns * Insert return postgres specific INSERT statements with RETURNING syntax

func Table

func Table(name string, modifiers ...sol.Modifier) *TableElem

Table creates a new table element. It will panic on any errors.

func (TableElem) C

func (table TableElem) C(name string) ColumnElem

C is an alias for Column

func (TableElem) Column

func (table TableElem) Column(name string) ColumnElem

Column will return a postgres specific ColumnElem rather than a generic ColumnElem. It is assumed that all columns belonging to postgres table are postgres columns

func (*TableElem) Insert

func (table *TableElem) Insert() InsertStmt

Insert creates a postgres.InsertStmt from the table

Jump to

Keyboard shortcuts

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