Giter VIP home page Giter VIP logo

loveseat's Introduction

LoveSeat

Love Seat is a simply architected CouchDB C# client with the intent to abstract away just enough so that it's easy to use, but not enough so that you don't know what's going on. LoveSeat will not introduce unneeded dependancies and will attempt to remove programmer burden while leaving you close enough to the metal that you are able to utilize the full featureset of CouchDb.

Tested compatibility

  • CouchDB 1.0.1
  • .NET Framework 3.5, 4.0 or Mono 2.9 (compiled master branch from Nov 20 2010), and MonoDroid

LoveSeat usage

Basics

// assumes localhost:5984 with no credentials if constructor is left blank
var client = new CouchClient();
var db= client.GetDatabase("Northwind");

// set default design doc (not required)
db.SetDefaultDesignDoc("docs"); 

// get document by ID
Document myDoc = db.GetDocument("12345");

// get document by ID (strongly typed POCO version)
MyObject myObj = db.GetDocument<MyObject>("12345"); 

Simple view results

// get view results
var results = db.View<MyObject>("view_name");

// get view results with parameters
var options = new ViewOptions();
options.StartKey.Add("Atlanta");
options.EndKey.Add("Washington");

var results = db.View<MyObject>("view_name", options);

// loop through strongly typed results
foreach (var item in results.Items){ 
    // do something 

}

Generating more complex view parameters

var options = new ViewOptions();
// generate ["foo"] startkey parameter
options.StartKey.Add("foo");
// generate ["foo",{},{}] endkey parameter
options.EndKey.Add("foo", CouchValue.Empty, CouchValue.Empty);

var results = db.View<MyObject>("view_name", options);

// loop through strongly typed results
foreach (var item in results.Items){ 
    // do something 

}

Customized view key parameters

Assuming that view keys have complex structure, for example:

["johny", ["work", "programming"]]

["joe", ["programming"]]

["johny", ["work"]]

using Newtonsoft.Json.Linq;

...

var options = new ViewOptions(); 
options.StartKey.Add(new JRaw("[\"johny\",[\"work\"]"));
options.EndKey.Add(new JRaw("[\"johny\",[\"work\",{}]]"));  

var results = db.View<MyObject>("view_name", options);

foreach (var item in results.Items){ 
    // do something 

}

This example will return only rows where first key contains "johny" and second key contains "work".

Get the results of a List

var results = db.List("list_name")

LoveSeat supports replication and user management off of the CouchClient as well. Enjoy!

loveseat's People

Contributors

chriswoerz avatar deadok22 avatar ido-ran avatar jzablocki avatar mccow002 avatar northnick avatar nsainaney avatar pagebrooks avatar willholley avatar yojimbo87 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.