如何从查询模块中读取Memgraph进程的环境变量?

huangapple go评论42阅读模式
英文:

How to read Memgraph process environment variables from a query module?

问题

我正在开发一个查询模块。我需要使用一些环境变量。我想在模块内部配置而不是硬编码数值。有什么办法吗?我想避免从外部文本文件中读取数值。

有办法访问Memgraph的环境变量吗?

英文:

I'm developing a query module. I need to use some environment variables. I want to configure the module without hardcoding values inside the module. What can I do? I'd like to avoid reading values from external text files.

Is there a way to access Memgraph ENV variables?

答案1

得分: 1

在Memgraph查询模块中,可以访问Memgraph的环境变量。以下是可用于测试的代码:

import mgp
import os

home = os.getenv("HOME")
my_env = os.getenv("MY_ENV_VAR")

@mgp.read_proc
def procedure() -> mgp.Record():
    print(my_env)
    print(home)
    return mgp.Record()

希望这对你有帮助。

英文:

In Memmgraph query modules have access to the Memgraph's environment variables. Here is the code that you can use for testing:

import mgp
  
import os
  
home = os.getenv("HOME")
my_env = os.getenv("MY_ENV_VAR")
  
@mgp.read_proc
def procedure() -> mgp.Record():
    print(my_env)
    print(home)
    return mgp.Record()

huangapple
  • 本文由 发表于 2023年2月6日 21:26:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定