Documentation ¶
Overview ¶
Example (SplitPara) ¶
rd := strings.NewReader(`1 one line 1 next line 2 another line 3 third 1 3 third 2`) scn := bufio.NewScanner(rd) scn.Split(splitPara) for scn.Scan() { fmt.Print(scn.Text()) fmt.Println("¶") }
Output: 1 one line 1 next line¶ 2 another line¶ 3 third 1 3 third 2¶
Index ¶
- Constants
- func NotNoRows(err error) error
- func RunScript(db Querier, rd io.Reader, ignoreErr bool) error
- func RunScriptFile(db Querier, file string, ignoreErr bool) error
- func Xaction(conn Querier, recovr bool, do func(tx Tx) error) error
- func XactionContext(ctx context.Context, conn Querier, opts *sql.TxOptions, recovr bool, ...) error
- type DB
- type DataSource
- type Entity
- type Entity32
- type Entity64
- type EntityBase
- type EntityID
- type ID32
- type ID64
- type Querier
- type Reader
- type Ref
- func (ref *Ref[E, ID]) Get(db Querier) (entity E, err error)
- func (ref Ref[E, ID]) ID() ID
- func (ref *Ref[E, ID]) Nil() bool
- func (ref *Ref[E, ID]) Resolved() (is bool, entity E)
- func (ref *Ref[E, ID]) Scan(src interface{}) error
- func (ref *Ref[E, ID]) Set(entity E)
- func (ref *Ref[E, ID]) SetID(r Reader[E, ID], id ID)
- func (ref *Ref[E, ID]) SetReader(r Reader[E, ID])
- func (ref *Ref[E, ID]) SetRef(r Ref[E, ID])
- func (ref Ref[E, ID]) Value() (driver.Value, error)
- func (ref Ref[E, ID]) WithReader(r Reader[E, ID]) (res Ref[E, ID])
- type Repo
- type RepoConfig
- type RollbackError
- type Tx
- type TypeID
- type TypeTable
Examples ¶
Constants ¶
const IDSeqMax32 = 4194303 // 0x3f_ffff
const IDSeqMax64 = 281474976710655 // 0xffff_ffffffff
const IDTypeMax32 = 511 // 0x1ff
const IDTypeMax64 = 32767 // 0x7fff
const NoID = 0
NoID is an ID that no DB record must have as an ID.
Variables ¶
This section is empty.
Functions ¶
func Xaction ¶ added in v0.2.0
Xaction supports writing DB code that needs a "begin at most once" logic for transaction. If conn is already a Tx simply do() is called with that transaction and returns its result.
If conn is a DB a new Tx is started from DB and do() is called with the new transaction. If do() returns a non-nil error the new transcation is rolled back and the error will be returned. If do() panics the new transaction will also be rolled back. If recovr is true the panic will be recovered and returned as error. If recovr is false the panic will escape Xaction. If the rollback itself returns an error this will be returned as RollbackError where Cause represents the reason for the rollback. Without error and panic Xaction will commit the new transaction and return the result from Commit().
Sell also XactionContext
func XactionContext ¶ added in v0.2.0
func XactionContext( ctx context.Context, conn Querier, opts *sql.TxOptions, recovr bool, do func(tx Tx) error, ) error
XactionContext supports writing DB code that need a "begin at most once" logic for transaction. It allows to pass a Context and TxOptions. See also Xaction().
Types ¶
type DataSource ¶ added in v0.2.0
func (*DataSource) Flags ¶ added in v0.2.0
func (ds *DataSource) Flags()
type EntityBase ¶ added in v0.2.0
func (EntityBase[_, ID]) EntityID ¶ added in v0.2.0
func (eb EntityBase[_, ID]) EntityID() ID
func (*EntityBase[_, ID]) IDScanner ¶ added in v0.2.0
func (eb *EntityBase[_, ID]) IDScanner() sql.Scanner
TODO Find out how to do this with generics, not reflection
func (*EntityBase[E, ID]) SetReader ¶ added in v0.2.0
func (eb *EntityBase[E, ID]) SetReader(rd Reader[E, ID])
type ID32 ¶
type ID32 int32
ID32 is the 32-bit ID type.
func MustMakeID32 ¶
MustMakeID32 panics if MakeID32 returns an error.
func NoRowsNoErr32 ¶
NoRowsNoErr32 returns NoID, nil when err is sql.ErrNoRows
type ID64 ¶
type ID64 int64
ID64 is the 64-bit ID type.
func MustMakeID64 ¶
MustMakeID64 panics if MakeID64 returns an error.
func NoRowsNoErr64 ¶
NoRowsNoErr64 returns NoID, nil when err is sql.ErrNoRows
type Querier ¶ added in v0.2.0
type Querier interface { Exec(query string, args ...interface{}) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Prepare(query string) (*sql.Stmt, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
Querier allows to run or execute queries against a database or to prepare statements. It is used to drop the distinction between sql.DB and sql.Tx in application code. See also Xaction and XactionContext.
type Ref ¶ added in v0.2.0
func (*Ref[E, ID]) Scan ¶ added in v0.2.0
TODO Find out how to do this with generics, not reflection
func (Ref[E, ID]) WithReader ¶ added in v0.2.0
type RepoConfig ¶ added in v0.3.2
type RollbackError ¶
func (RollbackError) Error ¶
func (ce RollbackError) Error() string
func (RollbackError) Unwrap ¶
func (ce RollbackError) Unwrap() 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. int32 and int64, are supported ID types. A valid type id must be > 0.
Directories ¶
Path | Synopsis |
---|---|
Package bsq helps to build structured queries for SQL in a maintainable manner.
|
Package bsq helps to build structured queries for SQL in a maintainable manner. |
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. |
cmd
|
|
Package null implements typed adapters for Go values to nullable DB columns.
|
Package null implements typed adapters for Go values to nullable DB columns. |
Package postgres implements the PostgreSQL dialect for bsq.
|
Package postgres implements the PostgreSQL dialect for bsq. |
Package qblogz provides a sqlmw driver interceptor that logs to a qblog Logger (see http://github.com/ngrok/sqlmw).
|
Package qblogz provides a sqlmw driver interceptor that logs to a qblog Logger (see http://github.com/ngrok/sqlmw). |
Package sqlite3 implements the SQLite 3 dialect for bsq.
|
Package sqlite3 implements the SQLite 3 dialect for bsq. |
Package stmt builds on top of package bsq to make programming with prepared statements and sqlize more convenient.
|
Package stmt builds on top of package bsq to make programming with prepared statements and sqlize more convenient. |