Permalink
Browse files

Fixed:

* Key, StartKey, EndKey initialization
* StartKeyDocId, EndKeyDocId view option

Added:
* some stuff into readme
  • Loading branch information...
1 parent 20f7608 commit f37191b14dd3aff06b3ef98d568151a62c8f1d56 @yojimbo87 yojimbo87 committed Dec 15, 2010
Showing with 63 additions and 18 deletions.
  1. +13 −6 LoveSeat/ViewOptions.cs
  2. +50 −12 README.md
View
@@ -33,15 +33,22 @@ public class ViewOptions : IViewOptions
public bool? Descending { get; set; }
public bool? Stale { get; set; }
public string Etag { get; set; }
-
+
+ public ViewOptions()
+ {
+ Key = new KeyOptions();
+ StartKey = new KeyOptions();
+ EndKey = new KeyOptions();
+ }
+
public override string ToString()
{
string result = "";
- if (Key != null)
+ if ((Key != null) && (Key.Count > 0))
result += "&key=" + HttpUtility.UrlEncode(Key.ToString());
- if (StartKey != null)
+ if ((StartKey != null) && (StartKey.Count > 0))
result += "&startkey=" + HttpUtility.UrlEncode(StartKey.ToString());
- if (EndKey != null)
+ if ((EndKey != null) && (EndKey.Count > 0))
result += "&endkey=" + HttpUtility.UrlEncode(EndKey.ToString());
if (Limit.HasValue)
result += "&limit=" + Limit.Value.ToString();
@@ -61,9 +68,9 @@ public override string ToString()
result += "&descending=" + Descending.Value.ToString().ToLower();
if (Stale.HasValue && Stale.Value)
result += "&stale=ok";
- if (string.IsNullOrEmpty(StartKeyDocId))
+ if (!string.IsNullOrEmpty(StartKeyDocId))
result += "&startkey_docid=" + StartKeyDocId;
- if (string.IsNullOrEmpty(EndKeyDocId))
+ if (!string.IsNullOrEmpty(EndKeyDocId))
result += "&endkey_docid=" + EndKeyDocId;
return result.Length < 1 ? "" : "?" + result.Substring(1);
}
View
@@ -1,42 +1,80 @@
-Love Seat is a simply architected CouchDB wrapper 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
+========
+
+Love Seat is a simply architected [CouchDB](http://couchdb.apache.org/) wrapper 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.
+
+
+Tested compatibility
+====================
+
+ * CouchDB 1.0.1
+ * .NET 4.0 Framework
+ * Mono 2.9 (compiled master branch form Nov 20 2010)
-Tested with 1.0.1
LoveSeat Basics
-=================
+===============
**Everything in LoveSeat starts with a CouchClient.**
- var client = new CouchClient(); //assumes localhost:5984 with no credentials if left blank
+ var client = new CouchClient(); // assumes localhost:5984 with no credentials if left blank
**From here you can get the database**
var db= client.GetDatabase("Northwind");
- //Set the default design doc (not required and can be overriden
-
+ // Set the default design doc (not required and can be overriden)
db.SetDefaultDesignDoc("foo");
- //Get a Document By Id
+ // Get a Document By Id
db.GetDocument("12345");
**Get a view results and populate your Domain object**
var results = db.View<MyObject>("view_name");
- //...or with parameters
-
+ // ...or with parameters
var options = new ViewOptions{Limit=10};
options.StartKey.Add("abc");
results = db.View<MyObject>("view_name", options);
- //loop through your strongly typed results
+ // loop through your strongly typed results
foreach (var item in results.Items){
- // do something
+ // do something
}
+
+**Get a view results and with more complex key parameters**
+
+Assuming that your 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\",{}]]"));
+ results = db.View<MyObject>("view_name", options);
+
+ // loop through your strongly typed results
+
+ 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**

0 comments on commit f37191b

Please sign in to comment.