I'm trying to get relational-pouch working, I'm able to set the schema but when I call the save function I get the error TypeError: this.rel.save is not a function
This is the setup:
import PouchDB from 'pouchdb-browser'
import find from 'pouchdb-find'
import rel from 'relational-pouch'
@Injectable({
providedIn: 'root'
})
export class PouchDBService {
public base_db: PouchDB.Database
public rel
constructor() {
PouchDB.plugin(find)
PouchDB.plugin(rel)
this.base_db = new PouchDB('Eeeek')
this.rel = this.base_db.setSchema(schema)
this.rel.save('project', {
name: 'George R. R. Martin', id: 1, books: [6, 7]
})
}
}
When I try to call this.rel.find(id) it seems to be ignoring the relational-pouch definition and using the pouch-find definition. So this.rel.find(id) results in Error: you must provide search parameters to find()
but
this.db.rel.find({
selector: {
type: this.type
}
})
works.
The dependencies seem fine, I'm stumped, any help greatly appreciated.
Thanks.
ps. using angular 12.
You're not using the
relfield as advertised. From the type declarationrelis defined asso I don't understand how this code is compilingIt's compiling because
relis implied asanyThis is a benefit of Typescript, and would've saved you a ton of wonder:
This is what you're looking for (kinda)
But that's awful to read - I recommend
Anyway the major takeaway here is to use explicit types. This is demonstrably correct:
OK great now you should be on your way. However I am warning people away from using this plugin as it appears practically abandoned, and issue #125 is a showstopper.
Until some maintenance happens - there are 16 pull requests spanning 2 years - I would not use it. If anything search for a viable fork.