Databases and Nessie migrations

It's time to add Nessie! We will now initialize Nessie in our project and also spin up our development database

Now that we have our endpoints ready, we need to add a database to use with our application.

We can start by adding the database connection variables to our .env and.env.example files

Spin up the database#

Start by spinning up a new database called quacker for our local development. I will be using PostgreSQL, and if you are using a different database, there might be some differences in the queries you have to use as each database uses slightly different syntax.

See Module 2 for how to run a database locally if you do not want to use Docker. If you don't want to install any external tools, I would recommend using SQLite.

As the Docker command is fairly long, and it is annoying to write and edit it in the terminal, we can simply slap it into the Makefile.

As I mentioned earlier, we are using both a Makefile and a deno.jsonc file to store our scripts, and now you will see why. We could store all our scripts in the Deno config file, but it has one slight problem, and that is the fact that we would need to use an external tool to load the environment variables from the .env file. Sure there might be easy solutions out there, but none that are cross platform compatible. By utilizing a Makefile we can simply ask make to load it for us.

Add the following commands to the Makefile:

As you can see, we are using the variables which are available in the .env file for our script. We have now added a db creation command and a db kill command which can be used by you or any of your project members for creating the local dev environment.

An improvement to the current local dev environment would be to use a Docker compose file instead, but for now our focus will be on creating a REST API in Deno.

Adding Nessie#


This page is a preview of Build and deploy a REST API with Deno

Start a new discussion. All notification go to the author.