Documentation
¶
Overview ¶
Package data defines a minimal set of interfaces for abstracting database access (servers, sessions, collections, and the objects they store) so that application code can perform CRUD operations without depending on a specific database driver.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶ added in v0.3.8
type Collection interface {
// Context returns the context.Context that scopes this collection's transaction
Context() context.Context
// Count returns the number of records that match the provided criteria
Count(criteria exp.Expression, options ...option.Option) (int64, error)
// Query populates the target (typically a slice) with all records that match the criteria
Query(target any, criteria exp.Expression, options ...option.Option) error
// Iterator returns an Iterator over all records that match the criteria
Iterator(criteria exp.Expression, options ...option.Option) (Iterator, error)
// Load populates the target with the first record that matches the criteria
Load(criteria exp.Expression, target Object, options ...option.Option) error
// Save inserts or updates the object, recording the note in its journal
Save(object Object, note string) error
// Delete virtually ("soft") deletes the object, recording the note in its journal
Delete(object Object, note string) error
// HardDelete permanently removes all records that match the criteria
HardDelete(criteria exp.Expression) error
}
Collection represents a single database collection (or table) that is opened to support a single transactional request, and then closed when this transaction is complete
type Iterator ¶ added in v0.2.5
type Iterator interface {
// Next populates the provided target with the next item, returning FALSE when the iterator is exhausted
Next(any) bool
// Error returns the first error (if any) encountered while iterating
Error() error
// Count returns the number of records contained by this iterator
Count() int
// Close releases any resources held by the iterator
Close() error
}
Iterator interface allows callers to iterate over a large number of items in a data structure
type Object ¶
type Object interface {
// ID returns the unique identifier for this object
ID() string
// Created returns the Unix epoch (in milliseconds) when this object was created
Created() int64
// Updated returns the Unix epoch (in milliseconds) when this object was updated
Updated() int64
// IsNew returns TRUE if the object has not yet been saved to the database
IsNew() bool
// IsDeleted returns TRUE if the object has been virtually deleted
IsDeleted() bool
// SetCreated stamps the CreateDate and UpdateDate of the object, and makes a note
SetCreated(comment string)
// SetUpdated stamps the UpdateDate of the object, and makes a note
SetUpdated(comment string)
// SetDeleted marks the object virtually "deleted", and makes a note
SetDeleted(comment string)
// ETag returns the signature or revision number of the object
ETag() string
}
Object interface defines all of the methods required for the `data` library to create, read, update, and delete objects in the database.
type Server ¶ added in v0.3.6
type Server interface {
// Session opens a new Session against the database, scoped to the provided context
Session(context.Context) (Session, error)
// WithTransaction opens a session, runs the callback, and commits or rolls back based on its result
WithTransaction(context.Context, TransactionCallbackFunc) (any, error)
}
Server is an abstract representation of a database and its connection information.
type Session ¶
type Session interface {
// Collection returns a handle to the named collection (or table) within this session
Collection(collection string) Collection
// Context returns the context.Context that scopes this session
Context() context.Context
// Close releases any resources held by this session
Close()
}
Session represents a single database session, that is opened to support a single transactional request, and then closed when this transaction is complete
type TransactionCallbackFunc ¶ added in v0.31.0
TransactionCallbackFunc is a function that is called after a transaction session is created. The callback function can return a value (which is passed through) and an error. If the error is nil then the transaction is committed to the database. Otherwise, the transaction is rolled back.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package journal provides a simple implementation of a change-tracking "journal" that can be embedded into other data objects to track their creation, update, and deletion history.
|
Package journal provides a simple implementation of a change-tracking "journal" that can be embedded into other data objects to track their creation, update, and deletion history. |
|
Package option provides an interface for query options that can be used to modify database queries.
|
Package option provides an interface for query options that can be used to modify database queries. |