Skip to content
jlarsson edited this page Sep 11, 2011 · 10 revisions

A KiwiDB database is called a collection and each collection has a single database file on disk.

var collection = new Collection(@"c:\temp\data.kiwidb");

Instatiating a collection really does nothin in itself, and the file name and extension is totally of your choice.

Now lets put stuff in the collection. And by stuff we mean plain old .NET objects, also called documents in the Nosql world. The documents you can put in a collection can have any combination of lists, classes, dictionaries and simple values. The only requirement is that the stuff you put in must be serializable to and deserializable from Json.

Also, each document is associated via a key. This is not negotiable.

Currently

  • keys are always strings
  • keys are case sensitive
  • keys are not part of the data, and this is an important difference compared to, say, MongoDB
  • keys are always created by the application, never by KiwiDB

Get

If you know the key of a stored document, access is easy.

For untyped access, the result is an IJsonValue or null.

IJsonValue user = collection.Get("key1");

Typed access map back to the same type.

User user = collection.Get<User>("key1");

Update

An update is always an UPSERT, that is if the key is unique, the document is added, otherwise it is overwritten.

The result of an update is the previously stored value or null.

For untyped updates, the result is an IJsonValue, i.e. the internal Json representation of the previsously stored value.

IJsonValue previous = collection.Update("key1",new {Name = "John"});

Typed access map back to the same type.

User previous = collection.Update<User>("key1",new User(){Name = "John"});

Remove

The remove operation accepts a single argument, and returns the deleted value or null.

For untyped deletes, the result is an IJsonValue, i.e. the internal Json representation of the previsously stored value.

IJsonValue deleted = collection.Remove("key1");

Typed access map back to the same type.

User deleted = collection.Remove<User>("key1");

Clone this wiki locally