Documentation ¶
Index ¶
- Constants
- Variables
- func Close(d *DB) error
- func Drivers() []string
- func ExpandPairs(args StringifyArgs, sb *strings.Builder, pairs ...any) string
- func Option[T any](options Optional) (*T, bool)
- func Register(name string, driver Driver)
- type Allocator
- type DB
- type DeleteRequest
- type DeleteRequestAny
- type DeleteResponse
- type DocOption
- type DocOptions
- type Driver
- type Expr
- type ExtractBinary
- type Fields
- type Filter
- type Format
- type GetFlags
- type GetOneResponse
- type GetRequest
- type GetResponse
- type ItemOpt
- type Local
- type Optional
- type PrivateDriver
- type SetRequest
- type SetRequestAny
- type SetResponse
- type StringifyArgs
- type Validator
Constants ¶
const ( // Expose parser-private data for the drivers. AndKeyword = parser.AndKeyword AssignKeyword = parser.AssignKeyword ListKeyword = parser.ListKeyword OrKeyword = parser.OrKeyword )
const ( RuleOff = iota // No rule will be applied in the filter RuleSetItem // The item is being set -- all fields are allowed. RuleCreateItem // The item is being created -- all fields are set except auto-generated ones )
Variables ¶
var FilterCreateItem = Filter{Rule: RuleCreateItem}
var FilterOff = Filter{}
var FilterSetItem = Filter{Rule: RuleSetItem}
Functions ¶
func Close ¶
Close safely closes the DB. Does this function seem ridiculous? It is. But there is SO MUCH error handling in Go, I'm constantly experimenting with little ways to tame it.
func Drivers ¶
func Drivers() []string
Drivers returns a sorted list of the names of the registered drivers.
func ExpandPairs ¶
func ExpandPairs(args StringifyArgs, sb *strings.Builder, pairs ...any) string
ExpandPairs compiles all values in pairs into a single comma-separated string. There must be an even number of pairs, which are treated as key=values. sep is inserted between each pair. String values are quoted with quoteRune. (use rune(0) if you don't want quotes).
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
type DeleteRequest ¶
DeleteRequest
func (DeleteRequest[T]) ItemAny ¶
func (r DeleteRequest[T]) ItemAny() any
type DeleteRequestAny ¶
type DeleteRequestAny interface {
ItemAny() any
}
DeleteRequestAny provides access to the item of a Delete request.
type DeleteResponse ¶
type DeleteResponse struct {
Optional
}
func Delete ¶
func Delete[T any](d *DB, req DeleteRequest[T]) (DeleteResponse, error)
type DocOption ¶
type DocOption func(*DocOptions)
type DocOptions ¶
type DocOptions struct {
Local Local
}
func MakeDocOptions ¶
func MakeDocOptions(opts ...DocOption) *DocOptions
type Driver ¶
type Driver interface { Open(dataSourceName string) (Driver, error) Close() error // Format provides driver-specific formatting rules // when converting an expression to a string. Return // nil for the default rules. Format() Format // Get performs a query based on the request parameters. // The responses are collected in the allocator, and the // driver can return any additional data in the first return param. Get(req GetRequest, a Allocator) (*Optional, error) Set(req SetRequestAny, a Allocator) (*Optional, error) Delete(req DeleteRequestAny, a Allocator) (*Optional, error) }
type Expr ¶
type Expr interface { // Compile the expression. No-op for already-compiled expressions. // Expressions that are not compiled may need to be compiled whenever // you ask for any info. Compile() (Expr, error) // Format answers the expression as a formatted string. Format() (string, error) // Extract allows clients to pull structured information from the Expr. // The argument should implement one or more of the Extract* interfaces. Extract(any) error }
func NewExpr ¶
NewExpr answers a new compiled expression based on the supplied tokens. Tokens will be interpreted as keywords if they exist. This bypasses the parsing stage -- it's an optimization for knowledgeable clients, but also can only handle simple phrases, so in general clients should prefer passing in an expression string.
type ExtractBinary ¶
type ExtractBinary = parser.ExtractBinary
ExtractBinary is passed to Expr.Extract.
type Fields ¶
type Fields struct {
// contains filtered or unexported fields
}
Fields stores a list of field names.
type Filter ¶
type Filter struct { // Rule provides some predefined rules to determine what fields are // allowed. Optional. Rule int64 }
Filter determines what fields are allowed during an operation.
type Format ¶
Expose the parser format to consumers of the doc package without requiring them to import the parser package. Conceptually, parser is completely private.
func FormatWithDefaults ¶
FormatWithDefaults answers the supplied format, adding default behaviour for anything the supplied format leaves unhandled. f can be nil if you just want the default formatting.
type GetOneResponse ¶
GetOneResponse provides output from a GetOne operation.
func GetOne ¶
func GetOne[T any](d *DB, req GetRequest) (GetOneResponse[T], error)
GetOne returns a single item based on the get condition.
func (GetOneResponse[T]) With ¶
func (r GetOneResponse[T]) With(opt any) GetOneResponse[T]
type GetRequest ¶
type GetRequest struct { Optional Condition Expr // Matching condition to accept a record. Fields *Fields // Limit response to these specific fields. Limit int // Limit to the number of items Flags GetFlags }
GetRequest provides parameters to a Get operation.
func (GetRequest) With ¶
func (r GetRequest) With(opt any) GetRequest
type GetResponse ¶
GetResponse provides output from a Get operation.
func Get ¶
func Get[T any](d *DB, req GetRequest) (GetResponse[T], error)
Get returns a list of items based on the get condition.
func (GetResponse[T]) With ¶
func (r GetResponse[T]) With(opt any) GetResponse[T]
type PrivateDriver ¶
type SetRequest ¶
type SetRequest[T any] struct { Optional // The item to set. Item T // Filter is used to determine which fields will be set. // An empty filter will set all fields. Filter Filter }
SetRequest provides parameters to a Set operation.
func (SetRequest[T]) GetFilter ¶
func (r SetRequest[T]) GetFilter() Filter
func (SetRequest[T]) ItemAny ¶
func (r SetRequest[T]) ItemAny() any
func (SetRequest[T]) With ¶
func (r SetRequest[T]) With(opt any) SetRequest[T]
type SetRequestAny ¶
SetRequestAny provides access to the item of a Set request.
type SetResponse ¶
SetResponse provides output from a Set operation.
func Set ¶
func Set[T any](d *DB, req SetRequest[T]) (SetResponse[T], error)
func (SetResponse[T]) With ¶
func (r SetResponse[T]) With(opt any) SetResponse[T]