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

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

Open
maroodb opened this issue Jun 5, 2018 · 4 comments
Open

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

maroodb opened this issue Jun 5, 2018 · 4 comments

Comments

@maroodb
Copy link

maroodb commented Jun 5, 2018

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?

@maxkerp
Copy link

maxkerp commented Jun 7, 2018

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)

@maroodb
Copy link
Author

maroodb commented Jun 10, 2018

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

@aphelionz
Copy link
Member

@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 aphelionz reopened this Apr 16, 2019
@aphelionz
Copy link
Member

Moving to the Field Manual repo to go into more detail

@aphelionz aphelionz transferred this issue from orbitdb/orbitdb Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants