YapDatabase only uses a single table to store data

350 Views Asked by At

I am looking for a key value store database on iOS. It should be based on sqlite, so YapDatabase seems to be a good choice.

But I find YapDatabase only uses a single table, to quote "The main database table is named "database" ": CREATE TABLE "database2" ("rowid" INTEGER PRIMARY KEY, "collection" CHAR NOT NULL, "key" CHAR NOT NULL, "data" BLOB, "metadata" BLOB ). So I am concerned about storing different type objects into the same column.

For example, I plan to use YapDatabase for my chat app, storing each message into |collection|key|object|metadata|. Each message has a unique id, which will be used as the key, message content normally is nstring, which will be used as object, timestamp with some other data is used as metadata. Just like YapDatase author answered here.

Sometimes pictures will be sent. The images are small, normally around couple hundreds of kbs, I don't want to store them as files, I believe storing them as blob is appropriate.

But if I use YapDatabse they are stored in the same table as my normally text messages. Then how can I do some query like, said find all my text messages?

Is my concern valid (storing different type objects into the same column)? Do I need to store them in separated tables? If yes, how? If not, how do I find all my text message easily?

1

There are 1 best solutions below

2
On

The whole point of a key/value store is that it uses only the keys to identify the values. So if you want to store messages and pictures in the same store, you must ensure that they have different keys.

If you want to store data in separate tables, use a database that actually has tables, like SQLite.