func NewWithAdapter(
	db DBAdapter,
	dbDriver string,
) (DB, error) {
	dialect := supportedDialects[dbDriver]
	if dialect == nil {
		return DB{}, fmt.Errorf("unsupported driver `%s`", dbDriver)
	}
	return DB{
		dialect: dialect,
		driver:  dbDriver,
		db:      db,
	}, nil
}
NewWithAdapter allows the user to insert a custom implementation
of the DBAdapter interface
package ksql
import (
	"context"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"unicode"
	"github.com/jackc/pgx/v4/pgxpool"
	"github.com/pkg/errors"
	"github.com/vingarcia/ksql/kstructs"
)
var selectQueryCache = map[string]map[reflect.Type]string{}
func init() {
	for dname := range supportedDialects {
		selectQueryCache[dname] = map[reflect.Type]string{}
	}
}
type DB struct {
	driver  string
	dialect Dialect
	db      DBAdapter
}
type DBAdapter interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
}
type TxBeginner interface {
	BeginTx(ctx context.Context) (Tx, error)
}
type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}
type Rows interface {
	Scan(...interface{}) error
	Close() error
	Next() bool
	Err() error
	Columns() ([]string, error)
}
type Tx interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	Rollback(ctx context.Context) error
	Commit(ctx context.Context) error
}
type Config struct {
	MaxOpenConns int
}
func New(
	dbDriver string,
	connectionString string,
	config Config,
) (DB, error) {
	db, err := sql.Open(dbDriver, connectionString)
	if err != nil {
		return DB{}, err
	}
	if err = db.Ping(); err != nil {
		return DB{}, err
	}
	if config.MaxOpenConns == 0 {
		config.MaxOpenConns = 1
	}
	db.SetMaxOpenConns(config.MaxOpenConns)
	return NewWithAdapter(SQLAdapter{db}, dbDriver)
}
func NewWithPGX(
	ctx context.Context,
	connectionString string,
	config Config,
) (db DB, err error) {
	pgxConf, err := pgxpool.ParseConfig(connectionString)
	if err != nil {
		return DB{}, err
	}
	pgxConf.MaxConns = int32(config.MaxOpenConns)
	pool, err := pgxpool.ConnectConfig(ctx, pgxConf)
	if err != nil {
		return DB{}, err
	}
	if err = pool.Ping(ctx); err != nil {
		return DB{}, err
	}
	db, err = NewWithAdapter(NewPGXAdapter(pool), "postgres")
	return db, err
}