View Source Handling multiple data sources
This guide assumes that you've read the How It Works and Getting Started guides.
If you're using Uniform it's likely that you have multiple databases and/or remote APIs that you query, but you don't want to give every app access to every one.
In this scenario, we recommend creating separate Lib
Dependencies (each in its own
lib/some_data_source
directory) which each encapsulate all of the code for
interacting with a single database or API. This implies that each Lib
Dependency would house the Ecto Repo
as well as all Ecto Schemas and
Context modules related to its
database.
Structuring the code this way allows you to easily include or exclude the code for a data source in uniform.exs.
an-example
An Example
For example, given apps with these uniform.exs
manifests
# lib/some_app/uniform.exs
[
lib_deps: [:my_data_source]
]
# lib/another_app/uniform.exs
[
lib_deps: [:my_data_source, :other_data_source]
]
# lib/third_app/uniform.exs
[
lib_deps: [:other_data_source]
]
SomeApp
would be ejected with all of the code related to interacting withmy_data_source
AnotherApp
would be ejected with the code for bothmy_data_source
andother_data_source
ThirdApp
would only be ejected with the code forother_data_source
configuring-lib-dependencies
Configuring Lib Dependencies
If you take this approach, make sure to configure your Blueprint module to include any Lib or Mix Dependencies of each data source's library. Also, be sure to include migrations and seeds related to the library.
lib :my_data_source do
lib_deps [:some_library]
mix_deps [:faker, ...]
# `match_dot: true` below to include priv/my_data_source_repo/.formatter.exs
file "priv/my_data_source_repo/**", match_dot: true
end