tables

package
v0.24.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: BSD-3-Clause Imports: 14 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

Variables

This section is empty.

Functions

func CreateBuildTime

func CreateBuildTime(mdlFile string) (ret *sql.DB, err error)

func CreateIdl

func CreateIdl(idlFile string) (ret *sql.DB, err error)

creates a db for the tables listed in idl.sql

func CreateRunTime

func CreateRunTime(mdlFile string) (ret *sql.DB, err error)

open the model as read-only, and create a memory writable database for the runtime

func CreateTest

func CreateTest(name string, includeRunTables bool) *sql.DB

add model and runtime to the same db if you run the test as "go test ... -args write" it'll write the db out in your user (home) directory

func Ins

func Ins(db Executer, tablecols []string, els ...interface{}) (err error)

insert an arbitrary number of rows into the passed db. tablecols holds the names of the table and columns to query, els can hold multiple rows of data, each containing the number of cols specified by tablecols.

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

InsertWith allows the specification of on conflict directives

func LoadFile

func LoadFile(dst *sql.DB, fromFile string) (err error)

reads from the passed file path, overwriting the dynamic parts of the dst database. ( the dynamic portions are all in the rt schema )

func Must

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

func OpenModel added in v0.24.7

func OpenModel(mdlFile string) (ret *sql.DB, err error)

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 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 SaveFile

func SaveFile(toFile string, force bool, src *sql.DB) (err error)

writes the dynamic portions of the src database to the passed file path. removes the file if it created

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 ShareRunTime added in v0.24.8

func ShareRunTime(mdlFile string) (ret *sql.DB, err error)

reuse the model file as the runtime file ( useful sometimes for debugging )

func SqliteConn

func SqliteConn(db *sql.DB, cb func(conn *sqlite3.SQLiteConn) error) (err error)

open a connection to the db and calls the passed cb. automatically closes the connection after the callback is done.

func WriteCsv

func WriteCsv(db Querier, w io.Writer, tablecols []string, where string) (err error)

query the passed db and write the results to w -- builds the query from "tablecols" which holds the names of the table and columns to query; "where" can filter that data. ( see also: WriteCsv. )

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