Initial commit

This commit is contained in:
jdl
2026-06-14 20:10:00 +02:00
parent 19f8bf4719
commit 0d382fa2d0
7 changed files with 173 additions and 0 deletions

28
tx.go Normal file
View File

@@ -0,0 +1,28 @@
package sqliteutil
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
// This is a convenience function to run a function within a transaction.
func WithTx(db *sql.DB, fn func(*sql.Tx) error) error {
// Start a transaction.
tx, err := db.Begin()
if err != nil {
return err
}
err = fn(tx)
if err == nil {
err = tx.Commit()
}
if err != nil {
_ = tx.Rollback()
}
return err
}