summaryrefslogtreecommitdiff
path: root/src/post/sql.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/post/sql.go')
-rw-r--r--src/post/sql.go10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/post/sql.go b/src/post/sql.go
index c7b726f..46c7b9a 100644
--- a/src/post/sql.go
+++ b/src/post/sql.go
@@ -78,7 +78,7 @@ var migrations = &migrate.MemoryMigrationSource{Migrations: []*migrate.Migration
// SQLDB is a sqlite3 database which can be used by storage interfaces within
// this package.
type SQLDB struct {
- db *sql.DB
+ *sql.DB
}
// NewSQLDB initializes and returns a new sqlite3 database for storage
@@ -116,12 +116,14 @@ func NewInMemSQLDB() *SQLDB {
// Close cleans up loose resources being held by the db.
func (db *SQLDB) Close() error {
- return db.db.Close()
+ return db.DB.Close()
}
-func (db *SQLDB) withTx(cb func(*sql.Tx) error) error {
+// WithTx initializes a transaction, runs the callback using it, and either
+// commits or rolls it back depending on if the callback returns an error.
+func (db *SQLDB) WithTx(cb func(*sql.Tx) error) error {
- tx, err := db.db.Begin()
+ tx, err := db.DB.Begin()
if err != nil {
return fmt.Errorf("starting transaction: %w", err)