Configuring Our Site To Use Our Database

Just like we configured MySQL Workbench to connect to our database, we need to configure our BoxLang server to connect to it as well.

  1. Open your project in VSCode.
  2. In the file menu on the left side, find the file called .cfconfig.json. This is a special configuration file that CommandBox feeds into our BoxLang server when it starts up. In it, we can define datasources, mapped drives and a number of other settings.
  3. Notice how in the .cfconfig.json file, there is a section called datasources
  4. Replace where it says DSOURCENAME with the username I messaged you in Canvas.
  5. Notice the other values which are in a format like ${}? DON'T CHANGE THEM! These are for server names, usernames and passwords and other sensitive information which you don't want to check into a git repo because you don't want them shared. So what does that format mean? Those values are being pulled from another file called .env which does not get checked into the git repo.
  6. Open the .env file and put the appropriate values in for each line. The datasource and usernames are the values I messaged you in Canvas. The password is whatever you made it when you connected with MySQL Workbench. The host is uml2480.cyqisqc1fx3i.us-west-2.rds.amazonaws.com
As soon as you've done that....

Take a quick break from this and open up Sourcetree. In the changed files area, right click on the .env listing and choose ignore. This might in turn create another file called .gitignore which tells git which files to NOT check into the repo. this .env file is one of them. Commit that to your repo as well.

  1. The last step is to open the file Application.bx and add the line this.datasource = 'Username' where Username is the username I sent you, not the actual word username.
  2. In CommandBox, restart your server by typing server restart.

When you've finished, create a file called dbtest.bxm in the root of your local server. Copy the following code into it, changing the **DatasourceName** to the name of your datasource.

<bx:DBInfo type="tables"
name="yourinfo"
datasource="**DatasourceName**"
 />

 <bx:dump var="#yourinfo#" />
Lesson 1 of 1 - Connecting to a Database