The application uses the Postgrex driver to connect to the YugabyteDB cluster. The driver is defined as a dependency in the mix.exs
file:
defp deps do
[
{:postgrex, ">= 0.18.0"}
]
end
First, open the lib\simple_app.ex
and provide the database connectivity settings:
hostname
- the host name of your database cluster.port
- the port number (the default is5433
).database
- the name of the database to connect to (the default isyugabyte
).username
andpassword
- the username and password for your database cluster.ssl: [cacertfile:...]
- the full path to your YugabyteDB Aeon or another secure cluster CA certificate (for example,/Users/dmagda/certificates/root.crt
)
Next, run the app by following these commands:
-
Navigate to the project's root folder:
cd postgrex/simple_app
-
Add all the required dependencies:
mix deps.get
-
Compile the app and start an iex session:
iex -S mix
-
Run the app:
SimpleApp.start
Lastly, verify that the ouput is as follows:
>>>> Successfully connected to YugabyteDB! PID: #PID<0.221.0>
>>>> Successfully created table DemoAccount.
>>>> Selecting accounts:
["Jessica", 28, "USA", 10000]
["John", 28, "Canada", 9000]
>>>> Transferred 800 between accounts.
>>>> Selecting accounts:
["Jessica", 28, "USA", 9200]
["John", 28, "Canada", 9800]
:ok