我们是否有内置机制在Elixir中启动Mnesia? [英] Is there a built-in mechanism for us to launch Mnesia in Elixir?

查看:73
本文介绍了我们是否有内置机制在Elixir中启动Mnesia?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我们只能通过输入 iex --erl --mnesia dir'〜/ doc /' --name mynode 来启动Mnesia。

我们可以直接启动它而不将参数传递给 erl 吗?

解决方案

您可以在代码中动态设置它。上面的-erl 指令所做的就是在启动mnesia应用程序之前对其进行配置。您可以通过以下方式实现此目的:

 #首次加载健忘症
iex(1)> :application.load(:mnesia)
:ok
#现在配置所需的目录
iex(2)> :application.set_env(:mnesia,:dir,'sample')
:ok
#照常启动mnesia
iex(3)> :mnesia.start
:ok
#查看所需信息是否正确
iex(4)> :mnesia.info
:ok

请注意,仅当您手动启动应用程序时,此方法才有效。如果您是自动启动它并希望通过命令行进行配置,则当前的代码段是最佳选择(或使用 ELIXIR_ERL_OPTS )。


It seems like that we can launch Mnesia only by typing iex --erl "--mnesia dir '~/doc/'" --name mynode.

Can we just launch it without passing arguments to erl?

解决方案

You can set it up dynamically in your code. All the --erl instruction above does is to configure the mnesia application before it is started. You could achieve this by:

# First load mnesia
iex(1)> :application.load(:mnesia)
:ok
# Now configure the desired directory
iex(2)> :application.set_env(:mnesia, :dir, 'sample')
:ok
# Start mnesia as usual
iex(3)> :mnesia.start
:ok
# See if the desired info is correct
iex(4)> :mnesia.info
:ok

Notice it only works if you start the application manually. If you are starting it automatically and want to configure through the command line, your current snippet is the best option (or using ELIXIR_ERL_OPTS).

这篇关于我们是否有内置机制在Elixir中启动Mnesia?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆