db

package
v0.0.0-...-e7141a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDeckWithTotals

func GetDeckWithTotals(wordCount map[string]int) *models.Deck

GetDeckWithTotals returns a Deck with the totals for the given word counts

func InitDB

func InitDB(prodDSN, stagingDSN string)

InitDB initializes the global database instances

Types

type DB

type DB struct {
	*bun.DB

	// context for queries
	Ctx context.Context
}
var (
	ProdDB    *DB
	StagingDB *DB
)

func MakeDB

func MakeDB(dsn string) *DB

MakeDB makes a new DB instance from a DSN using the pg driver

func NewDB

func NewDB(db *bun.DB) *DB

NewDB returns a new DB instance. Creates a background context for queries.

func (*DB) GetMedia

func (db *DB) GetMedia() ([]models.Media, error)

func (*DB) Transact

func (db *DB) Transact(txFunc func(tx *bun.Tx) error) error

Transact executes the given function in a transaction. If the function returns an error, the transaction is rolled back. If the function panics, the transaction is rolled back and the panic is re-thrown.

func (*DB) UploadMedia

func (db *DB) UploadMedia(metadata models.Media, wordCount map[string]int) error

UploadMedia uploads a media file to the database with the given metadata and word counts. Does so in a transaction for atomicity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL