Permalink
Browse files

Added test and stub for query method

  • Loading branch information...
1 parent fb0c91b commit 8e99e391b90bb1ae6958f461d63f3251324194d9 @hoisie committed Nov 28, 2009
Showing with 18 additions and 15 deletions.
  1. +16 −12 gocouch.go
  2. +2 −3 gocouch_test.go
View
@@ -294,19 +294,23 @@ func (database *Database) Delete(docid string) os.Error {
return nil;
}
+type QueryResults struct {
+ Total_rows int;
+ Offset int;
+ Rows []struct { Id string; Key string; Value string };
+}
+
func (database *Database) Query(map_fun string) os.Error {
- var url string = buildURL(database.Address,"_temp_view");
- var body = map[string]string {"map": map_fun, "language":"javascript"};
-
- /*
- var buf bytes.Buffer;
- err := json.Marshal(&buf, body);
- if err != nil {
- return nil;
- }
- println(buf.String());
- */
- return nil;
+ var url string = buildURL(database.Address,"_temp_view");
+ var body = map[string]string {"map": map_fun, "language":"javascript"};
+ var buf bytes.Buffer;
+ json.Marshal(&buf, body);
+ resp, err := post(url, buf.String());
+ if err != nil {
+ return err;
+ }
+ _ ,err = readResponse(resp);
+ return nil;
}
View
@@ -6,7 +6,6 @@ import (
var dbname string = "test123";
-
func clearDatabase(t *testing.T) {
server := Server{"http://127.0.0.1:5984"};
@@ -164,7 +163,7 @@ type testdoc struct {
var map_fun = `function(doc) {
if (doc.gender == 'male')
- emit(doc.name, null);
+ emit(doc.name.length, null);
}`
var test_docs = []testdoc {
@@ -188,4 +187,4 @@ func TestQueryDocument(t *testing.T) {
database.Query(map_fun);
-}
+}

0 comments on commit 8e99e39

Please sign in to comment.