sqlite3_rw

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: BSD-3-Clause Imports: 4 Imported by: 4

Documentation

Overview

Package sqlite3_rw reads and updates sqlite3 databases using consumers from the github.com/keep94/consume2 package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRow

func AddRow(
	tx *sql.Tx,
	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,
	dbrows *sql.Rows,
	noSuchRow error) error

FirstOnly reads one row from dbrows into row's business object. FirstOnly returns noSuchRow if dbrows 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[T any](
	tx *sql.Tx,
	row RowsForReading[T],
	consumer consume2.Consumer[T],
	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. ReadMultiple does not set the etag in business objects read even if row implements EtagSetter.

func ReadMultipleWithEtag

func ReadMultipleWithEtag[T any](
	tx *sql.Tx,
	row RowsForReadingEtagSetter[T],
	consumer consume2.Consumer[T],
	sql string,
	params ...interface{}) error

ReadMultipleWithEtag works like ReadMultiple, but it also computes etags for fetched rows.

func ReadRows

func ReadRows[T any](
	row RowsForReading[T],
	dbrows *sql.Rows,
	consumer consume2.Consumer[T]) error

ReadRows reads many rows from dbrows. For each row read, ReadRows adds row's business object to consumer. ReadRows does not set the etag in business objects read even if row implements EtagSetter.

func ReadRowsWithEtag

func ReadRowsWithEtag[T any](
	row RowsForReadingEtagSetter[T],
	dbrows *sql.Rows,
	consumer consume2.Consumer[T]) error

ReadRowsWithEtag works like ReadRows except it does set the etag in business objects read.

func ReadSingle

func ReadSingle(
	tx *sql.Tx,
	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(
	tx *sql.Tx,
	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 {

	// 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 single 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 RowsForReading

type RowsForReading[T any] interface {
	RowForReading

	// ValueRead returns the actual value of the business object just read
	// from the last row.
	ValueRead() T
}

RowsForReading is for reading multiple rows.

type RowsForReadingEtagSetter

type RowsForReadingEtagSetter[T any] interface {
	RowsForReading[T]
	EtagSetter
}

RowsForReadingEtagSetter handles both reading multiple rows and setting etags.

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