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 );
}
}