Level 4

Using and contributing to the dbt project

If you clicked on the macro link in the advanced tutorial and curiosity got the better of you, you'd notice that the Gallery and the dbt project that builds it, is much more than just macros.

In the dbt project that builds the Gallery, artworks are created as dbt models.

Any decent graphic design program (sorry MS Paint!) allows you to draw in layers. The SQL Draw Gallery project provides this via a custom materialization called new_layer. This means that instead of using UPDATE statements to the canvas like we do from Slack, instead we write SELECT statements that add a new layer to an existing layer below.

Why is this helpful?

Here's our space scene, created as a series of layers. We're looking at its lineage graph from the Gallery, and you can see how we built the image incrementally:

Now imagine we decided that it would look better with tiny stars in the background.
We certainly don't want to be trying to draw around the planet, that would be very tedious.
What we really want to do, is add the stars to the bottom layer and let the change flow through to the top, like so:
In space.sql,
{{ config(materialized='new_layer') }}
select x,y, '#000000' as colour
from {{ ref('blank_canvas_1000_1000') }}

{{ config(materialized='new_layer') }}
select x,y, case
-- 1% chance of a pixel becoming a distant star
when x-x+random() < 0.01 then '#ffffff'
else '#000000'
end as colour
from {{ ref('blank_canvas_1000_1000') }}

Contributing to the Gallery

A big part of SQL Draw is community contributions.
You can contribute an artwork for others to admire, or you can contribute macros to help others build their own artworks. Or both!

To submit a contribution:

  1. Fork the repository
  2. Commit and push your changes to your fork
  3. Open a pull request!
When a Pull Request is opened, your contribution is automatically built and deployed to a subfolder of the Gallery.
A moderator will review it before approving.

Got something to contribute?