Fix benchmarks submodule

pull/14/head
Vinícius Garcia 2022-03-15 19:41:34 -03:00
parent 9b7e5ddfbc
commit b6986e5fd1
4 changed files with 76 additions and 3 deletions

View File

@ -36,7 +36,7 @@ func BenchmarkInsert(b *testing.B) {
b.Fatalf("error connecting to database: %s", err)
}
db.SetMaxOpenConns(1)
ksqlDB, err := ksql.NewWithAdapter(ksql.NewSQLAdapter(db), driver)
ksqlDB, err := ksql.NewWithAdapter(NewSQLAdapter(db), driver)
if err != nil {
b.Fatalf("error creating ksql client: %s", err)
}
@ -292,7 +292,7 @@ func BenchmarkQuery(b *testing.B) {
b.Fatalf("error connecting to database: %s", err)
}
db.SetMaxOpenConns(1)
ksqlDB, err := ksql.NewWithAdapter(ksql.NewSQLAdapter(db), driver)
ksqlDB, err := ksql.NewWithAdapter(NewSQLAdapter(db), driver)
if err != nil {
b.Fatalf("error creating ksql client: %s", err)
}

View File

@ -7,8 +7,12 @@ require (
github.com/jmoiron/sqlx v1.3.4
github.com/lib/pq v1.10.4
github.com/vingarcia/ksql v1.1.0
github.com/vingarcia/ksql/adapters/kpgx v0.0.0-00010101000000-000000000000 // indirect
gorm.io/driver/postgres v1.2.2
gorm.io/gorm v1.22.3
)
replace github.com/vingarcia/ksql => ../
replace (
github.com/vingarcia/ksql => ../
github.com/vingarcia/ksql/adapters/kpgx => ../adapters/kpgx/
)

View File

@ -8,6 +8,7 @@ github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpz
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.2 h1:6Yo7N8UP2K6LWZnW94DLVSSrbobcWdVzAYOisuDPIFo=
github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d89JlCLQIfgVcNsNN0t6T2M=
@ -164,6 +165,7 @@ github.com/opencontainers/runc v1.0.2 h1:opHZMaswlyxz1OuGpBE53Dwe4/xF7EZTY0A2L/F
github.com/opencontainers/runc v1.0.2/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04suvGRQFzWTD0=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xAPP8dBsCoU0KuF8=
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
github.com/ory/dockertest/v3 v3.8.1 h1:vU/8d1We4qIad2YM0kOwRVtnyue7ExvacPiw1yDm17g=
github.com/ory/dockertest/v3 v3.8.1/go.mod h1:wSRQ3wmkz+uSARYMk7kVJFDBGm8x5gSxIhI7NDc+BAQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

67
benchmarks/sql_adapter.go Normal file
View File

@ -0,0 +1,67 @@
package benchmarks
import (
"context"
"database/sql"
"github.com/vingarcia/ksql"
)
// SQLAdapter adapts the sql.DB type to be compatible with the `DBAdapter` interface
type SQLAdapter struct {
*sql.DB
}
var _ ksql.DBAdapter = SQLAdapter{}
// NewSQLAdapter returns a new instance of SQLAdapter with
// the provided database instance.
func NewSQLAdapter(db *sql.DB) SQLAdapter {
return SQLAdapter{
DB: db,
}
}
// ExecContext implements the DBAdapter interface
func (s SQLAdapter) ExecContext(ctx context.Context, query string, args ...interface{}) (ksql.Result, error) {
return s.DB.ExecContext(ctx, query, args...)
}
// QueryContext implements the DBAdapter interface
func (s SQLAdapter) QueryContext(ctx context.Context, query string, args ...interface{}) (ksql.Rows, error) {
return s.DB.QueryContext(ctx, query, args...)
}
// BeginTx implements the Tx interface
func (s SQLAdapter) BeginTx(ctx context.Context) (ksql.Tx, error) {
tx, err := s.DB.BeginTx(ctx, nil)
return SQLTx{Tx: tx}, err
}
// SQLTx is used to implement the DBAdapter interface and implements
// the Tx interface
type SQLTx struct {
*sql.Tx
}
// ExecContext implements the Tx interface
func (s SQLTx) ExecContext(ctx context.Context, query string, args ...interface{}) (ksql.Result, error) {
return s.Tx.ExecContext(ctx, query, args...)
}
// QueryContext implements the Tx interface
func (s SQLTx) QueryContext(ctx context.Context, query string, args ...interface{}) (ksql.Rows, error) {
return s.Tx.QueryContext(ctx, query, args...)
}
// Rollback implements the Tx interface
func (s SQLTx) Rollback(ctx context.Context) error {
return s.Tx.Rollback()
}
// Commit implements the Tx interface
func (s SQLTx) Commit(ctx context.Context) error {
return s.Tx.Commit()
}
var _ ksql.Tx = SQLTx{}