Scott Paterson
Scott Paterson

Reputation: 406

App Script run basic queries using Cloud SQL

I am looking how to create basic queries from Cloud SQL using App Script.

q1: "SELECT id FROM users WHERE name = 'some name';"
q2: "UPDATE users SET name = 'other name' WHERE id = 1;"
q3: "DELETE FROM users WHERE id = 1;"

I can read the entire table and insert data, however i cannot find the documentation on the google docs site for these types of queries.

I have tried using the query filter however it returns a bool not the ID INT, I am looking for.

var id =app.datasources.Users.query.filters.name._equals == "some name";
app.Pages.Page1.decendents.label1.text = id;
:>> Type mismatch: Cannot set type Boolean for property text. Type String is expected

Note: Users table sql equivelent (id INT AUTO_INCREMENT, name VARCHAR(64), PRIMARY KEY(id))

Upvotes: 0

Views: 156

Answers (1)

TheMaster
TheMaster

Reputation: 50383

Your query server script syntax is wrong. Try

var query =  app.models.Users.newQuery(); //new query
query.filters.name._equals = "some name"; //Note single`=`; 
var records = query.run(); //run the query
app.Pages.Page1.decendents.label1.text = records[0].id;

To Read:

Upvotes: 3

Related Questions