sqlite_db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package sqlite_db contains common types and functions for storing data in a sqlite database.

Index

Constants

View Source
const (
	LastRowIdSQL = "select last_insert_rowid()"
)

Variables

View Source
var (
	AlreadyClosed = errors.New("sqlite_db: Already Closed")
	NoResult      = errors.New("sqlite_db: No result")
)

Functions

func DateToString

func DateToString(t time.Time) string

DateToString converts a date to YYYYmmdd

func LastRowId

func LastRowId(conn *sqlite.Conn) (id int64, err error)

LastRowId returns the Id of the last inserted row in database.

func LastRowIdFromStmt

func LastRowIdFromStmt(stmt *sqlite.Stmt) (id int64, err error)

LastRowIdFromStmt returns the Id of the last inserted row in database. stmt should be a prepared statement created from LastRowIdSQL.

func NewDoer

func NewDoer(db *Db) db.Doer

func StringToDate

func StringToDate(s string) (t time.Time, e error)

StringToDate converts a string of form YYYYmmdd to a time object in UTC time zone.

Types

type Action

type Action func(conn *sqlite.Conn) error

Action represents some action against a sqlite database

type Db

type Db struct {
	// contains filtered or unexported fields
}

Db wraps a sqlite database connection. With Db, multiple threads can safely share the same connection. Db also provides transactional behavior.

func New

func New(conn *sqlite.Conn) *Db

New creates a new Db.

func (*Db) Close

func (d *Db) Close() error

Close closes the underlying connection.

func (*Db) Do

func (d *Db) Do(action Action) error

Do performs action within a transaction. Do returns AlreadyClosed if Close was already called on this Db.

type Doer

type Doer interface {
	Do(Action) error
}

Doer does an Action against a sqlite database

func NewSqliteDoer

func NewSqliteDoer(conn *sqlite.Conn) Doer

func ToDoer

func ToDoer(db Doer, t db.Transaction) Doer

If t is not nil, converts t to a Doer. Otherwise returns db as the Doer.

Jump to

Keyboard shortcuts

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