crudlib

package
v0.0.0-...-7392356 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoRowsUpdated         error
	MoreThanOneRowUpdated error
	MoreThanOneRowDeleted error
)

Some standard errors that generated code may return.

Functions

func DeleteStatement

func DeleteStatement(tableName string, keyColumns []string) string

DeleteStatement returns "delete from tablename where ..."

func InTransaction

func InTransaction(db *sql.DB, operation func(*sql.Tx) error) error

InTransaction wraps an operation in BEGIN/COMMIT.

func InsertReturningStatement

func InsertReturningStatement(tableName string, columnNames []string, returningColumnName string) string

InsertReturningStatement returns "insert into tablename (...) values (...) returning id"

func InsertStatement

func InsertStatement(tableName string, columnNames []string) string

InsertStatement returns "insert into tablename (...) values (...)"

func Log

func Log(format string, v ...interface{})

Log will write a line to the logger, IFF it has been set to a non-nil value.

func PostDelete

func PostDelete(tx *sql.Tx, item interface{}, tableName string) error

PostDelete checks if the passed in item has a PostDelete method and invokes it.

func PostInsert

func PostInsert(tx *sql.Tx, item interface{}, tableName string) error

PostInsert checks if the passed in item has a PostInsert method and invokes it.

func PostModify

func PostModify(tx *sql.Tx, item interface{}, tableName string) error

PostModify checks if the passed in item has a PostModify method and invokes it.

func PostUpdate

func PostUpdate(tx *sql.Tx, item interface{}, tableName string) error

PostUpdate checks if the passed in item has a PostUpdate method and invokes it.

func PreDelete

func PreDelete(tx *sql.Tx, item interface{}, tableName string) error

PreDelete checks if the passed in item has a PreDelete method and invokes it.

func PreInsert

func PreInsert(tx *sql.Tx, item interface{}, tableName string) error

PreInsert checks if the passed in item has a PreInsert method and invokes it.

func PreModify

func PreModify(tx *sql.Tx, item interface{}, tableName string) error

PreModify checks if the passed in item has a PreModify method and invokes it.

func PreUpdate

func PreUpdate(tx *sql.Tx, item interface{}, tableName string) error

PreUpdate checks if the passed in item has a PreUpdate method and invokes it.

func SelectStatement

func SelectStatement(tableName string, columnNames []string, additionalClauses string) string

SelectStatement constructs a select statement for the given table and columns, with optional additional clauses (where, order by, etc.)

func SetLogger

func SetLogger(logger Logger)

SetLogger sets a logger so we'll start logging database actions.

func UnsetLogger

func UnsetLogger()

UnsetLogger disables logging of SQL actions.

func UpdateStatement

func UpdateStatement(tableName string, keyColumns []string, valueColumns []string) string

UpdateStatement returns "update tablename set ... where ..." Note that bind values must be used with values before keys.

Types

type BindStyle

type BindStyle int

BindStyle is an enum of styles of bind vars.

const (
	QuestionMark BindStyle = iota
	DollarNum
	ColonName
)

Varieties for supported bind-variable markers.

func (BindStyle) ConstName

func (bs BindStyle) ConstName() string

ConstName returns the go-name of a BindStyle.

func (BindStyle) Rebind

func (bs BindStyle) Rebind(query string) string

Rebind will convert question marks to another bind-var style, e.g. "$1, $2, ..." or ":arg, :arg, ..." (This is pretty much stolen directly from github.com/jmoiron/sqlx.)

func (*BindStyle) Set

func (bs *BindStyle) Set(v string) error

Set from string, to satisfy flag.Var()

func (*BindStyle) String

func (bs *BindStyle) String() string

String to satisfy flag.Var()

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger is a thing that can write to a log.

type PostDeleter

type PostDeleter interface {
	PostDelete(*sql.Tx, string) error
}

PostDeleter offers a post-deletion operation.

type PostInserter

type PostInserter interface {
	PostInsert(*sql.Tx, string) error
}

PostInserter offers a post-insert operation.

type PostModifier

type PostModifier interface {
	PostModify(*sql.Tx, string) error
}

PostModifier offers an operation to be executed after any insert/update/delete operation. Will be executed *before* PostInsert/PostUpdate/PostDelete, but *after* actual SQL insert/update/delete.

type PostUpdater

type PostUpdater interface {
	PostUpdate(*sql.Tx, string) error
}

PostUpdater offers a post-update operation.

type PreDeleter

type PreDeleter interface {
	PreDelete(*sql.Tx, string) error
}

PreDeleter offers a pre-delete operation.

type PreInserter

type PreInserter interface {
	PreInsert(*sql.Tx, string) error
}

PreInserter offers a pre-insert operation which might return an error to indicate the operation should be aborted.

type PreModifier

type PreModifier interface {
	PreModify(*sql.Tx, string) error
}

PreModifier offers an operation to be executed before any insert/update/delete operation. Will be executed *after* PreInsert/PreUpdate/PreDelete, but *before* actual SQL insert/update/delete.

type PreUpdater

type PreUpdater interface {
	PreUpdate(*sql.Tx, string) error
}

PreUpdater offers a pre-update operation which might return an error to indicate the operation should be aborted.

Jump to

Keyboard shortcuts

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