tursodatabase / tursodatabase/libsql
`READONLY` Transactions do not work
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 17.2k
- Forks
- 531
- Avg merge
- 1h 12m
- Merged PRs (30d)
- 1
Description
I was working on adding read only transactions support to the go client but found it does not work.
Here's my implementation for the go client:
func (h *hranaV2Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
var beginSQL string
if opts.Isolation != driver.IsolationLevel(sql.LevelDefault) {
return nil, fmt.Errorf("isolation level %d is not supported", opts.Isolation)
}
if opts.ReadOnly {
beginSQL = "BEGIN TRANSACTION READONLY"
} else {
beginSQL = "BEGIN"
}
_, err := h.ExecContext(ctx, beginSQL, nil)
if err != nil {
return nil, err
}
return &hranaV2Tx{h}, nil
}
Here's the test I wrote:
func (t Table) beginReadOnlyTx() Tx {
txOptions := &sql.TxOptions{ReadOnly: true}
tx, err := t.db.BeginTx(t.db.ctx, txOptions)
t.db.t.FatalOnError(err)
return Tx{tx, t, nil}
}
func TestReadOnlyTransaction(t *testing.T) {
db := getDb(T{t})
table := db.createTable()
tx := table.beginReadOnlyTx()
tx.assertRowsCount(0)
tx.insertRows(0, 10)
db.t.FatalOnError(tx.Commit())
table.assertRowsCount(0)
}
The results of the test should be 0 rows inserted since it is a read only transaction but 10 rows get inserted.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Go client's BeginTx implementation shown in the issue and run the TestReadOnlyTransaction test. Check why the read-only transaction still permits inserts; done means the test observes zero inserted rows after commit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sqlite
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100