PouchDB - Create an object store

312 views
Skip to first unread message

Himanshu Agrawal

unread,
Mar 23, 2015, 9:56:59 AM3/23/15
to pou...@googlegroups.com

How can an object store be created using PouchDB? I want to create an object store something like (which is like an SQL table) - codevar objectStore = db.createObjectStore((“SAMPLE_TABLE”, { keyPath: “ID” });code

And then insert multiple rows into it using codevar transaction = db.transaction([“SAMPLE_TABLE”], "readwrite");
var objectStore = transaction.objectStore(“SAMPLE_TABLE”); var request = objectStore.put({"rawData" : JSON.stringify(jObj), "ID" : number, "CALL_ID": callId});code

In PouchDB, I cannot see any API which can let me do this. I can create a document and then insert rows into it but then while traversing the same for update/delete/query there would be problem.

Something similar to this which YDN-DB do -

var schema = { stores:[{ name:'todo-1', keyPath:"timeStamp" }, { name:'todo-2', keyPath:"timeStamp" }] }; var dbTodo = new ydn.db.Storage('todo', schema);

Please let me know.

Warm Regards,

Himanshu

Dale Harvey

unread,
Mar 23, 2015, 10:06:53 AM3/23/15
to pou...@googlegroups.com
Sorry somewhat confused by this question. What are the problems you would have by using the PouchDB API? The equivalent code you posted would be

var db = new PouchDB('SAMPLE_TABLE');
db.put({_id: number, CALL_ID: callId, rawData: JSON.stringify(jObj)});


--
You received this message because you are subscribed to the Google Groups "PouchDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pouchdb+u...@googlegroups.com.
To post to this group, send email to pou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pouchdb/db18a9d1-c0c7-44dd-90d7-e2502a161530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Himanshu Agrawal

unread,
Mar 23, 2015, 10:33:32 AM3/23/15
to pou...@googlegroups.com
Hello Dale,

Thank you for your inputs.

I agree, but wouldn't it be creating a new database? Why should there should be a new database or data store created for each SQL like table?
I don't know how to relate it or think it from burden of several databases.

If we see YDN-DB then they support it through ydn.db.schema namespace.
I am looking for a similar feature in PouchDB.

Also, I have concern related to compaction mode - http://stackoverflow.com/questions/29212877/pouchdb-compaction-mode
We do not want to retain anything related to deleted documents.

Our requirement is just to abstract away WebSQL and IndexedDB, and nothing related to sync with CouchDB. Do you think still it would be wise to use PouchDB?

Please let me know your inputs.

Warm Regards,
Himanshu

--
You received this message because you are subscribed to a topic in the Google Groups "PouchDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pouchdb/NSHZ_cmLsPg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pouchdb+u...@googlegroups.com.

To post to this group, send email to pou...@googlegroups.com.

Dale Harvey

unread,
Mar 23, 2015, 10:42:40 AM3/23/15
to pou...@googlegroups.com
PouchDB is schemaless so it doesnt enforce and setup before you add documents, generally a good idea is if you have different types of documents you want to query together then you can add a 'type' field, so

db.post({type: 'user', name: 'Dale'});
db.post({type: 'message', contents: 'Hello'});

And then when you query make sure to filter by type (by creating a view or pouchdb-find)

If you are not using any of the sync functionality of PouchDB and are worried about the performance impact then it is probably worth looking at other datastores, the syncing functionality does not come for free and there are tradeoffs in place to make it work.

Cheers
Dale

Reply all
Reply to author
Forward
0 new messages