mirror of https://github.com/VinGarcia/ksql.git
Remove deprecated constructors ksql.New() and ksql.NewWithPgx()
It's recommended to use instead one of: - kpgx.New(ctx, connURL, ksql.Config{}) - kmysql.New(ctx, connURL, ksql.Config{}) - ksqlserver.New(ctx, connURL, ksql.Config{}) - ksqlite3.New(ctx, connURL, ksql.Config{})pull/16/head
parent
d98cf857c0
commit
1e282717b7
53
ksql.go
53
ksql.go
|
@ -2,13 +2,11 @@ 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"
|
||||
)
|
||||
|
@ -84,57 +82,6 @@ func (c *Config) SetDefaultValues() {
|
|||
}
|
||||
}
|
||||
|
||||
// New instantiates a new KissSQL client
|
||||
func New(
|
||||
dbDriver string,
|
||||
connectionString string,
|
||||
config Config,
|
||||
) (DB, error) {
|
||||
config.SetDefaultValues()
|
||||
|
||||
db, err := sql.Open(dbDriver, connectionString)
|
||||
if err != nil {
|
||||
return DB{}, err
|
||||
}
|
||||
if err = db.Ping(); err != nil {
|
||||
return DB{}, err
|
||||
}
|
||||
|
||||
db.SetMaxOpenConns(config.MaxOpenConns)
|
||||
|
||||
return NewWithAdapter(SQLAdapter{db}, dbDriver)
|
||||
}
|
||||
|
||||
// NewWithPGX instantiates a new ksql client using the pgx
|
||||
// library in the backend
|
||||
//
|
||||
// deprecated: use kpgx.New() instead
|
||||
func NewWithPGX(
|
||||
ctx context.Context,
|
||||
connectionString string,
|
||||
config Config,
|
||||
) (db DB, err error) {
|
||||
config.SetDefaultValues()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// NewWithAdapter allows the user to insert a custom implementation
|
||||
// of the DBAdapter interface
|
||||
func NewWithAdapter(
|
||||
|
|
|
@ -679,13 +679,14 @@ func TestInsert(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Using columns "id" and "name" as IDs:
|
||||
table := NewTable("users", "id", "name")
|
||||
|
||||
c, err := New(config.driver, connectionString[config.driver], Config{})
|
||||
assert.Equal(t, nil, err)
|
||||
db, closer := connectDB(t, config)
|
||||
defer closer.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
c := newTestDB(db, config.driver)
|
||||
|
||||
u := User{
|
||||
Name: "No ID returned",
|
||||
|
|
Loading…
Reference in New Issue