Skip to content

Commit bf1892b

Browse files
authored
edit SQLite documentation and transaction example (#621)
Minor finishing touches to give the documentation a sense of completion. Fix one major error in transaction example: Rollback was deferred instead of Commit.
1 parent 59e2681 commit bf1892b

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

‎_examples/pubsubs/sqlite/transaction.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ import (
1010
)
1111

1212
func publishWithInTransaction(db *sql.DB) {
13-
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{Isolation: sql.LevelReadCommitted})
13+
tx, err := db.BeginTx(context.Background(), &sql.TxOptions{
14+
Isolation: sql.LevelReadCommitted,
15+
})
1416
if err != nil {
1517
panic(err)
1618
}
1719
defer func() {
18-
_ = tx.Rollback()
20+
_ = tx.Commit()
1921
}()
2022

2123
publisher, err := wmsqlitemodernc.NewPublisher(
22-
tx,
24+
tx, // transaction presented as database
2325
wmsqlitemodernc.PublisherOptions{
2426
// schema must be initialized elsewhere before using
2527
// the publisher within the transaction

‎docs/content/pubsubs/sqlite.md‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ SQLite Pub/Subs provide the easiest way to publish and process events durably, s
1414

1515
You can find a fully functional example with SQLite in the [Watermill examples](https://github.com/ThreeDotsLabs/watermill/tree/master/_examples/pubsubs/sqlite).
1616

17-
## Vanilla ModernC Driver vs Advanced ZombieZen Driver
17+
## ModernC vs ZombieZen Driver
1818

19-
The **ModernC driver** is compatible with the Golang standard library SQL package and works without CGO. It has fewer dependencies than the ZombieZen variant and uses the `modernc.org/sqlite` pure Go SQLite implementation.
19+
The vanilla **ModernC driver** is compatible with the Golang standard library SQL package and works without CGO. It has fewer dependencies than the ZombieZen variant and uses the `modernc.org/sqlite` pure Go SQLite implementation. Most users should pick this driver for full compatibility with the standard library.
2020

21-
The **ZombieZen driver** abandons the standard Golang library SQL conventions in favor of [the more orthogonal API and higher performance potential](https://crawshaw.io/blog/go-and-sqlite). Under the hood, it also uses the ModernC SQLite3 implementation and does not need CGO. Advanced SQLite users might prefer this driver for its performance benefits.
22-
It is about **6 times faster** than the ModernC variant. It is currently more stable due to lower level control. It is faster than even the CGO SQLite variants on standard library interfaces, and with some tuning should become the absolute speed champion of persistent message brokers over time.
21+
The advanced **ZombieZen driver** abandons the standard Golang library SQL conventions in favor of [the more orthogonal API and higher performance potential](https://crawshaw.io/blog/go-and-sqlite). Under the hood, it also uses the ModernC SQLite3 implementation and does not need CGO. Advanced SQLite users might prefer this driver for its performance benefits. It is about **6 times faster** than the ModernC variant. It is currently more stable due to lower level control. It is faster than even the CGO SQLite variants on standard library interfaces, and with some tuning should become the absolute speed champion of persistent message brokers over time.
2322

2423
### Characteristics
2524

@@ -30,6 +29,8 @@ It is about **6 times faster** than the ModernC variant. It is currently more st
3029
| GuaranteedOrder | yes | |
3130
| Persistent | yes | |
3231

32+
Like the [BoltDB](../bolt/) implementation, the SQLite drivers are imbeddable into your application. They do not require any additional infrastructure other than a mounted persistent disk. Their advantage over the BoltDB Pub/Sub is supporting consumer groups and guaranteed order.
33+
3334
## Vanilla ModernC Driver
3435

3536
### Installation
@@ -127,11 +128,6 @@ The default marshaler handles:
127128

128129
Both drivers automatically handle message marshaling and unmarshaling, so no custom marshaler configuration is typically required.
129130

130-
## Similar Projects
131-
132-
- <https://github.com/davidroman0O/watermill-comfymill>
133-
- <https://github.com/walterwanderley/watermill-sqlite>
134-
135131
## Caveats
136132

137133
SQLite3 does not support querying `FOR UPDATE`, which is used for row locking when subscribers in the same consumer group read an event batch in official Watermill SQL PubSub implementations. Current architectural decision is to lock a consumer group offset using `unixepoch()+lockTimeout` time stamp. While one consumed message is processing per group, the offset lock time is extended by `lockTimeout` periodically by `time.Ticker`. If the subscriber is unable to finish the consumer group batch, other subscribers will take over the lock as soon as the grace period runs out. A time lock fulfills the role of a traditional database network timeout that terminates transactions when its client disconnects.

0 commit comments

Comments
 (0)