Skip to content

Converting CQL to D2

This is the guide how to use the earthly target to convert a CQL schema file into D2 diagram entity.

Following is the sample of using the target:

VERSION 0.8

IMPORT utilities/cql-to-d2 AS cql-to-d2-utils

example:
    FROM scratch

    COPY . .

    COPY (+cql-to-d2/diagrams --input="./input") ./output

    RUN ls ./output

Converting result sample

This is the sample valid CQL schema code:

CREATE TABLE IF NOT EXISTS sample_table (
    column_name_1 int,
    column_name_2 int,
    column_name_3 int,
    column_name_4 text static,
    column_name_5 int,
    column_name_6 counter,
    column_name_7 list<int>,
    column_name_8 set<int>,
    column_name_9 map<int>,
    column_name_10 custom_int,
    column_name_11 tuple<int, set<int>>,
    column_name_12 int,

    PRIMARY KEY (column_name_1, column_name_2, column_name_3)
) WITH CLUSTERING ORDER BY (column_name_3 DESC);

Resulted in D2:

sample_tablecolumn_name_1(int)Kcolumn_name_2(int)P↑column_name_3(int)P↓column_name_4(text)Scolumn_name_5(int)column_name_6(bigint)++[column_name_7](int){column_name_8}(int)<column_name_9>(int)*column_name_10*(custom_int)(column_name_11)(int, set<int>)column_name_12(int)