textileio / go-threads

Server-less p2p database built on libp2p
MIT License
451 stars 65 forks source link

ReadFilter not working #538

Open shoyebinamdar opened 2 years ago

shoyebinamdar commented 2 years ago

Hi Team,

I am referring to the README.md, and I have created a sample program to read and write from threaddb. I also want to test out WriteValidator and ReadFilter. But ReadFilter is not working for me. I tried to use following snippet as defined in README.md.

err := db.NewCollection(context.Background(), myThreadID, db.CollectionConfig{
    Name:    "Persons",
    Schema:  mySchema,
    Indexes: []db.Index{{
        Path:   "name",
        Unique: true,
    }},
    WriteValidator: 
        var type = event.patch.type
        var patch = event.patch.json_patch
        switch (type) {
          case "delete":
            if (writer != "the_boss") {
              return false // Not the boss? No deletes for you.
            }
          default:
            return true
        }
    ,
    ReadFilter: 
        if (instance.Age > 50) {
            delete instance.Age // Getting old, let's hide just _how_ old hehe
        }
        return instance
    ,
})

Please help me here. What am I doing wrong?