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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ defer db.Close()
#### Starting SQLite transactions

The `*LiteDB` returned by `Open` provides `StartRead` and `StartWrite` for
starting a read or write transaction. They make use of the `ReadConsistency`
and `WriteConsistency` package values to indicate isolation levels. A write
transaction must be ended with a call to `Commit`.
starting a read or write transaction. Each passes a `sql.TxOptions` value
(`ReadConsistency` or `WriteConsistency`) to `BeginTx`. The sqlite3 driver
does not implement transaction isolation levels, so the `Isolation` field is
ignored; effective isolation is determined by the connection's `_txlock` mode
(`deferred` for reads, `TransactionLock` for writes). A write transaction must
be ended with a call to `Commit`.

Read transactions use a pool of connections, and may be used concurrently.
They are restricted to reading; attempting to write using a read transaction
Expand Down
56 changes: 29 additions & 27 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,32 @@ type Configuration struct {
MaxConnectionsOpen int
}

// TypicalConfiguration should be suitable for use by most applications, such
// as web servers, api servers, and other general purpose scenarios. In
// particular it sets these parameter values:
//
// - encoding: utf8
// - journal_mode: WAL
// - foreign_keys: true
// - transaction_lock: immediate
// - auto_vacuum: incremental
// - synchronous: normal
// - cache_size: 16 megabytes per connection
// - mmap_size: 16 megabytes per connection
//
// Do not modify.
var TypicalConfiguration = &Configuration{
Mode: "rwc",
Encoding: "utf8",
BusyTimeout: 5000,
TransactionLock: "immediate",
ForeignKeys: true,
JournalMode: "WAL",
CacheSize: -16384,
AutoVacuum: "incremental",
Synchronous: "normal",
MemoryMapSize: 16777216,
MaxConnectionsOpen: 4,
}
var (
// TypicalConfiguration should be suitable for use by most applications, such
// as web servers, api servers, and other general purpose scenarios. In
// particular it sets these parameter values:
//
// - encoding: utf8
// - journal_mode: WAL
// - foreign_keys: true
// - transaction_lock: immediate
// - auto_vacuum: incremental
// - synchronous: normal
// - cache_size: 16 megabytes per connection
// - mmap_size: 16 megabytes per connection
//
// Do not modify.
TypicalConfiguration = &Configuration{
Mode: "rwc",
Encoding: "utf8",
BusyTimeout: 5000,
TransactionLock: "immediate",
ForeignKeys: true,
JournalMode: "WAL",
CacheSize: -16384,
AutoVacuum: "incremental",
Synchronous: "normal",
MemoryMapSize: 16777216,
MaxConnectionsOpen: 4,
}
)
2 changes: 1 addition & 1 deletion litesql.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
// This value has no effect.
ReadConsistency = &sql.TxOptions{
ReadOnly: true,
Isolation: sql.LevelReadCommitted,
Isolation: sql.LevelSnapshot,
}

// WriteConsistency provides options for general use transactional writes.
Expand Down
38 changes: 20 additions & 18 deletions litesqltest/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ import (
"cattlecloud.net/go/litesql"
)

// TestConfiguration provides PRAGMA settings appropriate for a database used
// in unit tests. This configuration uses a smaller page cache and disables
// memory-mapped I/O to keep resource usage low.
//
// Do not modify.
var TestConfiguration = &litesql.Configuration{
Mode: "rwc",
Encoding: "utf8",
BusyTimeout: 500,
TransactionLock: "immediate",
ForeignKeys: true,
JournalMode: "WAL",
CacheSize: -4000,
AutoVacuum: "incremental",
Synchronous: "normal",
MemoryMapSize: 0,
MaxConnectionsOpen: 4,
}
var (
// TestConfiguration provides PRAGMA settings appropriate for a database used
// in unit tests. This configuration uses a smaller page cache and disables
// memory-mapped I/O to keep resource usage low.
//
// Do not modify.
TestConfiguration = &litesql.Configuration{
Mode: "rwc",
Encoding: "utf8",
BusyTimeout: 500,
TransactionLock: "immediate",
ForeignKeys: true,
JournalMode: "WAL",
CacheSize: -4000,
AutoVacuum: "incremental",
Synchronous: "normal",
MemoryMapSize: 0,
MaxConnectionsOpen: 4,
}
)

// Open creates a database in a temporary directory for use in unit tests.
//
Expand Down