field-manual icon indicating copy to clipboard operation
field-manual copied to clipboard

Is it possible to give write access in a single record ?

Open maroodb opened this issue 6 years ago • 4 comments

I am looking for a solution that makes everyone write in a docs database, but no one can remove/modify other records.. is it possible? or I have to create multiple databases for each user?

maroodb avatar Jun 05 '18 21:06 maroodb

What do you mean by other records? Should a creator of a record be allowed to remove? This would be a lot of work right now.

If you just don't want to support a del() you could extend the Docstore and return in it, same for put() if a key is already present.

I haven't tested it, but you could try this:

class CustomStore extends DocumentStore {
  constructor (ipfs, id, dbname, options) {
    super(ipfs, id, dbname, options)
    this._type = CustomStore.type
  }

  static get type() {
    return 'custom'  
  }

  put (doc) {
    if (this.get(doc.key)) { throw new Error("Can't modify existing record!")} // <- like this
    super(doc)
  }

  del (key) {
    throw new Error('Store does not support delete!') // <- And this
  }
}

Keep in mind that you have to register the custom store with orbit-db

// add custom type to orbitdb
OrbitDB.addDatabaseType(CustomStore.type, CustomStore)

// instantiate custom store
let orbitdb = new OrbitDB(ipfs, dbPath)
let store = orbitdb.create(name, CustomStore.type)

maxkerp avatar Jun 07 '18 10:06 maxkerp

OK.. but I was asking about ownership of data in the same database

maroodb avatar Jun 10 '18 12:06 maroodb

@maroodb I think what you might consider is giving everybody their own docstore database with write access pinned to them, and then using OrbitDB's ability to do distributed queries to search all of them across the swarm and collate the data in the application layer.

This is covered in the tutorial section of the OrbitDB Field Manual. Have a look there and open an issue or a PR if you have any more questions or if something doesn't make sense.

aphelionz avatar Apr 16 '19 20:04 aphelionz

Moving to the Field Manual repo to go into more detail

aphelionz avatar Sep 27 '19 16:09 aphelionz