Documentation ¶
Overview ¶
Package db includes database functionality for Pixur.
Index ¶
- Constants
- func AllocId(ctx context.Context, beg Beginner, alloc *IdAlloc, adap DBAdapter) (int64, error)
- func AllocIdJob(ctx context.Context, qe querierExecutor, alloc *IdAlloc, adap DBAdapter) (int64, error)
- func Delete(exec Executor, name string, key UniqueIdx, adap DBAdapter) error
- func Insert(exec Executor, name string, cols []string, vals []interface{}, adap DBAdapter) error
- func PreallocateIds(ctx context.Context, beg Beginner, alloc *IdAlloc, adap DBAdapter) error
- func RegisterAdapter(a DBAdapter)
- func Scan(q Querier, name string, opts Opts, cb func(data []byte) error, adap DBAdapter) error
- func Update(exec Executor, name string, cols []string, vals []interface{}, key UniqueIdx, ...) error
- type Beginner
- type Columns
- type Commiter
- type DB
- type DBAdaptable
- type DBAdapter
- type Executor
- type IdAlloc
- type IdAllocatable
- type Idx
- type Lock
- type Opts
- type Querier
- type QuerierExecutorCommitter
- type Result
- type Retryable
- type Rows
- type UniqueIdx
Constants ¶
const ( SequenceTableName = "_SequenceTable" SequenceColName = "the_sequence" )
const ( DefaultIdLowWaterMark = 1 DefaultIdHighWaterMark = 10 )
Watermarks determines how many Ids will be grabbed at a time. If the number is too high program restarts will waste Id space. Additionally, Ids will become less monotonic if there are multiple servers. If the number is too low, it will make a lot more queries than necessary.
Variables ¶
This section is empty.
Functions ¶
func AllocIdJob ¶
func PreallocateIds ¶
PreallocateIds attempts to fill the cache in IdAlloc. It is best effort. If the number of cached Ids goes below the low watermark, PreallocateIds will attempt to get more. It will attempt to refill up to the high watermark.
func RegisterAdapter ¶
func RegisterAdapter(a DBAdapter)
Types ¶
type Beginner ¶
type Beginner interface { // Begin begins a transaction Begin(ctx context.Context, readonly bool) (QuerierExecutorCommitter, error) }
Beginner begins transactions. Upon a successful call to Begin(), callers should take care to either Commit() or Rollback() the QuerierExecutorCommitter.
type Commiter ¶
type Commiter interface { // Commit returns nil iff the transaction was successful. This method may only be called once. // If this method returns true, future calls to Rollback() will be no-ops and always return nil. // If an error is returned, the transaction may have been successful, or it may have failed. Commit() error // Rollback reverts the transaction. Invocations after first are no-ops and always return nil. // If an error is returned, the caller does not need to call Rollback() again. Rollback() error }
Commiter is an interface to commit transactions. It is not threadsafe
type DB ¶
type DB interface { DBAdaptable IdAllocatable Beginner // Close closes the database, and should be called when the db is no longer needed. Close() error // InitSchema initializes the database tables. This is typically used in unit tests. InitSchema(context.Context, []string) error }
DB represents a database. It is the entry point to creating transactions.
type DBAdaptable ¶
type DBAdaptable interface { // Adapter returns an adapter for use with a database. Adapter() DBAdapter }
type DBAdapter ¶
type DBAdapter interface { Name() string Quote(string) string BlobIdxQuote(string) string LockStmt(*strings.Builder, Lock) BoolType() string IntType() string BigIntType() string BlobType() string Open(ctx context.Context, dataSourceName string) (DB, error) OpenForTest(context.Context) (DB, error) // Can the given error be retried? RetryableErr(error) bool }
func GetAllAdapters ¶
func GetAllAdapters() []DBAdapter
type IdAlloc ¶
type IdAlloc struct {
// contains filtered or unexported fields
}
IdAlloc is an id allocator
func (*IdAlloc) GetWatermark ¶
GetWatermark returns the low and high watermark. See SetWatermark.
func (*IdAlloc) SetWatermark ¶
SetWatermark sets the low and high watermark for Id allocation. See PreallocateIds.
type IdAllocatable ¶
type IdAllocatable interface { // IdAllocator returns an IdAlloc for use with a database. IdAllocator() *IdAlloc }
type QuerierExecutorCommitter ¶
QuerierExecutorCommitter is an interface that matches the sql.Tx type.
type Retryable ¶
type Retryable interface {
CanRetry() bool
}
Retryable is implemented by errors that can describe their retryability.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package model described the model format for tables
|
Package model described the model format for tables |
protoc-grn-pxrtab is a protoc plugin for generating Pixur tables.
|
protoc-grn-pxrtab is a protoc plugin for generating Pixur tables. |
generator
Package generator is a protoc generator library for Pixur tables.
|
Package generator is a protoc generator library for Pixur tables. |