Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #28 from NorthNick/Compaction

Added Compact, and refactored ViewCleanup.
  • Loading branch information...
commit 424d3facc552f74f7015defe4fa49808e4aedc88 2 parents 6cd9af0 + 8258414
@soitgoes authored
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() + "]";
Please sign in to comment.
Something went wrong with that request. Please try again.