First of all you need a database. The easiest way is to install it via your distribution. If you are on Ubuntu 18.04, this is straight forward:
sudo apt install postgresql-10
Download LESQL, make it executable and put it into your PATH
wget https://lesql.com/dl/latest/lesql-linux-amd64
mv lesql-linux-amd64 lesql
chmod 755 lesql
sudo mv lesql /usr/local/bin
lesql version
_ _
| | ___ ___ __ _ | |
| | / _ \ / __| / _` | | |
| | | __/ \__ \ | (_| | | |
|_| \___| |___/ \__, | |_|
|_|
Run your ETL with LESS SQL
lesql version 0.9.0-123bb0a linux/amd64
mkdir -p ~/Workspace/lesql
cd ~/Workspace/lesql
lesql init .
This creates a base structure for you models and adds an example project in this structure called zzzexampleproject
. Futhermore it creates an SQL file which will set up the DB, schema and tables in your local Postgresql database. Just run the following command:
sudo su
sudo -u postgres psql < quickstart-zzzexampleproject.sql
exit
#Now you should delete the quickstart-zzzexampleproject.sql as it is not needed anymore#
rm quickstart-zzzexampleproject.sql
lesql run zzzexampleproject -d
This runs the whole project workflow named zzzexampleproject. At this stage it consists of one model only:
{{ block "CONFIG" .}}
{{end}}
{{ block "SELECT" .}}
SELECT * FROM {{ .Project }}.{{ ref "test1" }}
WHERE "date" BETWEEN '{{ .StartDate }}' and '{{ .EndDate }}'
{{end}}
Every model does at least three things:
"zzzexampleproject"."test2"
, if it doesn’t exist.DELETE FROM "zzzexampleproject"."test2" WHERE "date" BETWEEN '2019-10-24' AND '2019-11-23';
test1
to the destination table "zzzexampleproject"."test2"