Skip to content
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

avlorm: a package that makes the equivalent of SQL indices with avl.Trees #1467

Open
moul opened this issue Dec 19, 2023 · 0 comments
Open
Labels
good first issue Good for newcomers 🧾 package/realm Tag used for new Realms or Packages.

Comments

@moul
Copy link
Member

moul commented Dec 19, 2023

The objective is to develop a utility that stores a collection of pointers and provides multiple getters. Here's an example in pseudo-code (probably not a good suggestion):

type MyStruct {
	ID int
	Owner std.Address
	Tags []string
}

var db = index.Configuration{
	ID: index.UniqueInteger,
	Owner: index.Address,
	Tag: index.AnyStringSliceEntry,
}

Alternatively:

type MyStruct {
	ID int `index:unique`
	Owner std.Address `index:many2many`
	Tags []string `index:any`
}

db := index.ParseStruct(&MyStruct)

Or, my preferred option: code generation!


Then, we can use it like this:

db.Add(&MyStruct{
	ID: seq,
	Owner: std.GetOrigCaller(),
	Tags: []string{"foo", "bar"}
})

db.GetByID(42) // returns the first entry
db.ListByOwner("g1...") // returns a list
db.ListByTag("foo") // returns a list

An alternative, which would not be called an ORM, would be to create an index from an existing avl.Tree. It could be done like this:

var db avl.Tree

byAuthor := index.ByCallback(entry interface{}, func() interface{} {
	obj := db.(MyStruct)
	return obj.Author
})

This topic will likely have both successful and unsuccessful implementations. It's a suitable introductory task for those interested in experimenting with gno without committing to a complete product, as it only involves backend Go.

Additionally, it will serve as a crucial library component for individuals developing complex contracts, like a twitter clone. This library will enable pagination with different queries, such as "recent global tweets," "recent author tweets," and "recent tags tweets."


Please consider this task as a suitable one for the game of realms and becoming a contributor. If you don't plan to write a library, feel free to share your ideas. This challenge should have been addressed multiple times in the last 40 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Todo
Status: No status
Development

No branches or pull requests

1 participant