summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-07-31 21:39:56 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-07-31 23:35:23 +0200
commit656e5dcce132716b39005814407224f989aa8c2d (patch)
treeab0a6d3a046170f0ace6a6e4ab3668ce0af811ae /benchmark
parenta2f8d7a68f324d5b4086148571f990409425e22a (diff)
downloadgo-oblast-656e5dcce132716b39005814407224f989aa8c2d.tar.gz
replace types Handle, DB, Conn, Tx with their gg/gsql equivalents
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/benchmark_test.go5
-rw-r--r--benchmark/internal/oblast_pgx/handle.go14
-rw-r--r--benchmark/internal/oblast_pgx/results.go14
-rw-r--r--benchmark/internal/oblast_pgx/statement.go18
-rw-r--r--benchmark/postgres_test.go9
5 files changed, 31 insertions, 29 deletions
diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go
index a3e32f7..4549962 100644
--- a/benchmark/benchmark_test.go
+++ b/benchmark/benchmark_test.go
@@ -15,6 +15,7 @@ import (
"github.com/go-gorp/gorp/v3"
_ "github.com/mattn/go-sqlite3"
"go.xyrillian.de/gg/assert"
+ "go.xyrillian.de/gg/gsql"
"go.xyrillian.de/oblast"
"go.xyrillian.de/oblast/internal/testhelpers/must"
"gorm.io/driver/sqlite"
@@ -43,9 +44,9 @@ var (
batchSizesForUpdate = []int{1, 2, 4, 8, 16, 100}
)
-func makeSqliteTestDB(t testing.TB, recordCount int) (db *oblast.DB, dsn string) {
+func makeSqliteTestDB(t testing.TB, recordCount int) (db *gsql.DB, dsn string) {
dsn = fmt.Sprintf("file:%s?mode=memory&cache=shared", t.Name())
- db = oblast.NewDB(must.Return(sql.Open("sqlite3", dsn))(t))
+ db = gsql.NewDB(must.Return(sql.Open("sqlite3", dsn))(t))
_ = must.Return(db.Exec(`CREATE TABLE entries (id INTEGER, message TEXT, PRIMARY KEY (id AUTOINCREMENT))`))(t)
if recordCount > 0 {
diff --git a/benchmark/internal/oblast_pgx/handle.go b/benchmark/internal/oblast_pgx/handle.go
index 845fbe4..4bd72bd 100644
--- a/benchmark/internal/oblast_pgx/handle.go
+++ b/benchmark/internal/oblast_pgx/handle.go
@@ -12,7 +12,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
- "go.xyrillian.de/oblast/handle"
+ "go.xyrillian.de/gg/gsql"
)
type Handle interface {
@@ -27,7 +27,7 @@ var (
_ Handle = pgx.Tx(&pgxpool.Tx{})
)
-func Wrap(h Handle) handle.Handle {
+func Wrap(h Handle) gsql.Handle {
switch h := h.(type) {
case *pgx.Conn:
return wrappedHandle{h}
@@ -46,8 +46,8 @@ type wrappedHandle struct {
inner Handle
}
-// OblastPrepare implements the [handle.Handle] interface.
-func (h wrappedHandle) OblastPrepare(ctx context.Context, query string, repeated bool) (handle.Statement, error) {
+// GSQLPrepare implements the [gsql.Handle] interface.
+func (h wrappedHandle) GSQLPrepare(ctx context.Context, query string, repeated bool) (gsql.Statement, error) {
if !repeated {
return wrappedUnpreparedStatement{query, h.inner}, nil
}
@@ -74,7 +74,7 @@ func deallocate(ctx context.Context, h Handle, stmt *pgconn.StatementDescription
case *pgx.Conn:
return h.Deallocate(ctx, stmt.Name)
case *pgxpool.Conn:
- panic("unreachable") // because func OblastPrepare() does not return a wrappedPreparedStatement for this underlying type
+ panic("unreachable") // because func GSQLPrepare() does not return a wrappedPreparedStatement for this underlying type
case pgx.Tx:
return h.Conn().Deallocate(ctx, stmt.Name)
default:
@@ -82,8 +82,8 @@ func deallocate(ctx context.Context, h Handle, stmt *pgconn.StatementDescription
}
}
-// OblastQuery implements the [handle.Handle] interface.
-func (h wrappedHandle) OblastQuery(ctx context.Context, query string, args []any) (handle.Rows, error) {
+// GSQLQuery implements the [gsql.Handle] interface.
+func (h wrappedHandle) GSQLQuery(ctx context.Context, query string, args []any) (gsql.Rows, error) {
rows, err := h.inner.Query(ctx, query, args...)
return wrappedRows{rows}, err
}
diff --git a/benchmark/internal/oblast_pgx/results.go b/benchmark/internal/oblast_pgx/results.go
index 3ccb5ce..f842d36 100644
--- a/benchmark/internal/oblast_pgx/results.go
+++ b/benchmark/internal/oblast_pgx/results.go
@@ -9,16 +9,16 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
- "go.xyrillian.de/oblast/handle"
+ "go.xyrillian.de/gg/gsql"
)
type wrappedRows struct {
inner pgx.Rows
}
-var _ handle.Rows = wrappedRows{}
+var _ gsql.Rows = wrappedRows{}
-// Columns implements the [handle.Rows] interface.
+// Columns implements the [gsql.Rows] interface.
func (r wrappedRows) Columns() ([]string, error) {
descriptions := r.inner.FieldDescriptions()
result := make([]string, len(descriptions))
@@ -28,23 +28,23 @@ func (r wrappedRows) Columns() ([]string, error) {
return result, nil
}
-// Close implements the [handle.Rows] interface.
+// Close implements the [gsql.Rows] interface.
func (r wrappedRows) Close() error {
r.inner.Close()
return nil
}
-// Err implements the [handle.Rows] interface.
+// Err implements the [gsql.Rows] interface.
func (r wrappedRows) Err() error {
return r.inner.Err()
}
-// Next implements the [handle.Rows] interface.
+// Next implements the [gsql.Rows] interface.
func (r wrappedRows) Next() bool {
return r.inner.Next()
}
-// Scan implements the [handle.Rows] interface.
+// Scan implements the [gsql.Rows] interface.
func (r wrappedRows) Scan(args ...any) error {
return r.inner.Scan(args...)
}
diff --git a/benchmark/internal/oblast_pgx/statement.go b/benchmark/internal/oblast_pgx/statement.go
index d81c579..0a33c73 100644
--- a/benchmark/internal/oblast_pgx/statement.go
+++ b/benchmark/internal/oblast_pgx/statement.go
@@ -8,7 +8,7 @@ import (
"database/sql"
"github.com/jackc/pgx/v5/pgconn"
- "go.xyrillian.de/oblast/handle"
+ "go.xyrillian.de/gg/gsql"
)
type wrappedPreparedStatement struct {
@@ -23,38 +23,38 @@ type wrappedUnpreparedStatement struct {
}
var (
- _ handle.Statement = wrappedPreparedStatement{}
- _ handle.Statement = wrappedUnpreparedStatement{}
+ _ gsql.Statement = wrappedPreparedStatement{}
+ _ gsql.Statement = wrappedUnpreparedStatement{}
)
-// Close implements the [handle.Statement] interface.
+// Close implements the [gsql.Statement] interface.
func (s wrappedPreparedStatement) Close() error {
return deallocate(s.ctx, s.handle, s.statement)
}
-// Close implements the [handle.Statement] interface.
+// Close implements the [gsql.Statement] interface.
func (s wrappedUnpreparedStatement) Close() error {
return nil
}
-// Exec implements the [handle.Statement] interface.
+// Exec implements the [gsql.Statement] interface.
func (s wrappedPreparedStatement) Exec(ctx context.Context, args []any) (sql.Result, error) {
result, err := s.handle.Exec(ctx, s.statement.Name, args...)
return wrappedResult{result}, err
}
-// Exec implements the [handle.Statement] interface.
+// Exec implements the [gsql.Statement] interface.
func (s wrappedUnpreparedStatement) Exec(ctx context.Context, args []any) (sql.Result, error) {
result, err := s.handle.Exec(ctx, s.query, args...)
return wrappedResult{result}, err
}
-// QueryRow implements the [handle.Statement] interface.
+// QueryRow implements the [gsql.Statement] interface.
func (s wrappedPreparedStatement) QueryRow(ctx context.Context, args, slots []any) error {
return s.handle.QueryRow(ctx, s.statement.Name, args...).Scan(slots...)
}
-// QueryRow implements the [handle.Statement] interface.
+// QueryRow implements the [gsql.Statement] interface.
func (s wrappedUnpreparedStatement) QueryRow(ctx context.Context, args, slots []any) error {
return s.handle.QueryRow(ctx, s.query, args...).Scan(slots...)
}
diff --git a/benchmark/postgres_test.go b/benchmark/postgres_test.go
index a5957f7..dba7ca8 100644
--- a/benchmark/postgres_test.go
+++ b/benchmark/postgres_test.go
@@ -16,6 +16,7 @@ import (
"github.com/jackc/pgx/v5"
_ "github.com/lib/pq"
"go.xyrillian.de/gg/assert"
+ "go.xyrillian.de/gg/gsql"
"go.xyrillian.de/oblast"
"go.xyrillian.de/oblast/benchmark/internal/oblast_pgx"
"go.xyrillian.de/oblast/internal/testhelpers/must"
@@ -36,9 +37,9 @@ func BenchmarkPostgresHeadingHeadingHeadingHeadingHeadingHeadingHeadingHeading(b
const defaultPostgresDSN = "host=localhost user=postgres dbname=oblast_benchmark sslmode=disable"
-func connectToPostgresTestDB(t testing.TB, recordCount int) *oblast.DB {
+func connectToPostgresTestDB(t testing.TB, recordCount int) *gsql.DB {
dsn := cmp.Or(os.Getenv("BENCHMARK_POSTGRES_DSN"), defaultPostgresDSN)
- db := oblast.NewDB(must.Return(sql.Open("postgres", dsn))(t))
+ db := gsql.NewDB(must.Return(sql.Open("postgres", dsn))(t))
_ = must.Return(db.Exec(`CREATE TEMPORARY TABLE entries (id BIGSERIAL, message TEXT)`))(t)
if recordCount > 0 {
@@ -204,7 +205,7 @@ func BenchmarkPostgresInsertAndDelete(b *testing.B) {
// test with different amounts of records
for _, batchSize := range batchSizesForInsertDelete {
b.Run("N="+strconv.Itoa(batchSize), func(b *testing.B) {
- insertAndDeleteWithOblast := func(b *testing.B, dbh oblast.Handle) {
+ insertAndDeleteWithOblast := func(b *testing.B, dbh gsql.Handle) {
records := make([]OblastEntry, batchSize)
recordsForInsert := make([]*OblastEntry, batchSize)
for idx := range records {
@@ -334,7 +335,7 @@ func BenchmarkPostgresUpdate(b *testing.B) {
}
}
- updateWithOblast := func(b *testing.B, dbh oblast.Handle, records []OblastEntry) func(string) {
+ updateWithOblast := func(b *testing.B, dbh gsql.Handle, records []OblastEntry) func(string) {
return func(message string) {
for idx := range records {
records[idx].Message = message