postgres

package
v0.0.0-...-e446189 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyEmpty = errors.New("body is empty")

ErrBodyEmpty err throw when body is empty

Functions

func AddDatabaseToPool

func AddDatabaseToPool(name string, DB *sqlx.DB)

AddDatabaseToPool add connection to pool

func ClearStmt

func ClearStmt()

ClearStmt used to reset the cache and allow multiple tests

func Get

func Get() (*sqlx.DB, error)

Get get postgres connection

func GetDatabase

func GetDatabase() string

GetDatabase get current database in use

func GetPool

func GetPool() *connection.ConnectionPool

GetPool of connection

func GetQueryOperator

func GetQueryOperator(op string) (string, error)

GetQueryOperator identify operator on a join

func GetURI

func GetURI(DBName string) string

GetURI postgres connection URI

func Load

func Load()

Load postgres

func MustGet

func MustGet() *sqlx.DB

MustGet get postgres connection

func NormalizeGroupFunction

func NormalizeGroupFunction(paramValue string) (groupFuncSQL string, err error)

NormalizeGroupFunction normalize url params values to sql group functions

func Prepare

func Prepare(db *sqlx.DB, SQL string) (stmt *sql.Stmt, err error)

Prepare statement func

func PrepareTx

func PrepareTx(tx *sql.Tx, SQL string) (stmt *sql.Stmt, err error)

PrepareTx statement func

func SetDatabase

func SetDatabase(name string)

SetDatabase set current database in use

func WriteSQL

func WriteSQL(sql string, values []interface{}) (sc adapters.Scanner)

WriteSQL perform INSERT's, UPDATE's, DELETE's operations

Types

type Postgres

type Postgres struct {
}

Postgres adapter postgresql

func (*Postgres) BatchInsertCopy

func (adapter *Postgres) BatchInsertCopy(dbname, schema, table string, keys []string, values ...interface{}) (sc adapters.Scanner)

BatchInsertCopy execute batch insert sql into a table unsing copy

func (*Postgres) BatchInsertValues

func (adapter *Postgres) BatchInsertValues(SQL string, values ...interface{}) (sc adapters.Scanner)

BatchInsertValues execute batch insert sql into a table unsing multi values

func (*Postgres) CountByRequest

func (adapter *Postgres) CountByRequest(req *http.Request) (countQuery string, err error)

CountByRequest implements COUNT(fields) OPERTATION

func (*Postgres) DatabaseClause

func (adapter *Postgres) DatabaseClause(req *http.Request) (query string, hasCount bool)

DatabaseClause return a SELECT `query`

func (*Postgres) DatabaseOrderBy

func (adapter *Postgres) DatabaseOrderBy(order string, hasCount bool) (orderBy string)

DatabaseOrderBy generate database order by

func (*Postgres) DatabaseWhere

func (adapter *Postgres) DatabaseWhere(requestWhere string) (whereSyntax string)

DatabaseWhere generate database where syntax

func (*Postgres) Delete

func (adapter *Postgres) Delete(SQL string, params ...interface{}) (sc adapters.Scanner)

Delete execute delete sql into a table

func (*Postgres) DeleteSQL

func (adapter *Postgres) DeleteSQL(database string, schema string, table string) string

DeleteSQL generate delete sql

func (*Postgres) DeleteWithTransaction

func (adapter *Postgres) DeleteWithTransaction(tx *sql.Tx, SQL string, params ...interface{}) (sc adapters.Scanner)

DeleteWithTransaction execute delete sql into a table

func (*Postgres) DistinctClause

func (adapter *Postgres) DistinctClause(r *http.Request) (distinctQuery string, err error)

DistinctClause get params in request to add distinct clause

func (*Postgres) ExecuteScripts

func (adapter *Postgres) ExecuteScripts(method, sql string, values []interface{}) (sc adapters.Scanner)

ExecuteScripts run sql templates created by users

func (*Postgres) FieldsPermissions

func (adapter *Postgres) FieldsPermissions(r *http.Request, table string, op string) (fields []string, err error)

FieldsPermissions get fields permissions based in prest configuration

func (*Postgres) GetScript

func (adapter *Postgres) GetScript(verb, folder, scriptName string) (script string, err error)

GetScript get SQL template file

func (*Postgres) GetTransaction

func (adapter *Postgres) GetTransaction() (tx *sql.Tx, err error)

GetTransaction get transaction

func (*Postgres) GroupByClause

func (adapter *Postgres) GroupByClause(r *http.Request) (groupBySQL string)

GroupByClause get params in request to add group by clause

func (*Postgres) Insert

func (adapter *Postgres) Insert(SQL string, params ...interface{}) (sc adapters.Scanner)

Insert execute insert sql into a table

func (*Postgres) InsertSQL

func (adapter *Postgres) InsertSQL(database string, schema string, table string, names string, placeholders string) string

InsertSQL generate insert sql

func (*Postgres) InsertWithTransaction

func (adapter *Postgres) InsertWithTransaction(tx *sql.Tx, SQL string, params ...interface{}) (sc adapters.Scanner)

InsertWithTransaction execute insert sql into a table

func (*Postgres) JoinByRequest

func (adapter *Postgres) JoinByRequest(r *http.Request) (values []string, err error)

JoinByRequest implements join in queries

func (*Postgres) OrderByRequest

func (adapter *Postgres) OrderByRequest(r *http.Request) (values string, err error)

OrderByRequest implements ORDER BY in queries

func (*Postgres) PaginateIfPossible

func (adapter *Postgres) PaginateIfPossible(r *http.Request) (paginatedQuery string, err error)

PaginateIfPossible func

func (*Postgres) ParseBatchInsertRequest

func (adapter *Postgres) ParseBatchInsertRequest(r *http.Request) (colsName string, placeholders string, values []interface{}, err error)

ParseBatchInsertRequest create insert SQL to batch request

func (*Postgres) ParseInsertRequest

func (adapter *Postgres) ParseInsertRequest(r *http.Request) (colsName string, colsValue string, values []interface{}, err error)

ParseInsertRequest create insert SQL

func (*Postgres) ParseScript

func (adapter *Postgres) ParseScript(scriptPath string, queryURL url.Values) (sqlQuery string, values []interface{}, err error)

ParseScript use values sent by users and add on script

func (*Postgres) Query

func (adapter *Postgres) Query(SQL string, params ...interface{}) (sc adapters.Scanner)

Query process queries

func (*Postgres) QueryCount

func (adapter *Postgres) QueryCount(SQL string, params ...interface{}) (sc adapters.Scanner)

QueryCount process queries with count

func (*Postgres) ReturningByRequest

func (adapter *Postgres) ReturningByRequest(r *http.Request) (returningSyntax string, err error)

ReturningByRequest create interface for queries + returning

func (*Postgres) SchemaClause

func (adapter *Postgres) SchemaClause(req *http.Request) (query string, hasCount bool)

SchemaClause return a SELECT `query`

func (*Postgres) SchemaOrderBy

func (adapter *Postgres) SchemaOrderBy(order string, hasCount bool) (orderBy string)

SchemaOrderBy generate schema order by

func (*Postgres) SchemaTablesClause

func (adapter *Postgres) SchemaTablesClause() (query string)

SchemaTablesClause generate schema tables clause

func (*Postgres) SchemaTablesOrderBy

func (adapter *Postgres) SchemaTablesOrderBy(order string) (orderBy string)

SchemaTablesOrderBy generate schema tables order by

func (*Postgres) SchemaTablesWhere

func (adapter *Postgres) SchemaTablesWhere(requestWhere string) (whereSyntax string)

SchemaTablesWhere generate schema tables where syntax

func (*Postgres) SelectFields

func (adapter *Postgres) SelectFields(fields []string) (sql string, err error)

SelectFields query

func (*Postgres) SelectSQL

func (adapter *Postgres) SelectSQL(selectStr string, database string, schema string, table string) string

SelectSQL generate select sql

func (*Postgres) SetByRequest

func (adapter *Postgres) SetByRequest(r *http.Request, initialPlaceholderID int) (setSyntax string, values []interface{}, err error)

SetByRequest create a set clause for SQL

func (*Postgres) SetDatabase

func (adapter *Postgres) SetDatabase(name string)

SetDatabase set the current database name in use

func (*Postgres) TableClause

func (adapter *Postgres) TableClause() (query string)

TableClause generate table clause

func (*Postgres) TableOrderBy

func (adapter *Postgres) TableOrderBy(order string) (orderBy string)

TableOrderBy generate table order by

func (*Postgres) TablePermissions

func (adapter *Postgres) TablePermissions(table string, op string) bool

TablePermissions get tables permissions based in prest configuration

func (*Postgres) TableWhere

func (adapter *Postgres) TableWhere(requestWhere string) (whereSyntax string)

TableWhere generate table where syntax

func (*Postgres) Update

func (adapter *Postgres) Update(SQL string, params ...interface{}) (sc adapters.Scanner)

Update execute update sql into a table

func (*Postgres) UpdateSQL

func (adapter *Postgres) UpdateSQL(database string, schema string, table string, setSyntax string) string

UpdateSQL generate update sql

func (*Postgres) UpdateWithTransaction

func (adapter *Postgres) UpdateWithTransaction(tx *sql.Tx, SQL string, params ...interface{}) (sc adapters.Scanner)

UpdateWithTransaction execute update sql into a table

func (*Postgres) WhereByRequest

func (adapter *Postgres) WhereByRequest(r *http.Request, initialPlaceholderID int) (whereSyntax string, values []interface{}, err error)

WhereByRequest create interface for queries + where

type Stmt

type Stmt struct {
	Mtx        *sync.Mutex
	PrepareMap map[string]*sql.Stmt
}

Stmt statement representation

func GetStmt

func GetStmt() *Stmt

GetStmt get statement

func (*Stmt) Prepare

func (s *Stmt) Prepare(db *sqlx.DB, tx *sql.Tx, SQL string) (statement *sql.Stmt, err error)

Prepare statement

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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