tables

package
v0.24.4-1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package tables - utilities for working with the Tapestry sqlite tables.

Index

Constants

View Source
const (
	ONE_TO_ONE   = "one_one"
	ONE_TO_MANY  = "one_any"
	MANY_TO_ONE  = "any_one"
	MANY_TO_MANY = "any_any"
)

cardinality

View Source
const (
	USUALLY = "usually"
	ALWAYS  = "always"
	SELDOM  = "seldom"
	NEVER   = "never"
)

certainty

View Source
const DefaultDriver = "sqlite3"

Variables

This section is empty.

Functions

func CreateAll

func CreateAll(db *sql.DB) (err error)

CreateAll tables listed in the various .sql files.

func CreateIdl

func CreateIdl(db *sql.DB) (err error)

CreateRun creates the tables listed in idl.sql

func CreateModel

func CreateModel(db *sql.DB) (err error)

CreateModel creates the tables listed in model.sql

func CreateRun

func CreateRun(db *sql.DB) (err error)

CreateRun creates the tables listed in run.sql

func Insert

func Insert(table string, keys ...string) string

Insert creates a sqlite friendly insert statement. For example: "insert into foo(col1, col2, ...) values(?, ?, ...)"

func InsertWith

func InsertWith(table string, rest string, keys ...string) string

func Must

func Must(db *sql.DB, q string, args ...any)

func PrintPrep

func PrintPrep(w io.Writer, err error)

Prep is a utility function that prints a list of errors to w, one error per line, if the err parameter is an Prep. Otherwise it prints the err string.

func QueryAll

func QueryAll(db Querier, q string, cb func() error, dest ...any) (err error)

QueryAll queries the db ( or statement cache ) for one or more rows. For each row, it writes the row to the 'dest' args and calls 'cb' for processing.

func QueryStrings

func QueryStrings(db Querier, q string, args ...any) (ret []string, err error)

where each row is one string.

func RowsAffected

func RowsAffected(res sql.Result) (ret int)

func ScanAll

func ScanAll(rows *sql.Rows, cb func() error, dest ...any) (err error)

ScanAll writes each row to the 'dest' args and calls 'cb' for processing. It closes rows before returning.

func ScanStrings

func ScanStrings(rows *sql.Rows) (ret []string, err error)

func WriteCsv

func WriteCsv(db Querier, w io.Writer, q string, cols int) (err error)

query data from the passed db, and write the comma separated results to the passed writer. q holds the query string, cols holds the number of expected columns in the output. ex. WriteCsv(db, os.Stdout, "select col1, col2 from table", 2)

Types

type Cache

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

Cache mimics the sql.Stmt api, creating the Stmt objects on demand.

func NewCache

func NewCache(db *sql.DB) *Cache

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) DB

func (c *Cache) DB() *sql.DB

func (*Cache) Exec

func (c *Cache) Exec(q string, args ...any) (ret sql.Result, err error)

func (*Cache) Must

func (c *Cache) Must(q string, args ...any)

func (*Cache) Query

func (c *Cache) Query(q string, args ...any) (ret *sql.Rows, err error)

func (*Cache) QueryRow

func (c *Cache) QueryRow(q string, args ...any) (ret RowScanner)

QueryRow assumes a single result row. It mimics db.QueryRow but returns Scanner instead of Row so that we can defer any errors encountered while preparing the cached statement.

type Executer

type Executer interface {
	Exec(q string, args ...any) (sql.Result, error)
}

compatible with sql.DB for use with caches, etc.

type Prep

type Prep []*prepErr

Prep accumulates any errors that occur when creating a series of sql prepared statements.

func (Prep) Err

func (ps Prep) Err() (ret error)

Err returns an error equivalent to this error list. If the list is empty, Err returns nil.

func (*Prep) Prep

func (ps *Prep) Prep(db *sql.DB, q string) (ret *sql.Stmt)

unfortunately, this returns nil on error pkg sql doesnt provide a way to prepare an empty statement with a "sticky error" from outside the package.

func (*Prep) Reset

func (ps *Prep) Reset()

Reset resets an Prep to no errors.

type Querier

type Querier interface {
	Query(query string, args ...any) (*sql.Rows, error)
}

Query used for QueryAll to hide differences b/t tables.Cache and sql.DB

type QueryRow

type QueryRow interface {
	QueryRow(query string, args ...any) *sql.Row
}

Query used for QueryAll to hide differences b/t tables.Cache and sql.DB

type RowScanner

type RowScanner interface {
	Scan(...any) error
}

RowScanner because sql.Row.Scan doesnt have the sql.Scanner.Scan interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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