Documentation
¶
Overview ¶
Package store provides an interface for data store operations, to allow for easy extensibility to support various datastores. Also, provides the standardized Update and Query interfaces to data stores.
Index ¶
- Variables
- func Parent(id string) (parentid string, rerr error)
- func Register(name string, store Store)
- type Object
- type Query
- type Result
- type Store
- type Update
- func (n *Update) AddChild(kind string) *Update
- func (n *Update) Execute(c *req.Context) error
- func (n *Update) Id() string
- func (n *Update) MarkDeleted() *Update
- func (n *Update) Print() *Update
- func (n *Update) Set(property string, value interface{}) *Update
- func (n *Update) SetCommitTs(tsNano int64) *Update
- func (n *Update) SetSource(source string) *Update
- type Versions
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoParent = errors.New("No parent found")
)
Functions ¶
Types ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query stores the read instrutions, storing the instruction set for the entities Query relates to.
func NewQuery ¶
NewQuery is the main entrypoint to data store queries. Returns back a Query object pointer, to run read instructions on.
func (*Query) Collect ¶
Collect specifies the kind of child entities to retrieve. Returns back a new Query pointer pointing to those children entities as a collective.
Any further operations on this returned pointer would attribute to those children entities, and not the caller query entity.
func (*Query) FilterOut ¶
FilterOut provides a way to well, filter out, any entities which have the given property.
func (*Query) Run ¶
Run finds the root from the given Query pointer, recursively executes the read operations, and returns back pointer to Result object. Any errors encountered during these stpeps is returned as well.
func (*Query) UptoDepth ¶
UptoDepth specifies the number of levels of descendants that would be retrieved for the entity Query points to.
You can think of this in terms of a tree structure, where the Entity pointed to by Query points to other Entities, which in turn point to more Entities, and so on. For e.g. Post -> Comments -> Likes.
type Result ¶
Result stores the final entity state retrieved from Store upon running the instructions provided by Query.
func (*Result) ToJson ¶
ToJson creates the JSON for the data pointed by the Result pointer.
Note that this doesn't find the "root" from the Result pointer, instead doing the processing only from the current Result pointer.
func (*Result) WriteJsonResponse ¶
func (r *Result) WriteJsonResponse(w http.ResponseWriter)
WriteJsonResponse does the same as ToJson. But also writes the JSON generated to http.ResponseWriter. In case of error, writes that error instead, in this format:
{ "code": "E_ERROR", "message": "error message" }
type Store ¶
type Store interface { // Init is used to initialize store driver. Init(args ...string) // Commit writes the array of instructions to the data store. Commit(its []*x.Instruction) error // IsNew returns true if the entity id provided doesn't exist in the // store. Note that this entity id is never solely the row primary key, // because multiple rows can (and most surely will) have the same entity id. IsNew(entityId string) bool // GetEntity retrieves all the rows for the given subject id, parses them // into instructions, appends them to the array, and returns it. Any error // encountered during these steps is also returned. GetEntity(entityId string) ([]x.Instruction, error) // Iterate allows for a way to page over all the entities stored in the table. // Iteration starts from id fromId and stops after num results are processed. // Note that depending upon database, number of distinct entities might be // less than the number of results retrieved from the store. That's normal. // // Returns the number of entities found, the last entity returned // and error, if any. If the number of entities found are zero, assume // that we've reached the end of the table. Iterate(fromId string, num int, ch chan x.Entity) (int, x.Entity, error) }
All the data CRUD operations are run via this Store interface. Implement this interface to add support for a datastore.
type Update ¶
type Update struct { NanoTs int64 // contains filtered or unexported fields }
Update stores the create and update instructions, acting as the modifier to the entity Update relates to.
func NewUpdate ¶
NewUpdate is the main entrypoint to updates. Returns back a Update object pointer, to run create and update operations on.
func (*Update) AddChild ¶
AddChild creates a new entity with the given kind, and creates a directed relationship from current entity to this new child entity. This is useful to generate arbitrarily deep and complex data structures, for e.g. Posts by Users, Comments on Posts, Likes on Posts etc.
Retuns the Update pointer for the child entity, so any update operations done on this pointer would be reflected in the child entity. Note that a child can only have one parent by design.
func (*Update) Execute ¶
Execute finds the root from the given Update pointer, recursively generates the set of instructions to store, and commits them. Returns any errors encountered during these steps.
func (*Update) MarkDeleted ¶
Marks the current entity for deletion. This is equivalent to doing a Set("delete_me", true), and then running q.FilterOut("delete_me") during query phase. Nothing is actually deleted though, as per the retention principle.
func (*Update) Print ¶
Print finds the root from the given Update pointer, and does a recursive print on the tree for debugging purposes.
func (*Update) Set ¶
Set allows you to set the property and value on the current entity. This would effectively replace any other value this property had, on this entity node pointer represents. But, no actual data would be overwritten though, as per the retention principle.
func (*Update) SetCommitTs ¶
SetCommitTs allows you to set the commit timestamp of the update. The timestamp provided should be in nano-seconds. SetCommitTs can only be called on the root update node.