Introduction to Sterling NoSQL OODB

image
Sterling NoSQL OODB is a lightweight NoSQL object database designed for use in projects on .NET 4.0, Silverlight 4/5 and Windows Phone 7.

Opportunities

  • Work with complex objects (including other simple or complex objects, which may include more objects - and so on unlimitedly). Both classes and structures can act as objects.
  • Works with both fields and properties.
  • The ability to prohibit saving a specific type, property or field.
  • Detection of circular references.
  • DB type in memory.
  • Support for working in local file systems of trusted Silverlight-applications.
  • Support for isolated datastores for Silverlight and Windows Phone.
  • Support for standard file systems for common desktop applications.
  • The table structure is created dynamically on the fly.
  • Simple configuration: you specify the type of table, the type of key and the lambda expression for highlighting the key - and you can fully work.
  • Preservation of specific types when specifying in the description of the structure of their basic interfaces or abstract classes.
  • Full foreign key support - child objects are stored in separate tables.
  • A binary serializer that generates smaller objects on disk than JSON, XML, and so on.
  • Encryption support.
  • Compression support.
  • Support for all CRUD operations: loading, saving (asynchronous for collections), deletion, alignment, and full zeroing.
  • Support for multiple databases per application for partitioning and / or versioning.
  • Native support for the following types: basic, Nullable, strings, byte arrays, DateTime, TimeSpan, Guid, enumerations (Enum), Decimal, lists, dictionaries, arrays, WritableBitmap.
  • Support for custom type processing by writing your own serializers.
  • Support for Linq to Objects queries on indexes and keys.
  • Delayed (lazy) loading of objects in requests.
  • Built-in caching.
  • Built-in backup and recovery.
  • Ability to mount triggers on events “before saving”, “after saving” and “deleting”.
  • The ability to generate a key using a trigger.
  • The ability to implement relationships through triggers.
  • DLL weighs less than 100 kb.

Usage example

Suppose we need to store a species database. Let's describe the following entities:
enum FeedingType {
  Herbivore,
  Carnivore,
  Omnivore
}

class Feeding {
  public FeedingType Type { get; set; }
  public TimeSpan DefaultInterval { get; set; }
}

class Animal {
  public Guid Key { get; set; }
  public string Name { get; set; }
  public TimeSpan LifeExpectancy { get; set; }
  public Feeding Supply { get; set; }
}

* This source code was highlighted with Source Code Highlighter.

Accordingly, we will store objects of type Animal in the database.
Now we need to describe the structure of our database:
class BiologyDatabaseInstance: BaseDatabaseInstance {
  public const string INDEX_ANIMAL_NAME = "idx_animal_name";

  public override string Name { get { return "BiologyDb"; } }

  protected override List RegisterTables () {
    // В нашей БД будет пока только одна таблица - животные.
    return new List {
      CreateTableDefinition (animal => animal.Key)
        .WithIndex (INDEX_ANIMAL_NAME, animal => animal.Name)
    };
  }
}

* This source code was highlighted with Source Code Highlighter.

There will be one table in the database with a key of type Guid and an index on the name of the view.
Now we need to actually activate the database:
var engine = new SterlingEngine ();
engine.Activate();
var databaseInstance = engine.SterlingDatabase.RegisterDatabase (
  new FileSystemDriver ("C:/Temp/Animals/"));

* This source code was highlighted with Source Code Highlighter.

That's all. Can be used. All work is carried out through the copy that was provided to us during registration. For example:
var catId = databaseInstance.Save (new Animal {
  Key = Guid.NewGuid (),
  LifeExpectancy = TimeSpan.FromDays (365 * 15),
  Name = "Cat",
  Supply = new Feeding {
    Type = FeedingType.Carnivore,
    DefaultInterval = TimeSpan.FromHours (12)
  }
});

var cat = databaseInstance.Load (catId);

var orderedAnimals = databaseInstance
  .Query (BiologyDatabaseInstance.INDEX_ANIMAL_NAME)
  .OrderBy (x => x.Index)
  .Select (x => x.LazyValue.Value);

* This source code was highlighted with Source Code Highlighter.

To finish working with the database, call the Dispose () method.

Sources


Also popular now: