Search Apps Documentation Source Content File Folder Download Copy Actions Download

README.md

1.66 Kb · 55 lines

CommonDAO Package Storage Extension

Storage package is an extension of gno.land/p/nt/commondao/v0 that provides alternative storage implementations.

Member Storage

This custom implementation of MemberStorage is an implementation with grouping support that automatically adds or removes members from the storage when members are added or removed from any of the member groups.

The implementation provided by the commondao package doesn't automatically add members to the storage when any of the groups change, if need then users have to be added explicitly.

Adding or removing users automatically could be beneficial in some cases where implementation requires iterating all unique users within the storage and within each group, or counting all unique users within them. It also makes it cheaper to iterate because having all users within the same storage doesn't require to iterate each group.

Package also provide a GetMemberGroups() function that takes advantage of this storage which can be used to return the names of the groups that an account is a member of.

Example usage:

 1import (
 2  "gno.land/p/nt/commondao/v0"
 3  "gno.land/p/nt/commondao/v0/exts/storage"
 4)
 5
 6func main() {
 7  // Create a new member storage with grouping
 8  s := storage.NewMemberStorage()
 9  
10  // Create a member group for moderators
11  moderators, err := s.Grouping().Add("moderators")
12  if err != nil {
13    panic(err)
14  }
15
16  // Add members to the moderators group
17  moderators.Members().Add("g1...a")
18  moderators.Members().Add("g1...b")
19
20  // Create a DAO that uses the new member storage
21  dao := commondao.New(commondao.WithMemberStorage(s))
22
23  // Output: 2
24  println(dao.Members().Size())
25}