You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2015/03/26 00:30:48 UTC

couchdb-mango git commit: Return ddoc id and index name

Repository: couchdb-mango
Updated Branches:
  refs/heads/2645-return-doc-id [created] 2543fae46


Return ddoc id and index name

We return the ddoc id and index name for easier deletion
from the dashboard. We don't return the full design doc because
we want to hide that abstraction of dealing with design docs from
the user.

FIXES COUCHDB-2645


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/2543fae4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/2543fae4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/2543fae4

Branch: refs/heads/2645-return-doc-id
Commit: 2543fae4683c863d50c18fc041468a64005f8d32
Parents: 8930288
Author: Tony Sun <to...@cloudant.com>
Authored: Wed Mar 25 16:29:31 2015 -0700
Committer: Tony Sun <to...@cloudant.com>
Committed: Wed Mar 25 16:29:31 2015 -0700

----------------------------------------------------------------------
 src/mango_httpd.erl | 5 ++++-
 test/mango.py       | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2543fae4/src/mango_httpd.erl
----------------------------------------------------------------------
diff --git a/src/mango_httpd.erl b/src/mango_httpd.erl
index 2588a23..28a1578 100644
--- a/src/mango_httpd.erl
+++ b/src/mango_httpd.erl
@@ -20,6 +20,7 @@
 
 -include_lib("couch/include/couch_db.hrl").
 -include("mango.hrl").
+-include("mango_idx.hrl").
 
 
 handle_req(#httpd{} = Req, Db0) ->
@@ -58,6 +59,8 @@ handle_index_req(#httpd{method='POST', path_parts=[_, _]}=Req, Db) ->
     {ok, Idx0} = mango_idx:new(Db, Opts),
     {ok, Idx} = mango_idx:validate(Idx0),
     {ok, DDoc} = mango_util:load_ddoc(Db, mango_idx:ddoc(Idx)),
+    Id = Idx#idx.ddoc,
+    Name = Idx#idx.name,
     Status = case mango_idx:add(DDoc, Idx) of
         {ok, DDoc} ->
             <<"exists">>;
@@ -75,7 +78,7 @@ handle_index_req(#httpd{method='POST', path_parts=[_, _]}=Req, Db) ->
                     ?MANGO_ERROR(error_saving_ddoc)
             end
     end,
-	chttpd:send_json(Req, {[{result, Status}]});
+	chttpd:send_json(Req, {[{result, Status}, {id, Id}, {name, Name}]});
 
 handle_index_req(#httpd{method='DELETE',
         path_parts=[A, B, <<"_design">>, DDocId0, Type, Name]}=Req, Db) ->

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2543fae4/test/mango.py
----------------------------------------------------------------------
diff --git a/test/mango.py b/test/mango.py
index 79545e1..6dd4077 100644
--- a/test/mango.py
+++ b/test/mango.py
@@ -96,6 +96,8 @@ class Database(object):
         body = json.dumps(body)
         r = self.sess.post(self.path("_index"), data=body)
         r.raise_for_status()
+        assert r.json()["id"] != None
+        assert r.json()["name"] != None
         return r.json()["result"] == "created"
 
     def create_text_index(self, analyzer=None, selector=None, idx_type="text",


Re: couchdb-mango git commit: Return ddoc id and index name

Posted by Paul Davis <pa...@gmail.com>.
Seems a bit silly to assign these to temp variables. How about something
more like:

chttpd:send_json(Req, {[
        {result, Status},
        {id, Idx#idx.ddoci},
        {name, Idx#idx.name}
    ]}).


On Wed, Mar 25, 2015 at 6:30 PM, <to...@apache.org> wrote:

> Repository: couchdb-mango
> Updated Branches:
>   refs/heads/2645-return-doc-id [created] 2543fae46
>
>
> Return ddoc id and index name
>
> We return the ddoc id and index name for easier deletion
> from the dashboard. We don't return the full design doc because
> we want to hide that abstraction of dealing with design docs from
> the user.
>
> FIXES COUCHDB-2645
>
>
> Project: http://git-wip-us.apache.org/repos/asf/couchdb-mango/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/couchdb-mango/commit/2543fae4
> Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mango/tree/2543fae4
> Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mango/diff/2543fae4
>
> Branch: refs/heads/2645-return-doc-id
> Commit: 2543fae4683c863d50c18fc041468a64005f8d32
> Parents: 8930288
> Author: Tony Sun <to...@cloudant.com>
> Authored: Wed Mar 25 16:29:31 2015 -0700
> Committer: Tony Sun <to...@cloudant.com>
> Committed: Wed Mar 25 16:29:31 2015 -0700
>
> ----------------------------------------------------------------------
>  src/mango_httpd.erl | 5 ++++-
>  test/mango.py       | 2 ++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2543fae4/src/mango_httpd.erl
> ----------------------------------------------------------------------
> diff --git a/src/mango_httpd.erl b/src/mango_httpd.erl
> index 2588a23..28a1578 100644
> --- a/src/mango_httpd.erl
> +++ b/src/mango_httpd.erl
> @@ -20,6 +20,7 @@
>
>  -include_lib("couch/include/couch_db.hrl").
>  -include("mango.hrl").
> +-include("mango_idx.hrl").
>
>
>  handle_req(#httpd{} = Req, Db0) ->
> @@ -58,6 +59,8 @@ handle_index_req(#httpd{method='POST', path_parts=[_,
> _]}=Req, Db) ->
>      {ok, Idx0} = mango_idx:new(Db, Opts),
>      {ok, Idx} = mango_idx:validate(Idx0),
>      {ok, DDoc} = mango_util:load_ddoc(Db, mango_idx:ddoc(Idx)),
> +    Id = Idx#idx.ddoc,
> +    Name = Idx#idx.name,
>      Status = case mango_idx:add(DDoc, Idx) of
>          {ok, DDoc} ->
>              <<"exists">>;
> @@ -75,7 +78,7 @@ handle_index_req(#httpd{method='POST', path_parts=[_,
> _]}=Req, Db) ->
>                      ?MANGO_ERROR(error_saving_ddoc)
>              end
>      end,
> -       chttpd:send_json(Req, {[{result, Status}]});
> +       chttpd:send_json(Req, {[{result, Status}, {id, Id}, {name,
> Name}]});
>
>  handle_index_req(#httpd{method='DELETE',
>          path_parts=[A, B, <<"_design">>, DDocId0, Type, Name]}=Req, Db) ->
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/2543fae4/test/mango.py
> ----------------------------------------------------------------------
> diff --git a/test/mango.py b/test/mango.py
> index 79545e1..6dd4077 100644
> --- a/test/mango.py
> +++ b/test/mango.py
> @@ -96,6 +96,8 @@ class Database(object):
>          body = json.dumps(body)
>          r = self.sess.post(self.path("_index"), data=body)
>          r.raise_for_status()
> +        assert r.json()["id"] != None
> +        assert r.json()["name"] != None
>          return r.json()["result"] == "created"
>
>      def create_text_index(self, analyzer=None, selector=None,
> idx_type="text",
>
>