As someone who is new to typescript and web development, I am eager to incorporate PouchDB into my typescript project to store my objects. Despite the lack of documentation, I am struggling to find the correct approach.
I have created typescript objects that extend a Document base class with mandatory _id and _rev fields. Is this the right direction for me? Am I even close?
Below is my implementation of a Document base class that seems suitable for a PouchDB database-
import PouchDB from 'pouchdb';
// Base class for all objects persisted in the database
export class Document {
readonly type: string;
readonly _id: string;
private _rev?: string; // assigned by the database upon insertion
constructor(type: string, id_suffix?: string) {
this.type = type;
let unique_id: string = uuid();
if (id_suffix === undefined) {
this._id = '${type}_${unique_id}'
}
else {
this._id = '${type}_${id_suffix}_${unique_id}'
}
}
}
It seems I can successfully insert it into the database:
let db = new PouchDB('my-database');
let mydoc = new Document('mydoc');
db.put(mydoc);
let output = db.get(mydoc._id); //Promise<PouchDB.Core.IdMeta & PouchDB.Core.GetMeta>
Could anyone assist me in retrieving my object?