sqlize

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 12 Imported by: 0

README

sqlize

Experimental tools to help with the use of Go sql.

This module is somewhat chaotic. It is primarily published as a dependency off another App project. However the bsq package has matured through a complete rewrite. And, by the way, it combines quite well with sqlx.

Documentation

Index

Constants

View Source
const IDSeqMax32 = 4194303 // 0x3f_ffff
View Source
const IDSeqMax64 = 281474976710655 // 0xffff_ffffffff
View Source
const IDTypeMax32 = 511 // 0x1ff
View Source
const IDTypeMax64 = 32767 // 0x7fff
View Source
const NoID = 0

NoID is an ID that no DB record must have as an ID.

Variables

This section is empty.

Functions

func Delete32

func Delete32(repo Repo32, db SQL, entity Entity32) error

func Delete64

func Delete64(repo Repo64, db SQL, entity Entity64) error

func NotNoRows

func NotNoRows(err error) error

func RunScript

func RunScript(db SQL, rd io.Reader) error

func RunScriptFile

func RunScriptFile(db SQL, file string) error

func Transact

func Transact(conn SQL, do func(tx Tx) error) (err error)

func TransactContext

func TransactContext(
	ctx context.Context,
	conn SQL,
	opts *sql.TxOptions,
	do func(tx Tx) error,
) (err error)

func Update32

func Update32(repo Repo32, db SQL, entity Entity32) error

func Update64

func Update64(repo Repo64, db SQL, entity Entity64) error

Types

type Beginner

type Beginner interface {
	SqlizedBegin() (Tx, error)
	SqlizedBeginTx(context.Context, *sql.TxOptions) (Tx, error)
}

type DB

type DB interface {
	SQL
	Close() error
}

type Entity32

type Entity32 interface {
	EntityID() ID32
}

func Create32

func Create32(repo Repo32, db SQL, entity Entity32) (Entity32, error)

type Entity64

type Entity64 interface {
	EntityID() ID64
}

func Create64

func Create64(repo Repo64, db SQL, entity Entity64) (Entity64, error)

type EntityBase32

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

func (EntityBase32) EntityID

func (e EntityBase32) EntityID() ID32

func (EntityBase32) EntityRepo

func (e EntityBase32) EntityRepo() Repo32

func (*EntityBase32) SetEntityRepo

func (e *EntityBase32) SetEntityRepo(r Repo32, id ID32)

type ID32

type ID32 int32

ID32 is the 32-bit ID type.

func MakeID32

func MakeID32(t TypeID, s uint32) (ID32, error)

MakeID32 creates an ID32 from the TypeID t and the sequence value s.

func MustMakeID32

func MustMakeID32(t TypeID, s uint32) ID32

MustMakeID32 panics if MakeID32 returns an error.

func NoRowsNoErr32

func NoRowsNoErr32(id ID32, err error) (ID32, error)

NoRowsNoErr32 returns NoID, nil when err is sql.ErrNoRows

func (*ID32) Scan

func (id *ID32) Scan(src interface{}) error

func (ID32) Type

func (id ID32) Type() TypeID

Type returns the TypeID from id.

func (ID32) Value

func (id ID32) Value() (driver.Value, error)

type ID64

type ID64 int64

ID64 is the 64-bit ID type.

func MakeID64

func MakeID64(t TypeID, s uint64) (ID64, error)

MakeID64 creates an ID64 from the TypeID t and the sequence value s.

func MustMakeID64

func MustMakeID64(t TypeID, s uint64) ID64

MustMakeID64 panics if MakeID64 returns an error.

func NoRowsNoErr64

func NoRowsNoErr64(id ID64, err error) (ID64, error)

NoRowsNoErr64 returns NoID, nil when err is sql.ErrNoRows

func (*ID64) Scan

func (id *ID64) Scan(src interface{}) error

func (ID64) Type

func (id ID64) Type() TypeID

Type returns the TypeID from id.

func (ID64) Value

func (id ID64) Value() (driver.Value, error)

type NormSpace

type NormSpace string

func (NormSpace) String

func (ns NormSpace) String() string

type Reader32

type Reader32 interface {
	ReadEntity(db SQL, id ID32, entity Entity32) (Entity32, error)
}

type Reader64

type Reader64 interface {
	ReadEntity(db SQL, id ID64, entity Entity64) (Entity64, error)
}

type Ref32

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

func RefEntity32

func RefEntity32(e Entity32) Ref32

func RefID32

func RefID32(rsv Reader32, id ID32) Ref32

func (*Ref32) Get

func (ref *Ref32) Get(db SQL) (entity Entity32, err error)

func (Ref32) ID

func (ref Ref32) ID() ID32

func (Ref32) Nil

func (ref Ref32) Nil() bool

func (*Ref32) Resolved

func (ref *Ref32) Resolved() (is bool, entity Entity32)

func (*Ref32) Scan

func (ref *Ref32) Scan(src interface{}) error

func (*Ref32) Set

func (ref *Ref32) Set(e Entity32)

func (*Ref32) SetID

func (ref *Ref32) SetID(rsv Reader32, id ID32)

func (Ref32) Value

func (ref Ref32) Value() (driver.Value, error)

func (Ref32) WithResolver

func (ref Ref32) WithResolver(rsv Reader32) Ref32

type Ref64

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

func RefEntity64

func RefEntity64(e Entity64) Ref64

func RefID64

func RefID64(rsv Reader64, id ID64) Ref64

func (*Ref64) Get

func (ref *Ref64) Get(db SQL) (entity Entity64, err error)

func (Ref64) ID

func (ref Ref64) ID() ID64

func (Ref64) Nil

func (ref Ref64) Nil() bool

func (*Ref64) Resolved

func (ref *Ref64) Resolved() (is bool, entity Entity64)

func (*Ref64) Scan

func (ref *Ref64) Scan(src interface{}) error

func (*Ref64) Set

func (ref *Ref64) Set(e Entity64)

func (*Ref64) SetID

func (ref *Ref64) SetID(rsv Reader64, id ID64)

func (Ref64) Value

func (ref Ref64) Value() (driver.Value, error)

func (Ref64) WithResolver

func (ref Ref64) WithResolver(rsv Reader64) Ref64

type Repo32

type Repo32 interface {
	Reader32
	CreateEntity(tx Tx, entity Entity32) (Entity32, error)
	UpdateEntity(tx Tx, entity Entity32) error
	DeleteEntity(tx Tx, entity Entity32) error
}

type Repo64

type Repo64 interface {
	Reader64
	CreateEntity(tx Tx, entity Entity64) (Entity64, error)
	UpdateEntity(tx Tx, entity Entity64) error
	DeleteEntity(tx Tx, entity Entity64) error
}

type RollbackError

type RollbackError struct {
	Cause    error
	Rollback error
}

func (RollbackError) Error

func (ce RollbackError) Error() string

func (RollbackError) Unwrap

func (ce RollbackError) Unwrap() error

type SQL

type SQL interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Prepare(query string) (*sql.Stmt, error)
}

func SqlDB

func SqlDB(conn SQL) (*sql.DB, SQL)

func SqlTx

func SqlTx(conn SQL) (*sql.Tx, SQL)

func StdLogDB

func StdLogDB(conn SQL) SQL

type Tx

type Tx interface {
	SQL
	Commit() error
	Rollback() error
}

type TypeID

type TypeID = uint16

To support ploymorphism IDs consist of a TypeID part and a sequence part. The number of bits for both parts depend on the number of bits in the ID type. Currently only ID32 and ID64, i.e. uint32 and uint64, are supported ID types. A valid type id must be > 0.

type TypeTable

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

func NewTypeTable

func NewTypeTable(conn SQL, table string) (res TypeTable, err error)

func (TypeTable) ForEach

func (idt TypeTable) ForEach(do func(tid TypeID, tag string) (done bool)) (hasDone bool)

func (TypeTable) ID

func (idt TypeTable) ID(tag string) TypeID

func (TypeTable) Tag

func (idt TypeTable) Tag(tid TypeID) string

type Wrapper

type Wrapper interface {
	Unwrap() SQL
}

Directories

Path Synopsis
bsq
Package bsq helps to build maintainable structured queries for SQL.
Package bsq helps to build maintainable structured queries for SQL.
keywords
Package keywords defines some handy SQL keywords as const strings for use with the bsq query builder.
Package keywords defines some handy SQL keywords as const strings for use with the bsq query builder.
postgres
Package postgres implements the PostgreSQL dialect for bsq.
Package postgres implements the PostgreSQL dialect for bsq.
sqlite3
Package sqlite3 implements the SQLite 3 dialect for bsq.
Package sqlite3 implements the SQLite 3 dialect for bsq.
Package buildsq helps to build structured queries for the structured query language.
Package buildsq helps to build structured queries for the structured query language.
sql
cmd
bsq
Deprecated: The goxic package will soon be removed.
Deprecated: The goxic package will soon be removed.
Package null implements typed adapters for Go values to nullable DB columns.
Package null implements typed adapters for Go values to nullable DB columns.

Jump to

Keyboard shortcuts

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