sqlite_rw

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: BSD-3-Clause Imports: 5 Imported by: 3

Documentation

Overview

Package sqlite_rw reads and updates sqlite databases using consumers from the github.com/keep94/goconsume package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRow

func AddRow(
	conn *sqlite.Conn,
	row RowForWriting,
	rowId *int64,
	sql string) error

AddRow adds row's business object as a new row in database. The row being added must have auto increment id field. AddRow stores the id of the new row at rowId.

func FirstOnly

func FirstOnly(
	row RowForReading,
	stmt *sqlite.Stmt,
	noSuchRow error) error

FirstOnly reads one row from stmt into row's business object. FirstOnly returns noSuchRow if stmt has no rows.

func InsertValues

func InsertValues(row RowForWriting) (
	values []interface{}, err error)

InsertValues returns the values of the SQL columns to add a new row

func ReadMultiple

func ReadMultiple(
	conn *sqlite.Conn,
	row RowForReading,
	consumer goconsume.Consumer,
	sql string,
	params ...interface{}) error

ReadMultiple executes sql and reads multiple rows. Each time a row is read, row's business object is added to consumer. params provides values for question mark (?) place holders in sql.

func ReadRows

func ReadRows(
	row RowForReading,
	stmt *sqlite.Stmt,
	consumer goconsume.Consumer) error

ReadRows reads many rows from stmt. For each row read, ReadRows adds row's business object to consumer.

func ReadSingle

func ReadSingle(
	conn *sqlite.Conn,
	row RowForReading,
	noSuchRow error,
	sql string,
	params ...interface{}) error

ReadSingle executes sql and reads a single row into row's business object. ReadSingle returns noSuchRow if no rows were found. params provides the values for the question mark (?) place holders in sql.

func UpdateRow

func UpdateRow(
	conn *sqlite.Conn,
	row RowForWriting,
	sql string) error

UpdateRow updates a row's business object in the database.

func UpdateValues

func UpdateValues(row RowForWriting) (
	values []interface{}, err error)

UpdateValues returns the values of the SQL columns to update row

Types

type EtagSetter

type EtagSetter interface {

	// Values returns column values from database with Id column last
	Values() []interface{}

	// SetEtag sets the etag on this instance's business object
	SetEtag(etag uint64)
}

EtagSetter sets the etag on its business objecct

type RowForReading

type RowForReading interface {

	// ValuePtr returns the pointer to this instance's business object.
	ValuePtr() interface{}

	// Ptrs returns the pointers to be passed to Scan to read the database row.
	Ptrs() []interface{}

	// Unmarshall updates this instance's business object with the values
	// stored in the pointers that Ptrs returned.
	Unmarshall() error
}

RowForReading reads a database row into its business object. RowForReading instances can optionally implement EtagSetter if its business object has an etag.

type RowForWriting

type RowForWriting interface {

	// Values returns the column values for the database with Id column last.
	Values() []interface{}

	// Marshall updates the values that Values() returns using this instance's
	// business object
	Marshall() error
}

RowForWriting writes its business object to a database row.

type SimpleRow

type SimpleRow struct {
}

SimpleRow provides empty Marshall / Unmarshall for implementations of RowForReading and RowForWriting

func (SimpleRow) Marshall

func (s SimpleRow) Marshall() error

func (SimpleRow) Unmarshall

func (s SimpleRow) Unmarshall() error

Jump to

Keyboard shortcuts

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