Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #868 from grtjn/821-javascript-queries
Browse files Browse the repository at this point in the history
Fixed #821: allow executing sjs queries
  • Loading branch information
grtjn authored Jan 10, 2018
2 parents 522c368 + 5388b35 commit 93ce5f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions deploy/lib/MLClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def go(url, verb, headers = nil, params = nil, body = nil, xcc = false)
end

request_params[:request].use_xcc(xcc)
logger.debug(params)
response = get_http.request request_params
response.value
response
Expand Down
17 changes: 7 additions & 10 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2652,9 +2652,9 @@ def execute_query_8(query, properties = {})
# If app_name is specified, wrap the eval in an xdmp:eval to create an eval context
# that matches that of the selected app-server
if properties[:app_name] != nil
eval_type = "javascript-" if properties[:javascript] != nil
params[:xquery] = %Q{
xquery version "1.0-ml";
(: derived from qconsole-amped.xqy :)
declare function local:eval-options(
$server-id as xs:unsignedLong
Expand All @@ -2673,37 +2673,34 @@ def execute_query_8(query, properties = {})
<options xmlns="xdmp:eval">{
if ($database-id eq xdmp:database()) then ()
else element database { $database-id },
if ($modules-id eq xdmp:modules-database()) then ()
else element modules { $modules-id },
if ($collation eq default-collation()) then ()
else element default-collation { $collation },
if (empty($default-coordinate-system)) then ()
else element default-coordinate-system { $default-coordinate-system },
if ($xquery-version eq xdmp:xquery-version()) then ()
else element default-xquery-version { $xquery-version },
(: we should always have a root path, but better safe than sorry :)
if (empty($modules-root) or $modules-root eq xdmp:modules-root()) then ()
else element root { $modules-root },
element isolation { "different-transaction" }
}</options>
};
let $query := <query><![CDATA[#{query}]]></query>
return xdmp:eval(
return xdmp:#{eval_type}eval(
string($query),
(),
local:eval-options(xdmp:server("#{properties[:app_name]}"))
)
}
else
# No app_name, just run the straight query
params[:xquery] = query
if properties[:javascript] != nil
params[:javascript] = query
else
params[:xquery] = query
end

# Pass through selected database if specified, otherwise run against App-Services
if properties[:db_name] != nil
Expand Down

0 comments on commit 93ce5f1

Please sign in to comment.