[
    {
        "id": "f84fe21bfb96294f",
        "type": "tab",
        "label": "clickhouse demo",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0c75fd74244852ae",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "CREATE TABLE products if not exists",
        "query": "CREATE TABLE IF NOT EXISTS test_db.products (\n    id UUID DEFAULT generateUUIDv4(),\n    article String,\n    brand String,\n    name String,\n    created_at DateTime DEFAULT now(),\n    updated_at DateTime DEFAULT now(),\n    source Nullable(String) COMMENT 'some source',\n    filename Nullable(String)\n) ENGINE = MergeTree()\nORDER BY id;",
        "wait": true,
        "returnError": false,
        "x": 510,
        "y": 120,
        "wires": [
            [
                "ca85b3d3646e1222"
            ]
        ]
    },
    {
        "id": "886b73926f7b7afa",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 120,
        "wires": [
            [
                "0c75fd74244852ae"
            ]
        ]
    },
    {
        "id": "ca85b3d3646e1222",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 120,
        "wires": []
    },
    {
        "id": "31ae684fa5383355",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "SELECT from products with limit as param",
        "query": "select * from test_db.products p\norder by p.created_at desc\nLIMIT {limit_rows: UInt32}",
        "wait": false,
        "returnError": false,
        "x": 530,
        "y": 180,
        "wires": [
            [
                "1a2b3560fab24aa6"
            ]
        ]
    },
    {
        "id": "6a0d9e30ebe8203b",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 180,
        "wires": [
            [
                "6f95eae161bd8c3a"
            ]
        ]
    },
    {
        "id": "1a2b3560fab24aa6",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 180,
        "wires": []
    },
    {
        "id": "408b6239497fdaf8",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "insert",
        "table": "test_db.products",
        "output": "toArray",
        "name": "INSERT items into products from payload",
        "query": "",
        "wait": true,
        "returnError": false,
        "x": 520,
        "y": 300,
        "wires": [
            [
                "84a161e7da9a4568"
            ]
        ]
    },
    {
        "id": "84a161e7da9a4568",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 300,
        "wires": []
    },
    {
        "id": "c157c5b4dd7d11c3",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "SELECT count from products",
        "query": "select COUNT(*) as count\nfrom test_db.products",
        "wait": false,
        "returnError": true,
        "x": 480,
        "y": 240,
        "wires": [
            [
                "02566ebc7d9fdef1"
            ]
        ]
    },
    {
        "id": "02566ebc7d9fdef1",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload[0].count",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 240,
        "wires": []
    },
    {
        "id": "5fdb4220bb3b9722",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "SELECT using custom query and params",
        "query": "",
        "wait": false,
        "returnError": false,
        "x": 520,
        "y": 360,
        "wires": [
            [
                "9e92cde3f4904d51"
            ]
        ]
    },
    {
        "id": "9e92cde3f4904d51",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 790,
        "y": 360,
        "wires": []
    },
    {
        "id": "ca7e2baa29a36714",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "UPDATE using custom query and params",
        "query": "",
        "wait": false,
        "returnError": false,
        "x": 520,
        "y": 420,
        "wires": [
            [
                "3b5beaffac82bf77"
            ]
        ]
    },
    {
        "id": "3b5beaffac82bf77",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 420,
        "wires": []
    },
    {
        "id": "b0d863dabf6231e2",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set query",
        "func": "msg.query = `\nINSERT INTO test_db.products (article, brand, name, source, filename)\nSELECT \n    toString(number) AS article,\n    'Brand_' || toString(number % 10) AS brand,\n    'Product ' || toString(number) AS name,\n    NULL AS source,\n    NULL AS filename\nFROM numbers(100000);\n`;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 480,
        "wires": [
            [
                "c03933903d037616"
            ]
        ]
    },
    {
        "id": "c03933903d037616",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "INSERT 100k random products using query",
        "query": "",
        "wait": true,
        "returnError": false,
        "x": 530,
        "y": 480,
        "wires": [
            [
                "d8e43e14fe19d727"
            ]
        ]
    },
    {
        "id": "d8e43e14fe19d727",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 480,
        "wires": []
    },
    {
        "id": "1a733921a3f39742",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set query",
        "func": "msg.query = `\n  DELETE FROM test_db.products \n  WHERE id = {article_id: String}\n`;\nmsg.payload = {\n  article_id: 'b676478a-3697-4e4f-85d4-000000000000'\n};\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 540,
        "wires": [
            [
                "2771bca0e01a53dc"
            ]
        ]
    },
    {
        "id": "0f4765777c6ff7e9",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 540,
        "wires": []
    },
    {
        "id": "2771bca0e01a53dc",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "command",
        "table": "",
        "output": "toArray",
        "name": "DELETE using query and params",
        "query": "",
        "wait": false,
        "returnError": false,
        "x": 500,
        "y": 540,
        "wires": [
            [
                "0f4765777c6ff7e9"
            ]
        ]
    },
    {
        "id": "a5f98ee7f05a1ffc",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "command",
        "table": "",
        "output": "toArray",
        "name": "TRUNCATE TABLE test_db.products",
        "query": "TRUNCATE TABLE test_db.products;",
        "wait": false,
        "returnError": false,
        "x": 510,
        "y": 600,
        "wires": [
            [
                "298eca04c5db7e6e"
            ]
        ]
    },
    {
        "id": "298eca04c5db7e6e",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 600,
        "wires": []
    },
    {
        "id": "d1a5c5a3e03d71d6",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "DROP TABLE test_db.products",
        "props": [
            {
                "p": "query",
                "v": "DROP TABLE test_db.products;",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 170,
        "y": 660,
        "wires": [
            [
                "e0af7c62a8bfc983"
            ]
        ]
    },
    {
        "id": "e0af7c62a8bfc983",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "command",
        "table": "",
        "output": "toArray",
        "name": "",
        "query": "",
        "wait": false,
        "returnError": false,
        "x": 430,
        "y": 660,
        "wires": [
            [
                "258256050498e92e"
            ]
        ]
    },
    {
        "id": "258256050498e92e",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 660,
        "wires": []
    },
    {
        "id": "20d446625ec83e1a",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "custom mode",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "query",
                "v": "select id,article, brand, name, created_at, updated_at from test_db.products p order by p.created_at desc LIMIT {limit_rows: UInt32}",
                "vt": "str"
            },
            {
                "p": "mode",
                "v": "query",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"limit_rows\":100}",
        "payloadType": "json",
        "x": 110,
        "y": 720,
        "wires": [
            [
                "c2e303eec08a6c0f"
            ]
        ]
    },
    {
        "id": "c2e303eec08a6c0f",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "command",
        "table": "",
        "output": "toArray",
        "name": "",
        "query": "",
        "wait": false,
        "returnError": true,
        "x": 430,
        "y": 720,
        "wires": [
            [
                "f869e4e85123987f"
            ]
        ]
    },
    {
        "id": "f869e4e85123987f",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 720,
        "wires": []
    },
    {
        "id": "9bc0d945ff7ddd38",
        "type": "catch",
        "z": "f84fe21bfb96294f",
        "name": "catch all",
        "scope": null,
        "uncaught": false,
        "x": 100,
        "y": 20,
        "wires": [
            [
                "bd114522434a875a"
            ]
        ]
    },
    {
        "id": "bd114522434a875a",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "CATCH",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 260,
        "y": 20,
        "wires": []
    },
    {
        "id": "5415a83f2e110e84",
        "type": "clickhouse",
        "z": "f84fe21bfb96294f",
        "clientNode": "654e989bde223c42",
        "mode": "query",
        "table": "",
        "output": "toArray",
        "name": "CREATE DATABASE test_db",
        "query": "CREATE DATABASE IF NOT EXISTS test_db;",
        "wait": true,
        "returnError": false,
        "x": 480,
        "y": 60,
        "wires": [
            [
                "8faeb62ee690694c"
            ]
        ]
    },
    {
        "id": "d30fe2f8128f437f",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 60,
        "wires": [
            [
                "5415a83f2e110e84"
            ]
        ]
    },
    {
        "id": "8faeb62ee690694c",
        "type": "debug",
        "z": "f84fe21bfb96294f",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 60,
        "wires": []
    },
    {
        "id": "6f95eae161bd8c3a",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set payload",
        "func": "msg.payload = {\n    limit_rows:100\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 180,
        "wires": [
            [
                "31ae684fa5383355"
            ]
        ]
    },
    {
        "id": "c4d38bc239ff132e",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 480,
        "wires": [
            [
                "b0d863dabf6231e2"
            ]
        ]
    },
    {
        "id": "a35bd64e7f16c348",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 540,
        "wires": [
            [
                "1a733921a3f39742"
            ]
        ]
    },
    {
        "id": "945c87b6fefb261b",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 240,
        "wires": [
            [
                "c157c5b4dd7d11c3"
            ]
        ]
    },
    {
        "id": "500b46032fc4f404",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set payload",
        "func": "msg.payload = [\n    {\n        \"id\": \"b676478a-3697-4e4f-85d4-000000000000\",\n        \"article\": \"test entry\",\n        \"brand\": \"Custom\",\n        \"name\": \"TV 55\\\"\",\n        \"source\": \"Amazon\",\n        \"filename\": \"file1.csv\"\n    },\n    {\n        \"id\": \"b676478a-3697-4e4f-85d4-000000000001\",\n        \"article\": \"DEF456\",\n        \"brand\": \"Samsung\",\n        \"name\": \"Smartphone Galaxy S24\",\n        \"source\": \"AliExpress\",\n        \"filename\": null\n    },\n    {\n        \"id\": \"b676478a-3697-4e4f-85d4-000000000002\",\n        \"article\": \"GHI789\",\n        \"brand\": \"Apple\",\n        \"name\": \"MacBook Pro 16\\\"\",\n        \"source\": null,\n        \"filename\": \"file3.csv\"\n    }\n]\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 300,
        "wires": [
            [
                "408b6239497fdaf8"
            ]
        ]
    },
    {
        "id": "aa7295fe23cd3bb8",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 300,
        "wires": [
            [
                "500b46032fc4f404"
            ]
        ]
    },
    {
        "id": "8b466197c1e2170b",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set payload",
        "func": "msg.payload = {\"limit_rows\":100};\nmsg.query = `\n    select id, article, brand, name, created_at, updated_at\n    from test_db.products p\n    order by p.created_at desc\n    LIMIT {limit_rows: UInt32}\n`;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 360,
        "wires": [
            [
                "5fdb4220bb3b9722"
            ]
        ]
    },
    {
        "id": "1dbce4dcccd611a2",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 360,
        "wires": [
            [
                "8b466197c1e2170b"
            ]
        ]
    },
    {
        "id": "753d098ef447441f",
        "type": "function",
        "z": "f84fe21bfb96294f",
        "name": "set payload",
        "func": "msg.payload = {\n    \"new_brand\": \"Custom Updated\",\n    \"article_id\": \"b676478a-3697-4e4f-85d4-000000000000\"\n};\n\nmsg.query = `\n    ALTER TABLE test_db.products\n    UPDATE brand = {new_brand: String}\n    WHERE id = {article_id: String}\n`;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 420,
        "wires": [
            [
                "ca7e2baa29a36714"
            ]
        ]
    },
    {
        "id": "81e3bb0b8b667390",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 420,
        "wires": [
            [
                "753d098ef447441f"
            ]
        ]
    },
    {
        "id": "a3cd34609fdc8662",
        "type": "inject",
        "z": "f84fe21bfb96294f",
        "name": "timestamp",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 600,
        "wires": [
            [
                "a5f98ee7f05a1ffc"
            ]
        ]
    },
    {
        "id": "654e989bde223c42",
        "type": "clickhouse-client",
        "name": "clickhouse",
        "protocol": "http",
        "hostname": "localhost",
        "port": "8123",
        "dbName": "default",
        "pathname": "",
        "appName": "",
        "maxPoolSize": "100",
        "maxIdleTimeMS": "2500",
        "uri": "",
        "uriTabActive": "tab-uri-simple"
    }
]