Add documentation
This commit is contained in:
parent
3f031f2fe2
commit
789d0c26ca
@ -5,10 +5,15 @@ import (
|
|||||||
"zombiezen.com/go/sqlite"
|
"zombiezen.com/go/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Db holds a connection to a SQLite database.
|
||||||
type Db struct {
|
type Db struct {
|
||||||
Db *sqlite.Conn
|
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) {
|
func OpenDb(databaseSource string) (*Db, error) {
|
||||||
conn, err := sqlite.OpenConn(databaseSource)
|
conn, err := sqlite.OpenConn(databaseSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -17,10 +22,13 @@ func OpenDb(databaseSource string) (*Db, error) {
|
|||||||
return &Db{Db: conn}, nil
|
return &Db{Db: conn}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the database.
|
||||||
func (d *Db) Close() error {
|
func (d *Db) Close() error {
|
||||||
return d.Db.Close()
|
return d.Db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustClose closes the database. If an error occurs, it panics instead of
|
||||||
|
// returning the error.
|
||||||
func (d *Db) MustClose() {
|
func (d *Db) MustClose() {
|
||||||
err := d.Close()
|
err := d.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user