Multiple TinyDB question

38 views
Skip to first unread message

Steve Marcus

unread,
Nov 5, 2013, 1:37:07 PM11/5/13
to alternate-java-bridg...@googlegroups.com
If I had 2 TinyDB's in one app, how does the file system then work?

Would it have 2 folders with a set of those little files in each? Or would it have the one folder with all files for both DBs?

If the latter, and I stored a var with the same tag name on different TinyDB's, would it keep two files with the same tag name? Or would one overwrite the other?

Thanks!

Imp Inc

unread,
Nov 5, 2013, 4:21:03 PM11/5/13
to alternate-java-bridg...@googlegroups.com
There's no reason to use multiple TinyDBs. When TinyDB saves something, it saves to it's own file in the app's files directory (using the tag you supply as the filename).

In fact, you don't even really need to instantiate it. There are static methods in that class, so you can just use something like

TinyDB.GetValue(this, "mytag");

Same with StoreValue.

Steve Marcus

unread,
Nov 6, 2013, 7:38:40 AM11/6/13
to alternate-java-bridg...@googlegroups.com
Ok thanks. I was just thinking of having a backup and restore function in my app, and i thought one possible way might be to use 2 TinyDBs.

So to backup, I would get all data from TinyDB1, and store it in TinyB2, to restore I would get all the data from TinyDB2 and overwrite it back into TinyDB1.

So I'm guessing it wouldn't work that way ?


Imp Inc

unread,
Nov 6, 2013, 11:46:32 AM11/6/13
to alternate-java-bridg...@googlegroups.com
No, as each value you store is stored in it's own file.

You may want to use the Prefs class, as this acts more like how you want. It stores all values to a single file, and you can have multiple saving to different files. Only snag is that it only stores booleans, ints, longs, and Strings.

One possible way in TinyDB to do it would be to just store all the values to different tags. Say item1, item2, item3, and item1_backup, item2_backup, etc.

Or, you could use the same tags, and store them to the SD card.

Steve Marcus

unread,
Nov 6, 2013, 3:40:15 PM11/6/13
to alternate-java-bridg...@googlegroups.com
Excellent. thanks!
Reply all
Reply to author
Forward
0 new messages