You can sync data from a Google Sheet back to your database using the
- Create a new SQL block with . It's best to give the parameter the same name as the column, e.g.Parameters
- Add the form tag
- Launch the addon
- Select the block created in step #1 (you should see "Form" to the right of it)
- Click "Set up a sync" under the Run button
- Add the range that your data is in, e.g. "Sheet1!A:G". You need to include the cell range using A1 notation. Your table in sheets needs to have headers / column names
- If the table in Sheets has different column names then your parameters, specify the names under each parameter name.
- Click Save
- Done! You can now test your sync by updating a value in the Sheet and confirming the write back to your database. Please let us know if you run into any issues with this.
update dummy.users
set plan = '{{plan}}'
where email = '{{email}}'
Tips and Tricks
Upserts
In MySQL, Upserts (updating and inserting data at the same time) can be performed with "On Duplicate Key Update" after the Insert statement. Your table must already have a unique index. When the row being inserted has a key that already exists in the table, the specified fields will be updated for that key in the database.
In this example, "id" is the unique index. When a certain id already exists in the table, its title, author and year_published will be updated instead of inserting a new row.
INSERT INTO books
(id, title, author, year_published)
VALUES
({{id}}, '{{title}}', '{{author}}', '{{year_published}}')
ON DUPLICATE KEY UPDATE
title = '{{title}}',
author = '{{author}}',
year_published = '{{year_published}}';
Handling Null Data
Null numbers can be casted as Signed Integers in MySQL to avoid errors:
CAST('{{your_param}}' AS SIGNED INTEGER)