func PrepareTx(tx *sql.Tx, SQL string) (stmt *sql.Stmt, err error) {
	stmt, err = GetStmt().Prepare(nil, tx, SQL)
	return
}
PrepareTx statement func
package postgres
import (
	"bytes"
	"database/sql"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"net/http"
	"regexp"
	"sort"
	"strconv"
	"strings"
	"sync"
	"unicode"
	"github.com/lib/pq"
	"github.com/jmoiron/sqlx"
	"github.com/nuveo/log"
	"github.com/prest/adapters"
	"github.com/prest/adapters/postgres/formatters"
	"github.com/prest/adapters/postgres/internal/connection"
	"github.com/prest/adapters/postgres/statements"
	"github.com/prest/adapters/scanner"
	"github.com/prest/config"
)
type Postgres struct {
}
const (
	pageNumberKey   = "_page"
	pageSizeKey     = "_page_size"
	defaultPageSize = 10
)
var removeOperatorRegex *regexp.Regexp
var insertTableNameQuotesRegex *regexp.Regexp
var insertTableNameRegex *regexp.Regexp
var groupRegex *regexp.Regexp
var ErrBodyEmpty = errors.New("body is empty")
var stmts *Stmt
type Stmt struct {
	Mtx        *sync.Mutex
	PrepareMap map[string]*sql.Stmt
}
func (s *Stmt) Prepare(db *sqlx.DB, tx *sql.Tx, SQL string) (statement *sql.Stmt, err error) {
	if config.PrestConf.EnableCache && (tx == nil) {
		var exists bool
		s.Mtx.Lock()
		statement, exists = s.PrepareMap[SQL]
		s.Mtx.Unlock()
		if exists {
			return
		}
	}
	if tx != nil {
		statement, err = tx.Prepare(SQL)
	} else {
		statement, err = db.Prepare(SQL)
	}
	if err != nil {
		return
	}
	if config.PrestConf.EnableCache && (tx == nil) {
		s.Mtx.Lock()
		s.PrepareMap[SQL] = statement
		s.Mtx.Unlock()
	}
	return
}
func Load() {
	config.PrestConf.Adapter = &Postgres{}
	db, err := connection.Get()
	if err != nil {
		log.Fatal(err)
	}
	err = db.Ping()
	if err != nil {
		log.Fatal(err)
	}
}
func init() {
	removeOperatorRegex = regexp.MustCompile(`\$[a-z]+.`)
	insertTableNameRegex = regexp.MustCompile(`(?i)INTO\s+([\w|\.]*\.)*(\w+)\s*\(`)
	insertTableNameQuotesRegex = regexp.MustCompile(`(?i)INTO\s+([\w|\.|"]*\.)*"(\w+)"\s*\(`)
	groupRegex = regexp.MustCompile(`\"(.+?)\"`)
}
func GetStmt() *Stmt {
	if stmts == nil {
		stmts = &Stmt{
			Mtx:        &sync.Mutex{},
			PrepareMap: make(map[string]*sql.Stmt),
		}
	}
	return stmts
}
func ClearStmt() {
	if stmts != nil {
		stmts = nil
		stmts = GetStmt()
	}
}
func (adapter *Postgres) GetTransaction() (tx *sql.Tx, err error) {
	db, err := connection.Get()
	if err != nil {
		log.Println(err)
		return
	}
	tx, err = db.Begin()
	return
}
func Prepare(db *sqlx.DB, SQL string) (stmt *sql.Stmt, err error) {
	stmt, err = GetStmt().Prepare(db, nil, SQL)
	return
}