# Learning Velo SQL backend

**URL:** <https://forum.wixstudio.com/t/learning-velo-sql-backend/4391>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [November 7, 2021, 11:59pm UTC](https://forum.wixstudio.com/t/learning-velo-sql-backend/4391 "2021-11-07T23:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![widstje](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@widstje](https://forum.wixstudio.com/u/widstje)\
**Post date:** [November 7, 2021, 11:59pm UTC](https://forum.wixstudio.com/t/learning-velo-sql-backend/4391/1 "2021-11-07T23:59:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![widstje](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@widstje](https://forum.wixstudio.com/u/widstje)\
**Post date:** [November 8, 2021, 12:05am UTC](https://forum.wixstudio.com/t/learning-velo-sql-backend/4391/2 "2021-11-08T00:05:46Z")

</div>

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 + ‘"’ );

---

<div class="post-metadata">

**Author:** ![brad32190](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/brad32190/32/26461_2.png) [@brad32190](https://forum.wixstudio.com/u/brad32190)\
**Post date:** [August 15, 2022, 11:58pm UTC](https://forum.wixstudio.com/t/learning-velo-sql-backend/4391/3 "2022-08-15T23:58:36Z")

</div>

Not to kibitz, but this is a perfect situation to use [Template Literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) :  
This way you can compose clean SQL:

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

```

Then Interpolate as so:

```javascript
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!
