DEV Community

TJ-MD for WayScript

Posted on

Tutorial: Schedule SQL Queries on your Database

We're building a rapid development platform for developers called WayScript. Thank you to all of the community members who have tried it out. Today's tutorial can also be viewed as a video here. Of course, you can also find this completed script here as everything you build can be shared publicly or privately.

Introduction

Automation makes our lives easier. Here at WayScript, we want to provide tools to developers that take away the pain points to implement this automation. Database work can be tricky, let's see how we can automate daily SQL queries on our database using WayScript.

Prerequisites

No prerequisites but some content you might find helpful:
Working with databases
Working with CRON

Activating a Script Routinely

To activate any script on WayScript at set intervals, on certain days, or at certain time, we offer the use of the time trigger:

Time Trigger

We're able to do anything fancy that you might want to using full CRON syntax to denote when we want to activate our script.

For the purposes of simplicity, let's make our's run everyday at 7AM.

Run everyday

Once we have this, anything contained in this tree will be executed, everyday, at 7AM.

Connecting our Database

To connect our database, we'll need to drag it into our workflow below our time trigger.

connect to db

Once here, we'll need to provide some information for WayScript to be able to read/write your database. If you need help with setting up your database, our documentation has a full video and text walkthrough. As with anything else, if you get stuck feel free to reach out to us on our discord as well.

Executing your Database Action

Now that we have the database in the workflow, we're able to write SQL statements and execute those against our tables just like how we would locally. Click edit code to the left:

edit code

This will give us access to the text editor, in which we can write our own custom code. Let's just put something simple in:

SELECT * FROM table_name

This will give us access to all of the information in our table. We can then use this data throughout our script to trigger other actions. Such as sending emails with this data, alerting us if a value exists, and plenty more.

Questions, Concerns?

If there's any questions feel free to comment below or message us on discord after you sign up. We're happy to help! If you want to see this full script template, you can find it here.

Top comments (3)

Collapse
 
jeh212 profile image
Jean

Great tool for someone that hasn't much programming skills, this take away the possibility to learn how to write a proper line of code! But the tool is interesting!

Collapse
 
jorshman profile image
Jesse Orshan

The tool does allow you to write the SQL code exactly how you would coding from scratch. What WayScript removes is all of the work required to make this query execute in a cloud environment on a cron schedule. Therefore, the user can rapidly set up programs that are executing on a schedule in a cloud environment and they only have to worry about their SQL query code.

Collapse
 
jeh212 profile image
Jean

I will give it a try...