From f056ca6421b72d12a5c8af170368b97a43e84171 Mon Sep 17 00:00:00 2001 From: damienkatz Date: Fri, 21 Sep 2007 14:07:09 +0000 Subject: [PATCH] _temp_view support for alternate query languages, using content-type git-svn-id: http://couchdb.googlecode.com/svn/trunk@227 efc57d8c-411c-0410-91b3-cfdf4dd2bc77 --- dist/common/ht_utils/couch.js | 2 +- dist/common/ht_utils/couch_tests.js | 1 + src/CouchDb/couch_db.erl | 4 +++- src/CouchDb/couch_server_sup.erl | 21 ++++++++++++++++----- src/CouchDb/mod_couch.erl | 10 +++++----- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/dist/common/ht_utils/couch.js b/dist/common/ht_utils/couch.js index 1b6b98f..b203d5a 100644 --- a/dist/common/ht_utils/couch.js +++ b/dist/common/ht_utils/couch.js @@ -89,7 +89,7 @@ function CouchDb(dbname) { // gets information about the database this.info = function() { this.req.open("GET", this.dbUrl, false); - this.req.send(null); + this.req.send(""); if (this.req.status != 200) throw this.req.responseText.parseJSON(); return this.req.responseText.parseJSON(); diff --git a/dist/common/ht_utils/couch_tests.js b/dist/common/ht_utils/couch_tests.js index ba4fc84..f4ebaf4 100644 --- a/dist/common/ht_utils/couch_tests.js +++ b/dist/common/ht_utils/couch_tests.js @@ -375,6 +375,7 @@ var design_doc_tests = function() { var designDoc = { _id:"_design_foo", + language: "text/javascript", views: { all_docs: "function(doc){return {key:doc.integer}}", no_docs: "function(doc){}", diff --git a/src/CouchDb/couch_db.erl b/src/CouchDb/couch_db.erl index 64defaf..58bff32 100644 --- a/src/CouchDb/couch_db.erl +++ b/src/CouchDb/couch_db.erl @@ -444,7 +444,9 @@ init_main(Filepath, Fd, Supervisor, Header) -> GetTempViewGroupInfoFun = fun(GroupKey) -> % for temp views, the groupkey is the source. and we never persist info - {ok, {{"javascript", [{GroupKey, GroupKey}]}, nil}} + Type = lists:takewhile(fun($|) -> false; (_) -> true end, GroupKey), + [$| | Function] = lists:dropwhile(fun($|) -> false; (_) -> true end, GroupKey), + {ok, {{Type, [{GroupKey, Function}]}, nil}} end, UpdateViewGroupInfoFun = fun(GroupKey, UpdateStatus, GroupInfo) -> diff --git a/src/CouchDb/couch_server_sup.erl b/src/CouchDb/couch_server_sup.erl index f99d1ce..dd3b738 100644 --- a/src/CouchDb/couch_server_sup.erl +++ b/src/CouchDb/couch_server_sup.erl @@ -49,8 +49,8 @@ start_server(IniFilename) -> file:read_file(IniFilename) end, {ok, Ini} = couch_util:parse_ini(binary_to_list(IniBin)), - ConsoleStartupMsg = list_to_atom(couch_util:ini_get_value(Ini, "Couch", "ConsoleStartupMsg", "CouchDb server starting")), - ConsoleStartupCompleteMsg = list_to_atom(couch_util:ini_get_value(Ini, "Couch", "ConsoleStartupCompleteMsg", "CouchDb server started")), + ConsoleStartupMsg = couch_util:ini_get_value(Ini, "Couch", "ConsoleStartupMsg", "CouchDb server starting"), + ConsoleStartupCompleteMsg = couch_util:ini_get_value(Ini, "Couch", "ConsoleStartupCompleteMsg", "CouchDb server started"), LogLevel = list_to_atom(couch_util:ini_get_value(Ini, "Couch", "LogLevel", "error")), DbRootDir = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "DbRootDir", ".")), HttpConfigFile = couch_util:abs_pathname(couch_util:ini_get_value(Ini, "Couch", "HttpConfigFile", "couch_httpd.conf")), @@ -77,9 +77,20 @@ start_server(IniFilename) -> StartResult = supervisor:start_link({local, couch_server_sup}, couch_server_sup, {LogFile, LogLevel, DbRootDir, QueryServers, HttpConfigFile, UtilDriverDir, UpdateNotifierExes, FtSearchQueryServer}), - couch_log:debug("Startup Info:~n\tDbRootDir=~p~n\tHttpConfigFile=~p~n\tLogFile=~p~n\tUtilDriverDir=~p~n\tDbUpdateNotificationProcesses=~p~n\tFullTextSearchQueryServer=~p~n" ++ - [lists:flatten(io_lib:format("\t~s=~p~n", [Lang, QueryExe])) || {Lang, QueryExe} <- QueryServers], - [DbRootDir, HttpConfigFile, LogFile, UtilDriverDir, UpdateNotifierExes, FtSearchQueryServer]), + couch_log:debug("Startup Info:~n\tDbRootDir=~p~n" ++ + "\tHttpConfigFile=~p~n" ++ + "\tLogFile=~p~n" ++ + "\tUtilDriverDir=~p~n" ++ + "\tDbUpdateNotificationProcesses=~p~n" ++ + "\tFullTextSearchQueryServer=~p~n" ++ + "~s~n", + [DbRootDir, + HttpConfigFile, + LogFile, + UtilDriverDir, + UpdateNotifierExes, + FtSearchQueryServer, + [lists:flatten(io_lib:format("\t~s=~p~n", [Lang, QueryExe])) || {Lang, QueryExe} <- QueryServers]]), case StartResult of {ok,_} -> diff --git a/src/CouchDb/mod_couch.erl b/src/CouchDb/mod_couch.erl index b08c397..99221dc 100644 --- a/src/CouchDb/mod_couch.erl +++ b/src/CouchDb/mod_couch.erl @@ -207,8 +207,6 @@ open_db(DbName) -> throw({error_response, Error}) end. - - handle_missing_revs_request(#mod{entity_body=RawJson}=ModData, _UriParts, Db) -> {obj, DocIdRevs} = cjson:decode(RawJson), {ok, Results} = couch_db:get_missing_revs(Db, tuple_to_list(DocIdRevs)), @@ -216,8 +214,9 @@ handle_missing_revs_request(#mod{entity_body=RawJson}=ModData, _UriParts, Db) -> -handle_db_request(#mod{method="POST", entity_body=RawBody}=ModData, #uri_parts{doc="_temp_view"}=Uri, Db) -> - handle_db_request(ModData#mod{method="GET"}, Uri#uri_parts{resource=RawBody}, Db); +handle_db_request(#mod{method="POST", entity_body=RawBody, parsed_header=Headers}=ModData, #uri_parts{doc="_temp_view"}=Uri, Db) -> + Type = proplists:get_value(Headers, "content-type", "text/javascript"), + handle_db_request(ModData#mod{method="GET"}, Uri#uri_parts{resource=Type ++ "|" ++ RawBody}, Db); handle_db_request(#mod{method="DELETE"}=ModData, #uri_parts{doc=DocId,querystr=QueryStr}, Db) -> % handle doc deletion #doc_query_args{revs=Revs} = doc_parse_query(QueryStr), @@ -284,7 +283,8 @@ handle_db_request(#mod{method="PUT",entity_body=RawBody}=ModData, #uri_parts{doc send_ok(ModData, 201, [{results, list_to_tuple(DocResults)}], []); _ -> Doc = couch_doc:from_json_obj(Json), - %if the docid is specified in the URL, use that (we override the json documents ID). + %if the docid is specified in the URL, use that (we override the + % json document's _id member). Doc2 = case {UrlDocId, Doc#doc.uuid} of {"", ""} -> % both blank -- 2.11.4.GIT