gpt4 book ai didi

maven - 如何在 xquery 中访问环境变量?

转载 作者:行者123 更新时间:2023-12-01 22:55:56 25 4
gpt4 key购买 nike

我在 xquery 中的程序有一些基于函数运行环境的变量。例如,dev 指向“devserver”,test 指向“testserver”,prod 指向“server”等。

如何在我的 application.xml 文件中进行设置以及如何在我的 .xqy 函数中引用这些?

"workaround" solution 1

use "switch" to determine host:

switch (xdmp:host-name(xdmp:host()))
case <dev environment as string> return "devserver"
case <test environment as string> return "testserver"
.
.
.
default return fn:error(xs:QName("ERROR"), "Unknown host: " || xdmp:host-name(xdmp:host()))

"workaround" solution 2

create an xml file in your project for each host, update your application.xml to place the xml file in a directory depending on the environment name, then refer to the document now built on installation.

application.xml:

<db dbName="!mydata-database">
<dir name="/config/" permissionsMode="set">
<uriPrivilege roles="*_uberuser"/>
<permissions roles="*_uberuser" access="riu"/>
<load env="DEV" root="/config/DEV/" merge="true" include="*.xml"/>
<load env="TEST" root="/config/TEST/" merge="true" include="*.xml"/>

documents located in project directory /config//environment.xml

<environment>
<services>
<damApi>https://stage.mydam.org</damApi>
<dimeApi>https://stage.mydime.org/api/Services</dimeApi>
</services>
</environment>

usage when I need to get the value

fn:doc("/config/environment.xml")/environment/services/damApi/fn:string()

neither solution seems the best to me.

最佳答案

如果您使用ml-gradle来部署您的项目,it can do substitutions in your code 。这意味着您可以使用如下代码设置 XQuery 库:

declare variable $ENV = "%%environmentName%%";

然后您可以在任何需要的地方导入该库。

关于maven - 如何在 xquery 中访问环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58841443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com