jonotree

jonotree

I’m trying to use Tzdata module, and according to the Getting Started section of the hexdoc

, the following config should be used:

config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

Issue 1
When trying to follow this I had the problem of having no config file in my project (generated using mix new projectname) - I’ve provisionally created config/config.exs at the root, with use Mix.Config at the top, based on previous example project. However, documentation about config states that depending on whether you want that the config info to influence the initial build, or be accessible at runtime, you should use put it in runtime.exs or config.exs.
In the case I’m not sure which is appropriate - should it be in config.exs?

Issue 2
Secondly, I’ve updated to a newer version of Elixir (1.13.3) since making the previous example project, and now I’m being warned that Mix.Config is deprecated.In order to migrate to the newer Config module, I want to understand what the line config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase actually does. Looking at the documentation of Mix.Config.config/3, I would expect the arguments to be: root element, key, options (keyword list?) - but here we have:
root element = Elixir
key = :time_zone_database
options(s) = Tzdata.TimeZoneDatabase

Specifying the options as Tzdata.TimeZoneDatabase surely does not pass for a keyword list, so what’s going on here?

Showing Posts 1 to 2

cmo

cmo

You probably want that one in config.exs.

You often have these files:

config/
- config.exs
- dev.exs
- prod.exs
- runtime.exs
- test.exs

config.exs is your base config and others are imported afterwards, depending on the environment, like so:

# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

... your config here ...

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"

If you’re using releases, runtime.exs will end up in the release directory, so you can edit it after the fact. The others will vanish, like magic (or be compiled).

All the config will end up in your Application env, which you can retrieve using Application.fetch_env/get_env and friends. Notice the typespec for Application.put_env is put_env(app(), key(), value(), timeout: timeout(), persistent: boolean()) :: :ok, where value() :: term().

Config.config/3 is config(root_key, key, opts). It talks about keyword lists, which may lead us to think we can only put keyword lists in there, but as we can see from our config files, and Application.put_env, we can jam just about anything in there. Typically it is either a single value or a keyword list.

jonotree

jonotree OP

I see, as you suggested I have got it working using config.exs.

Config is also now working using the module name as opposed to a keyword list - for some reason I was getting an error when using just the module name, but after adjusting a few places and retrying, it seems the source of the error was somewhere else. Thankyou!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews