Skip to content

Instantly share code, notes, and snippets.

@rofr
Created September 17, 2014 03:17
Show Gist options
  • Save rofr/1ccb93d107d9ae16c7fd to your computer and use it in GitHub Desktop.
Save rofr/1ccb93d107d9ae16c7fd to your computer and use it in GitHub Desktop.
OrigoDB document database example
public class Program
{
public static int CountCustomersQuery(Dictionary<object,object> docs)
{
return docs.OfType<Customer>().Count();
}
public static void Main(string[] args)
{
//Loads or creates a new database at the default location
DocumentDatabaseEngine db = new DocumentDatabaseEngine();
//Create a document
Customer customer = new Customer() {Name = "Rad Robs Surf Shop"};
customer.Addresses.Add(
new Address
{
Street = "404 Ocean Drive",
Zipcode = "92051",
City = "Oceanside",
State = "CA"
});
//Write it to the database
db.Put(customer.Id, customer);
//Query by id
Customer c2 = db.Get<Customer>(customer.Id);
Console.WriteLine(c2.Id + ": " + c2.Name);
//Query using ad-hoc lambda
foreach (var c in db.Get(docs => docs.Values.OfType<Customer>().ToArray()))
{
Console.WriteLine(c.Id + ": " + c.Name);
}
//Query by passing implicit delegate
int result = db.Get(CountCustomersQuery);
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment