From 7872296b838f4d1b26c6a0a01d79d27fe5ab44cc Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 15 Apr 2023 21:07:16 +0200 Subject: Move asset store into its own package --- src/post/sql.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/post/sql.go') 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) -- cgit v1.2.3