-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(examples): add p/jeronimoalbi/datastore
package
#3698
base: master
Are you sure you want to change the base?
Conversation
This adds typing support for record collection indexing functions. It also enforces sparse indexes which are required to make sure they work when record fields are removed or renamed.
Datastore allows the creation of multiple collection based storages.
🛠 PR Checks Summary🔴 Pending initial approval by a review team member, or review from tech-staff Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🔴 Pending initial approval by a review team member, or review from tech-staff ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
Added to support record pagination. Offset pagination is initially not possible because custom indexes can have multiple record ID values for a single key.
Moving back to draft to rethink data iteration |
p/jeronimoalbi/datastore
p/jeronimoalbi/datastore
package
A `Query` methods was added to deal with record queries. Recordset type was introduced for query results to protect users from potentially get a large list of records. Recordsets require users to iterate each record. Users can still get the underlying collection for more advance cases. Queries can have an offset and size which allows pagination of records.
Iteration can be done by using a query to get a recordset: package main
import (
ds "gno.land/p/jeronimoalbi/datastore"
)
func main() {
var db ds.Datastore
// Create a new storage for user records
storage := db.CreateStorage("users")
// Add a couple of empty records
storage.NewRecord().Save() // ID 1
storage.NewRecord().Save() // ID 2
storage.NewRecord().Save() // ID 3
storage.NewRecord().Save() // ID 4
// Query records with a custom offset and size
recordset, err := storage.Query(ds.WithOffset(1), ds.WithSize(2))
if err != nil {
panic(err)
}
// Get all query results
recordset.Iterate(func(r ds.Record) bool {
println("ID = ", r.ID())
return false
})
}
// Output:
// ID = 2
// ID = 3 By default query uses an ID index that contains all available storage records, but it supports a |
The purpose of this package is to support a data store where multiple collection based storages could be defined.
Each named storage defines a collection of records where each record can optionally and by default have any number of user defined fields, which can be constrained to a pre defined set of fields by using a schema definition.
The implementation is a layer on top of
p/moul/collection
.Example of
datastore
package usage: