Learning Velo SQL backend

I’m trying to learn how to use the SQL for backend in order to hide pulling data from sensitive GameData collection. I used the tutorial that comes with the package to write the code below but I am getting the following error.

The GameData collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.

It reads like I haven’t pointed the backend to the correct location of the collection. I know I have the collection name GameData correct. I tried to point this code at another collection but I got the same error. Does the backend not have permission to see/open the collection? I have the collection set for Site Content.

Backend Code:
import { sql } from@velo/wix-data-sql-backend’ ;
const DATABASE = “GameData” ;
const visitorId = “ownerID” ;

export async function getAllData () {
try {
const results = await sql ( ‘SELECT _id, title FROM "’ + DATABASE + ’ Where _owner = “’ + visitorId + '”’ );
return results . payload . data . rows ;
} catch ( error ) {
console . error ( error );
}
}

I found the error. My query was broken because I had a typo with a quote. Should be:

const results = await sql ( ‘SELECT _id, title FROM ’ + DATABASE + ’ Where _owner = "’ + visitorId + ‘"’ );

Not to kibitz, but this is a perfect situation to use Template Literals :
This way you can compose clean SQL:

SELECT
_id
, title
FROM
myStuff
WHERE
_owner = 'abc123'

Then Interpolate as so:

const DATABASE = 'myStuff'
const visitorId = 'abc123'
let sqlCode = `SELECT
_id
, title
FROM
${DATABASE}
WHERE
_owner = '${visitorId}'`

This way, you can test with as many manual queries as makes you comfortable, then interpolate it with Template Literals and the result reads more like good ol’ SQL!