gopherbouncepostgres

package module
v0.0.0-...-623662d Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

gopherbouncepostgres

PostgreSQL bindings for the gopherbouncedb package

Documentation

Overview

Package gopherbouncepostgres provides Postgres bindings for the gopherbounce package.

Index

Constants

View Source
const (
	PGUsersInit = `` /* 396-byte string literal not displayed */

	PGUsernameIndex = `CREATE INDEX IF NOT EXISTS idx_users_username 
ON $USERS_TABLE_NAME$(username);`

	PGEMailIndex = `CREATE INDEX IF NOT EXISTS idx_users_email
ON $USERS_TABLE_NAME$(email);`

	PGQueryUserID = `SELECT * FROM $USERS_TABLE_NAME$ WHERE id=$1;`

	PGQueryUsername = `SELECT * FROM $USERS_TABLE_NAME$ WHERE username=$1;`

	PQQueryEmail = `SELECT * FROM $USERS_TABLE_NAME$ WHERE email=$1;`

	PGInsertUser = `` /* 203-byte string literal not displayed */

	PGUpdateUser = `` /* 184-byte string literal not displayed */

	PGDeleteUser = `DELETE FROM $USERS_TABLE_NAME$ WHERE id=$1;`

	PGListUsers = `SELECT * FROM $USERS_TABLE_NAME$;`

	PGUpdateUserFields = `UPDATE $USERS_TABLE_NAME$
SET $UPDATE_CONTENT$
WHERE id=$ID_PARAM_NUM$;`

	PGSessionsInit = `` /* 195-byte string literal not displayed */

	PGInsertSession = `INSERT INTO $SESSIONS_TABLE_NAME$(
session_key, user_, expire_date) VALUES($1, $2, $3);`

	PGGetSession = `SELECT * FROM $SESSIONS_TABLE_NAME$ WHERE session_key=$1;`

	PGDeleteSession = `DELETE FROM $SESSIONS_TABLE_NAME$ WHERE session_key=$1;`

	PGCleanUpSession = `DELETE FROM $SESSIONS_TABLE_NAME$ WHERE expire_date < $1;`

	PGDeleteSessionForUser = `DELETE FROM $SESSIONS_TABLE_NAME$ WHERE user_=$1;`
)
View Source
const (
	// PGKeyExists is the error code from the pq driver that states
	// that a key error occurred.
	PGKeyExists = "23505"
)

Variables

View Source
var (
	DefaultPGRowNames = gopherbouncedb.DefaultUserRowNames
)

Functions

func DefaultPostgreReplacer

func DefaultPostgreReplacer() *gopherbouncedb.SQLTemplateReplacer

Types

type PGBridge

type PGBridge struct{}

func NewPGBridge

func NewPGBridge() PGBridge

func (PGBridge) ConvertTime

func (b PGBridge) ConvertTime(t time.Time) interface{}

func (PGBridge) ConvertTimeScanType

func (b PGBridge) ConvertTimeScanType(val interface{}) (time.Time, error)

func (PGBridge) IsDuplicateInsert

func (b PGBridge) IsDuplicateInsert(err error) bool

func (PGBridge) IsDuplicateUpdate

func (b PGBridge) IsDuplicateUpdate(err error) bool

func (PGBridge) TimeScanType

func (b PGBridge) TimeScanType() interface{}

type PGQueries

type PGQueries struct {
	InitS []string
	GetUserS, GetUserByNameS, GetUserByEmailS, InsertUserS,
	UpdateUserS, DeleteUserS, UpdateFieldsS, ListUsersS string
	Replacer *gopherbouncedb.SQLTemplateReplacer
	RowNames map[string]string
}

PGQueries implements gopherbouncedb.UserSQL with support for Postgres.

func NewPGQueries

func NewPGQueries(replaceMapping map[string]string) *PGQueries

func (*PGQueries) DeleteUser

func (q *PGQueries) DeleteUser() string

func (*PGQueries) GetUser

func (q *PGQueries) GetUser() string

func (*PGQueries) GetUserByEmail

func (q *PGQueries) GetUserByEmail() string

func (*PGQueries) GetUserByName

func (q *PGQueries) GetUserByName() string

func (*PGQueries) InitUsers

func (q *PGQueries) InitUsers() []string

func (*PGQueries) InsertUser

func (q *PGQueries) InsertUser() string

func (*PGQueries) ListUsers

func (q *PGQueries) ListUsers() string

func (*PGQueries) SupportsUserFields

func (q *PGQueries) SupportsUserFields() bool

func (*PGQueries) UpdateUser

func (q *PGQueries) UpdateUser(fields []string) string

type PGSessionQueries

type PGSessionQueries struct {
	InitS                                                                               []string
	InsertSessionS, GetSessionS, DeleteSessionS, CleanUpSessionS, DeleteForUserSessionS string
	Replacer                                                                            *gopherbouncedb.SQLTemplateReplacer
}

PGSessionQueries implements gopherbouncedb.SessionSQL with support for Postgres.

func NewPGSessionQueries

func NewPGSessionQueries(replaceMapping map[string]string) *PGSessionQueries

NewPGSessionQueries returns new queries given the replacement mapping that is used to update the default replacer.

That is it uses the default Postgres replacer, but updates the fields given in replaceMapping to overwrite existing values / insert new ones.

func (*PGSessionQueries) CleanUpSession

func (q *PGSessionQueries) CleanUpSession() string

func (*PGSessionQueries) DeleteForUserSession

func (q *PGSessionQueries) DeleteForUserSession() string

func (*PGSessionQueries) DeleteSession

func (q *PGSessionQueries) DeleteSession() string

func (*PGSessionQueries) GetSession

func (q *PGSessionQueries) GetSession() string

func (*PGSessionQueries) InitSessions

func (q *PGSessionQueries) InitSessions() []string

func (*PGSessionQueries) InsertSession

func (q *PGSessionQueries) InsertSession() string

type PGSessionStorage

type PGSessionStorage struct {
	*gopherbouncedb.SQLSessionStorage
}

PGSessionStorage is as session storage based on Postgres.

func NewPGSessionStorage

func NewPGSessionStorage(db *sql.DB, replaceMapping map[string]string) *PGSessionStorage

NewPGSessionStorage creates a new Postgres session storage given the database connection and the replacement mapping used to create the queries with NewPGSessionQueries.

If you want to configure any options please read the gopherbounce wiki.

type PGStorage

type PGStorage struct {
	*PGUserStorage
	*PGSessionStorage
}

PGStorage combines a user storage and a session storage (both based on Postgres) to implement gopherbouncedb.Storage.

func NewPGStorage

func NewPGStorage(db *sql.DB, replaceMapping map[string]string) *PGStorage

NewPGStorage returns a new PGStorage.

type PGUserStorage

type PGUserStorage struct {
	*gopherbouncedb.SQLUserStorage
}

func NewPGUserStorage

func NewPGUserStorage(db *sql.DB, replaceMapping map[string]string) *PGUserStorage

func (*PGUserStorage) InsertUser

overwrites because of returning, must use query row

Jump to

Keyboard shortcuts

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