Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v7.0.1

- uses: jdx/mise-action@v5.1.2
- uses: jdx/mise-action@v5.2.7

- name: mise run check
run: mise run check
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fi

- name: Create GitHub Release
uses: taiki-e/create-gh-release-action@v1.11.0
uses: taiki-e/create-gh-release-action@v1.12.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
changelog: ${{ steps.module.outputs.changelog }}
Expand Down
68 changes: 67 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,71 @@ module only; the `postgres` and `sqlint` sub-modules each keep their own.

## [Unreleased]

## [v0.7.0] - 2026-11-11

A transaction's configuration is the standard library's `*sql.TxOptions`, passed as a trailing
argument, not variadic option functions: `DB.Begin`, `DB.Transact`, and `Transact` take it, and
nil keeps a default transaction.

### Changed

- **Breaking:** `DB.Begin(ctx, opts)` takes a `*sql.TxOptions` in place of variadic `TxOption`
values. Nil opens a default transaction; a non-nil value's `Isolation` and `ReadOnly` reach
the driver.
- **Breaking:** `DB.Transact(ctx, fn, opts)` and `Transact(ctx, b, fn, opts)` take a required
trailing `*sql.TxOptions` in place of variadic `TxOption` values. A call with no option
passes nil.
- **Breaking:** `Beginner.Begin` has `DB.Begin`'s new signature,
`Begin(ctx context.Context, opts *sql.TxOptions) (*Tx, error)`, so a type that implements
`Beginner` with its own `Begin` changes its signature. A type embedding `*DB` is unaffected.

### Removed

- **Breaking:** `TxOption` and the `Isolation` and `ReadOnly` option functions, with no
aliases. Set `sql.TxOptions.Isolation` and `sql.TxOptions.ReadOnly`.

### Migrating from v0.6.x

- **Options become one `*sql.TxOptions` value.** Pass nil for a default transaction.

```go
// v0.6.x
tx, err := db.Begin(ctx)
tx, err := db.Begin(ctx, sqlate.Isolation(sql.LevelSerializable))
tx, err := db.Begin(ctx, sqlate.Isolation(sql.LevelRepeatableRead), sqlate.ReadOnly())

// v0.7.0
tx, err := db.Begin(ctx, nil)
tx, err := db.Begin(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable})
tx, err := db.Begin(ctx, &sql.TxOptions{Isolation: sql.LevelRepeatableRead, ReadOnly: true})
```

- **`Transact` takes the options as its last argument.** A call that passed none passes nil.

```go
// v0.6.x
n, err := db.Transact(ctx, fn)
n, err := sqlate.Transact(ctx, b, fn, sqlate.ReadOnly())

// v0.7.0
n, err := db.Transact(ctx, fn, nil)
n, err := sqlate.Transact(ctx, b, fn, &sql.TxOptions{ReadOnly: true})
```

- **A `Beginner` implementer's `Begin` takes `*sql.TxOptions`.** Pass the value on unchanged.

```go
// v0.6.x
func (a *AppDB) Begin(ctx context.Context, opts ...sqlate.TxOption) (*sqlate.Tx, error) {
return a.DB.Begin(ctx, opts...)
}

// v0.7.0
func (a *AppDB) Begin(ctx context.Context, opts *sql.TxOptions) (*sqlate.Tx, error) {
return a.DB.Begin(ctx, opts)
}
```

## [v0.6.1] - 2026-10-15

### Fixed
Expand Down Expand Up @@ -217,7 +282,8 @@ experiment's library packages.
- `sqltest`, the scripted `database/sql` driver every consumer's unit tier runs over: `Open`,
`Recorder`, `Response`, and the stub `Dialect`.

[Unreleased]: https://github.com/standards-lab/sqlate/compare/v0.6.1...HEAD
[Unreleased]: https://github.com/standards-lab/sqlate/compare/v0.7.0...HEAD
[v0.7.0]: https://github.com/standards-lab/sqlate/compare/v0.6.1...v0.7.0
[v0.6.1]: https://github.com/standards-lab/sqlate/compare/v0.6.0...v0.6.1
[v0.6.0]: https://github.com/standards-lab/sqlate/compare/v0.5.0...v0.6.0
[v0.5.0]: https://github.com/standards-lab/sqlate/compare/v0.4.1...v0.5.0
Expand Down
1 change: 1 addition & 0 deletions STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The judgement calls the standards-reviewer applies to sqlate, beyond what `mise
- `architecture/standards/go-elemental/principles/dsl-driven-services.md`: `query`, `header`, and every authored `.sql` file, the library's patterns included.
- `architecture/standards/go-elemental/principles/baseline-standards.md`: `query`'s guards and projections, which take every name and bound from their caller.
- `architecture/standards/go-elemental/principles/utc-times.md`: `query.Scanner` and `query.Scalar`, which return every time in UTC, a cursor's keyed time, and the `postgres` dialect's `timestamp with time zone` history.
- `architecture/standards/go-elemental/principles/construction-and-execution.md`: `DB.Begin`, `DB.Transact`, and `Transact` take their transaction's configuration as a trailing `*sql.TxOptions` whose nil keeps a default transaction, and a new runner that takes configuration does the same.
- `architecture/principles/service-tiers.md`: the `Dialect` boundary between the base module and each engine sub-module.
- `architecture/principles/tool-beside-library.md`: the `sqlint` package and its command.
- `architecture/principles/validation-first.md`: authored SQL, `sqlint.Load` and `migrate.New`.
Expand Down
3 changes: 2 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
// [Session] is the method set the query and migrate packages take,
// implemented by both [DB] and [Tx], so the same statement runs against the
// pool or inside a transaction. The consumer owns the transaction boundary:
// [DB.Begin] opens a [Tx] with [TxOption] values applied, and [DB.Transact]
// [DB.Begin] opens a [Tx] with the standard library's
// [database/sql.TxOptions], nil for a default transaction, and [DB.Transact]
// runs one unit of work with a result: commit on success, rollback on the
// unit's error or panic; [Transact] is the same runner over any [Beginner].
// [Tx.Commit] routes its error through the dialect's MapError, the one place
Expand Down
20 changes: 11 additions & 9 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ dialect before returning it. `ErrorMapper` is the capability both expose for err
after a call returns, from `rows.Err` and `Scan`; the typed values use it, and a consumer
running raw SQL through a session can too.

**Transactions.** `DB.Begin(ctx, opts...)` opens a `*Tx` with `TxOption` values applied:
`Isolation(level)` and `ReadOnly()`. `Tx.Commit` maps its error, the one place a violation
deferred to `COMMIT` can be classified; `Tx.Rollback` does not. `DB.Transact(ctx, fn, opts...)`
is the runner: it begins, calls `fn(tx)`, commits on success, and returns `fn`'s result. On
**Transactions.** `DB.Begin(ctx, opts)` opens a `*Tx` with the standard library's
`*sql.TxOptions`: nil is a default transaction, and a non-nil value's `Isolation` and `ReadOnly`
reach the driver, as in `&sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: true}`.
`Tx.Commit` maps its error, the one place a violation deferred to `COMMIT` can be classified;
`Tx.Rollback` does not. `DB.Transact(ctx, fn, opts)` is the runner, taking the same trailing
options: it begins, calls `fn(tx)`, commits on success, and returns `fn`'s result. On
`fn`'s error it rolls back and returns that error with a rollback failure joined onto it. A
panic in `fn` rolls back and re-panics, so no transaction leaks to the pool. `Beginner` is the
interface of a session that can open a transaction, satisfied by `*DB` and any type embedding
it. A protocol handed a session rather than a transaction asserts `Beginner` to open its own.
`sqlate.Transact(ctx, b, fn, opts...)` is the same runner over any `Beginner`, so a protocol, or
an application's own pool type embedding `*DB`, runs its unit exactly as `DB.Transact` does;
`DB.Transact` is `Transact` over the `*DB`.
interface of a session that can open a transaction. Its `Begin` has `DB.Begin`'s signature, and
`*DB` and any type embedding it satisfy it. A protocol handed a session rather than a
transaction asserts `Beginner` to open its own. `sqlate.Transact(ctx, b, fn, opts)` is the same
runner over any `Beginner`, so a protocol, or an application's own pool type embedding `*DB`,
runs its unit exactly as `DB.Transact` does; `DB.Transact` is `Transact` over the `*DB`.

**Pinned connections.** `DB.Conn(ctx)` pins one connection for a protocol that needs session
scope: a session-level lock, or DDL an engine refuses inside a transaction. The caller closes
Expand Down
7 changes: 4 additions & 3 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (s *Store) Seed(ctx context.Context, rows []SeedTeam) (int64, error) {
inserted += n
}
return inserted, nil
})
}, nil)
}

// Create validates the command and runs it; the result is the new row's
Expand Down Expand Up @@ -619,7 +619,7 @@ func (s *Store) Replace(ctx context.Context, id string, version int64, t NewTeam
return Identity{}, err
}
return s.create.One(ctx, tx, query.ArgsOf(t))
})
}, nil)
}
```

Expand All @@ -638,7 +638,8 @@ func (s *Store) Replace(ctx context.Context, id string, version int64, t NewTeam
- `Rename` validates, then runs the guarded command with the version the caller read and
returns the new one; `With` adds the id the command needs beside the command's own fields.
- `Replace` runs two commands as one unit of work: `Transact` commits on success and rolls back
on error or panic.
on error or panic. Its last argument is the transaction's `*sql.TxOptions`; nil is a default
transaction, and `&sql.TxOptions{Isolation: sql.LevelSerializable}` would run it serializable.

## 9. Test without a database

Expand Down
4 changes: 2 additions & 2 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tools]
go = "1.27.2"
golangci-lint = "2.14.0"
go = "1.27.4"
golangci-lint = "2.15.0"
jq = "1.8.2"
"aqua:google/go-containerregistry" = "0.22.1"

Expand Down
18 changes: 17 additions & 1 deletion postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ changelog covers this sub-module only; the base module keeps its own.

## [Unreleased]

## [v0.7.0] - 2026-11-11

### Changed

- **Breaking:** The `sqlate` requirement is v0.7.0, whose `DB.Begin`, `DB.Transact`, and
`Transact` take a `*sql.TxOptions` (nil for a default transaction) in place of the variadic
`TxOption`, and whose `Beginner` has `DB.Begin`'s signature. A module that requires this
release builds against it, so code calling those methods moves to the new form: drop
`sqlate.Isolation(level)` and `sqlate.ReadOnly()`, pass
`&sql.TxOptions{Isolation: level, ReadOnly: true}` or nil instead, and give `Transact` that
trailing argument. The dialect's own API is unchanged.
- The live proofs' counting session implements the new `Beginner`.

Requires `github.com/standards-lab/sqlate v0.7.0`.

## [v0.6.0] - 2026-10-15

### Added
Expand Down Expand Up @@ -112,7 +127,8 @@ The first release of the PostgreSQL dialect, against `github.com/standards-lab/s
- The integration tier: the migrate and query proofs against a live engine, behind the
`integration` build tag.

[Unreleased]: https://github.com/standards-lab/sqlate/compare/postgres/v0.6.0...HEAD
[Unreleased]: https://github.com/standards-lab/sqlate/compare/postgres/v0.7.0...HEAD
[v0.7.0]: https://github.com/standards-lab/sqlate/compare/postgres/v0.6.0...postgres/v0.7.0
[v0.6.0]: https://github.com/standards-lab/sqlate/compare/postgres/v0.5.0...postgres/v0.6.0
[v0.5.0]: https://github.com/standards-lab/sqlate/compare/postgres/v0.4.0...postgres/v0.5.0
[v0.4.0]: https://github.com/standards-lab/sqlate/compare/postgres/v0.3.0...postgres/v0.4.0
Expand Down
10 changes: 5 additions & 5 deletions postgres/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/standards-lab/sqlate/postgres
go 1.27

require (
github.com/jackc/pgx/v5 v5.11.0
github.com/standards-lab/sqlate v0.6.0
github.com/jackc/pgx/v5 v5.13.0
github.com/standards-lab/sqlate v0.6.1
)

require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/text v0.29.0 // indirect
github.com/jackc/puddle/v2 v2.2.3 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/text v0.41.0 // indirect
)
20 changes: 10 additions & 10 deletions postgres/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg=
github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jackc/pgx/v5 v5.13.0 h1:Hl08k64maU0nrRyVUEbwCnK6/gT0EhMrtAqBHz9/gA4=
github.com/jackc/pgx/v5 v5.13.0/go.mod h1:u2Fi6no03HCSBYE+ZVdLxbwdu3xyi2vU+K/YNJioSds=
github.com/jackc/puddle/v2 v2.2.3 h1:f8HoREISb3l5eO9coPgK7U3hKLhWGokOFVcThl5jrao=
github.com/jackc/puddle/v2 v2.2.3/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/standards-lab/sqlate v0.6.0 h1:QdSuEo7sPamge38X3vocTRc6mvMthJWJhKtDcpyYyLw=
github.com/standards-lab/sqlate v0.6.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4=
github.com/standards-lab/sqlate v0.6.1 h1:Kgp8freMX9Gs2KweBwG4IPzENgUmSJq8+r4tq02cDNw=
github.com/standards-lab/sqlate v0.6.1/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
6 changes: 3 additions & 3 deletions postgres/returning_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func (c *counted) QueryContext(ctx context.Context, q string, args ...any) (*sql
return c.DB.QueryContext(ctx, q, args...)
}

func (c *counted) Begin(ctx context.Context, opts ...sqlate.TxOption) (*sqlate.Tx, error) {
func (c *counted) Begin(ctx context.Context, opts *sql.TxOptions) (*sqlate.Tx, error) {
c.begin++
return c.DB.Begin(ctx, opts...)
return c.DB.Begin(ctx, opts)
}

// calls is what one scenario cost: the session's calls and the engine's
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestLive_ReturningInsideACallersTransaction(t *testing.T) {
return row, fmt.Errorf("retire again: %+v, changed %v: %w", row, changed, err)
}
return row, nil
})
}, nil)
sent := tr.take()
if err != nil {
t.Errorf("%s: Transact: %v", f.name, err)
Expand Down
2 changes: 1 addition & 1 deletion query/returning.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (r Returning[T]) One(ctx context.Context, s sqlate.Session, args Args) (T,
out, err := sqlate.Transact(ctx, s, func(tx *sqlate.Tx) (changedRow[T], error) {
row, changed, err := r.fallback(ctx, tx, args)
return changedRow[T]{row: row, changed: changed}, err
})
}, nil)
return out.row, out.changed, err
}
return zero, false, ErrTransactionRequired
Expand Down
2 changes: 1 addition & 1 deletion query/returning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func TestReturningOne_InsideATransactionOpensNone(t *testing.T) {
pool, rec := sqltest.Open(t, script...)
db := sqlate.Wrap(pool, f.dialect)
r := rename(t, f.dialect)
tx, err := db.Begin(ctx)
tx, err := db.Begin(ctx, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion query/rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestExec_TransactionRequired(t *testing.T) {
_, err := db.Transact(ctx, func(tx *sqlate.Tx) (struct{}, error) {
_, err := lock.Exec(ctx, tx, query.Args{"key": int64(1)})
return struct{}{}, err
})
}, nil)
if err != nil {
t.Errorf("Exec in a transaction: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ type TryLocker interface {
// Beginner is a session that can open a transaction: *DB, and any type that
// embeds it. A protocol that must run several statements as one unit, and
// is handed a session rather than a transaction, asserts it to open its own.
// Begin has DB.Begin's signature: nil opts opens a default transaction.
type Beginner interface {
Begin(ctx context.Context, opts ...TxOption) (*Tx, error)
Begin(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
}

var _ Beginner = (*DB)(nil)
Expand Down
Loading
Loading