Skip to content
Closed

v3 #2

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c42503d
Reset
mdwhatcott Sep 12, 2025
7295811
v3
mdwhatcott Sep 12, 2025
258647a
Use SplitSeq
mdwhatcott Sep 12, 2025
5a0fb45
Named return values
mdwhatcott Sep 12, 2025
ae05c66
Integration test suite (in separate module). ⤵️
mdwhatcott Sep 15, 2025
5473d77
Return rows.Err as final result of BindAll func.
mdwhatcott Sep 15, 2025
c29b1a6
Export error normalization func.
mdwhatcott Sep 15, 2025
2a93c2c
Document NormalizeErr func.
mdwhatcott Sep 16, 2025
db2a63d
Function to bind an [optional] row.
mdwhatcott Sep 16, 2025
2353a55
Expand API with a DB that can execute 'Scripts' and 'Queries'. ⤵️
mdwhatcott Sep 17, 2025
85308b4
Context cancellation needs no stack trace.
mdwhatcott Sep 17, 2025
68e4cc4
Remove duplication.
mdwhatcott Sep 17, 2025
b61b897
Committing to (what is now called) the Handle interface.
mdwhatcott Sep 17, 2025
23e0e6f
Some notes.
mdwhatcott Sep 17, 2025
701a686
Define RowsAffected interface as optional hook for Script types.
mdwhatcott Sep 19, 2025
da27bd4
Tweak wording.
mdwhatcott Sep 19, 2025
7fa2a32
Intentionally defining contractual interfaces to be exported. ⤵️
mdwhatcott Sep 19, 2025
65a9e6e
Lower threshold to trigger use of prepared statements.
mdwhatcott Sep 19, 2025
5e155ba
Finesse the docs.
mdwhatcott Sep 19, 2025
fac6848
Base types, for convenience.
mdwhatcott Sep 19, 2025
6a62242
Store checksums of statements (smaller) and cap how many we will track.
mdwhatcott Sep 22, 2025
83afe83
go work sync
mdwhatcott Sep 22, 2025
b8b68ca
Include adapter code to ease migration from v2 to v3.
mdwhatcott Sep 23, 2025
87d1a7a
Variadic methods.
mdwhatcott Sep 23, 2025
a0fa880
Test interleaving of statements and parameters.
mdwhatcott Sep 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

test: fmt
GORACE="atexit_sleep_ms=50" go test -timeout=1s -race -covermode=atomic ./...
GORACE="atexit_sleep_ms=50" go test -count=1 github.com/smarty/sqldb/integration

fmt:
go fmt ./...
go mod tidy && go fmt ./...

compile:
go build ./...
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,56 @@
[![Code Coverage](https://codecov.io/gh/smarty/sqldb/branch/master/graph/badge.svg)](https://codecov.io/gh/smarty/sqldb)
[![Go Report Card](https://goreportcard.com/badge/github.com/smarty/sqldb)](https://goreportcard.com/report/github.com/smarty/sqldb)
[![GoDoc](https://godoc.org/github.com/smarty/sqldb?status.svg)](http://godoc.org/github.com/smarty/sqldb)


## Upgrading from v2 to v3

Those upgrading from v2 to v3 may be interested in the following code, which can be used to adapt write operations ('Scripts') to v3 while still using a v2-style interface:

```go
package mysql

import (
"context"

"github.com/smarty/sqldb/v3"
)

// Deprecated
type LegacyExecutor interface {
Execute(context.Context, string, ...any) (uint64, error)
}

// Deprecated
func newLegacyExecutor(handle sqldb.Handle) LegacyExecutor {
return &legacyExecutor{handle: handle}
}

// Deprecated
type legacyExecutor struct {
handle sqldb.Handle
}

// Deprecated
func (this *legacyExecutor) Execute(ctx context.Context, statement string, args ...any) (uint64, error) {
script := &rowCountScript{
BaseScript: sqldb.BaseScript{
Text: statement,
Args: args,
},
}
err := this.handle.Execute(ctx, script)
return script.rowsAffectedCount, err
}

// Deprecated
type rowCountScript struct {
sqldb.BaseScript
rowsAffectedCount uint64
}

// Deprecated
func (this *rowCountScript) RowsAffected(rowCount uint64) {
this.rowsAffectedCount += rowCount
}
```
29 changes: 29 additions & 0 deletions base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sqldb

// BaseScript is a bare-minimum implementation of Script.
type BaseScript struct {
Text string
Args []any
}

func (this BaseScript) Statements() string {
return this.Text
}
func (this BaseScript) Parameters() []any {
return this.Args
}

// BaseQuery is a bare-minium, partial implementation of Query.
// Users are invited to embed it on types that define a Scan method,
// thus completing the Query implementation.
type BaseQuery struct {
Text string
Args []any
}

func (this BaseQuery) Statement() string {
return this.Text
}
func (this BaseQuery) Parameters() []any {
return this.Args
}
41 changes: 0 additions & 41 deletions binding_connection_pool_adapter.go

This file was deleted.

87 changes: 0 additions & 87 deletions binding_connection_pool_adapter_test.go

This file was deleted.

37 changes: 0 additions & 37 deletions binding_selector_adapter.go

This file was deleted.

106 changes: 0 additions & 106 deletions binding_selector_adapter_test.go

This file was deleted.

19 changes: 0 additions & 19 deletions binding_transaction_adapter.go

This file was deleted.

Loading