summaryrefslogtreecommitdiff
path: root/src/post/sql.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2023-04-15 21:07:16 +0200
committerBrian Picciano <mediocregopher@gmail.com>2023-04-15 21:07:16 +0200
commit7872296b838f4d1b26c6a0a01d79d27fe5ab44cc (patch)
tree9487f5abb93d88ab3b52700d2b3002b7dda373d6 /src/post/sql.go
parent68f3215df6e2e4f345076dd5b20b9bf5867353cf (diff)
Move asset store into its own package
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)