Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added Compact, and refactored ViewCleanup. #28

Merged
merged 2 commits into from

2 participants

@NorthNick

As proposed in my email yesterday: here are the changes to add database and view compaction. This is my first attempt at a Git pull request, so please do let me know if I'm doing something wrong. Thanks,

Nick

@NorthNick

I needed the keys argument on my view requests, as described at http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options, so have added another commit to this branch which adds a new Keys property to ViewOptions. The changes are completely independent of those in the first commit, so you can pick and choose which you want to add.

@soitgoes soitgoes merged commit 424d3fa into soitgoes:master
@soitgoes
Owner

Thanks nick. These are great. Sorry for the delay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2012
  1. @NorthNick
Commits on Apr 14, 2012
  1. @NorthNick

    Added Keys to ViewOptions

    NorthNick authored
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 8 deletions.
  1. +27 −5 LoveSeat/CouchDatabase.cs
  2. +8 −3 LoveSeat/ViewOptions.cs
View
32 LoveSeat/CouchDatabase.cs
@@ -255,19 +255,41 @@ public ViewResult View(string viewName)
/// <returns>JSON success statement if the response code is Accepted</returns>
public JObject ViewCleanup()
{
- HttpWebResponse resp = GetRequest(databaseBaseUri + "/_view_cleanup").Post().Json().GetResponse();
+ return CheckAccepted(GetRequest(databaseBaseUri + "/_view_cleanup").Post().Json().GetResponse());
+ }
- if (resp == null)
- {
+ /// <summary>
+ /// Compact the current database
+ /// </summary>
+ /// <returns></returns>
+ public JObject Compact()
+ {
+ return CheckAccepted(GetRequest(databaseBaseUri + "/_compact").Post().Json().GetResponse());
+ }
+
+ /// <summary>
+ /// Compact a view.
+ /// </summary>
+ /// <param name="designDoc">The view to compact</param>
+ /// <returns></returns>
+ /// <remarks>Requires admin permissions.</remarks>
+ public JObject Compact(string designDoc)
+ {
+ return CheckAccepted(GetRequest(databaseBaseUri + "/_compact/" + designDoc).Post().Json().GetResponse());
+ }
+
+ private static JObject CheckAccepted(HttpWebResponse resp)
+ {
+ if (resp == null) {
throw new System.Exception("Response returned null.");
}
- if (resp.StatusCode != HttpStatusCode.Accepted)
- {
+ if (resp.StatusCode != HttpStatusCode.Accepted) {
throw new System.Exception("Response return with a HTTP Code of " + resp.StatusCode + " - " + resp.StatusDescription);
}
return resp.GetJObject();
+
}
View
11 LoveSeat/ViewOptions.cs
@@ -1,4 +1,6 @@
-using System;
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Web;
using LoveSeat.Interfaces;
using Newtonsoft.Json;
@@ -18,7 +20,8 @@ public ViewOptions()
/// <summary>
/// If you have a complex object as a string set this using a JRaw object()
/// </summary>
- public IKeyOptions Key { get; set; }
+ public IKeyOptions Key { get; set; }
+ public IEnumerable<IKeyOptions> Keys { get; set; }
/// <summary>
/// If you have a complex object as a string set this using a JRaw object()
/// </summary>
@@ -46,7 +49,9 @@ public override string ToString()
{
string result = "";
if ((Key != null) && (Key.Count > 0))
- result += "&key=" + Key.ToString();
+ result += "&key=" + Key.ToString();
+ if (Keys != null)
+ result += "&keys=[" + String.Join(",", Keys.Select(k => k.ToString()).ToArray()) + "]";
if ((StartKey != null) && (StartKey.Count > 0))
if((StartKey.Count == 1) && (EndKey.Count > 1))
result += "&startkey=[" + StartKey.ToString() + "]";
Something went wrong with that request. Please try again.