From 789d0c26caad9728b74b7ee25f6a65b91590bbe8 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Tue, 18 Feb 2025 17:21:06 +0100 Subject: [PATCH] Add documentation --- database.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/database.go b/database.go index 5629287..7ba2646 100644 --- a/database.go +++ b/database.go @@ -5,10 +5,15 @@ import ( "zombiezen.com/go/sqlite" ) +// Db holds a connection to a SQLite database. type Db struct { Db *sqlite.Conn } +// OpenDb opens a new connection to a SQLite database. +// The databaseSource specifies the database to use. Set it to `:memory:` to use +// an in-memory database. +// Any database that was successfully opened should afterwards be closed using Db.Close func OpenDb(databaseSource string) (*Db, error) { conn, err := sqlite.OpenConn(databaseSource) if err != nil { @@ -17,10 +22,13 @@ func OpenDb(databaseSource string) (*Db, error) { return &Db{Db: conn}, nil } +// Close closes the database. func (d *Db) Close() error { return d.Db.Close() } +// MustClose closes the database. If an error occurs, it panics instead of +// returning the error. func (d *Db) MustClose() { err := d.Close() if err != nil {