Gold Medal Metrics - Writing the SQL query in the sql.js file

I am just wondering how we go about writing the code in the sql.js file for the Gold Medal Metrics project.

Do we literally write the SQL directly into the function between the return and ;
Like this

const createCountryTable = () => {
return CREATE TABLE "Country" (
"name"  TEXT NOT NULL,
"code"  TEXT NOT NULL,
"gdp" INTEGER,
"population"  INTEGER

Or do we need to place the SQL inside a function. I think I have round online that you need to put it within but I’m not sure.

If anyone is able to assist it would be much appreciated :slight_smile:


You should be returning a string that contains the SQL in each of the functions for this project. The code already provided in the project will handle the rest.

How you create the string will be up to you. You can use concatenation, template literals, or a combination of those methods.

One tip if you decide to use concatenation is to be conscious of spacing for multiple lines. You may accidentally create invalid SQL.

For example:

const bestFlowerForMonth = (month) => {
  const sql = "SELECT name FROM flowers"
    + "WHERE month = '" + month + "';";
  return sql;

// SELECT name FROM flowersWHERE month = 'July';

Notice the lack of space in flowersWHERE.

I prefer to use template literals.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.