{ "kind": "open-flow-workflow", "version": 1, "name": "Create, Insert and Update a Snowflake Table", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_027a92292e06ed6b": { "name": "Enter Snowflake account URL", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "account" } ] }, "n_ef2017833327c070": { "inputs": { "account": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_027a92292e06ed6b", "output": "account" } ] } }, "name": "Prepare SQL statements", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "account" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare SQL statements", "moduleId": "n_c74363c821efde99", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_f7a7571c1bdef7d1": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ef2017833327c070", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ef2017833327c070", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Execute SQL statements", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Execute SQL statements", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_70b1b2792c57c7e5": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f7a7571c1bdef7d1", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_f7a7571c1bdef7d1", "output": "statusCode" } ] }, "account": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_027a92292e06ed6b", "output": "account" } ] }, "previous": { "kind": "value", "value": null } }, "name": "Check submission", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "account" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previous" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "done" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "result" } ], "name": "Check submission", "moduleId": "n_8452ab484ee77b62", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_73ad85183850e3cf": { "inputs": {}, "name": "Statements complete?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "done", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_70b1b2792c57c7e5", "output": "done" } }, "operator": "isTrue" } ] } ] } ] }, "n_72bc5ae735fa5c21": { "inputs": {}, "name": "Wait for Snowflake", "kind": "wait", "inputDefinitions": [], "prompt": "Wait for Snowflake", "autoContinue": { "kind": "after", "durationMs": 5000 } }, "n_7ed4852542d47540": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_70b1b2792c57c7e5", "output": "url" } ] }, "auth.token": { "kind": "unset" } }, "name": "Check statement status", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Check statement status", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_9be1db5c88d1ffc5": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7ed4852542d47540", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7ed4852542d47540", "output": "statusCode" } ] }, "account": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_027a92292e06ed6b", "output": "account" } ] }, "previous": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9be1db5c88d1ffc5", "output": "state" } ] } }, "name": "Check completion", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "account" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previous" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "done" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "result" } ], "name": "Check completion", "moduleId": "n_27ca27a041834622", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_0e71a7ced983b82f": { "inputs": {}, "name": "Execution complete?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "done", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_9be1db5c88d1ffc5", "output": "done" } }, "operator": "isTrue" } ] } ] } ] } }, "edges": [ { "source": "n_027a92292e06ed6b", "target": "n_ef2017833327c070" }, { "source": "n_ef2017833327c070", "target": "n_f7a7571c1bdef7d1" }, { "source": "n_f7a7571c1bdef7d1", "target": "n_70b1b2792c57c7e5" }, { "source": "n_70b1b2792c57c7e5", "target": "n_73ad85183850e3cf" }, { "source": "n_73ad85183850e3cf", "target": "n_72bc5ae735fa5c21", "sourceHandle": "otherwise" }, { "source": "n_72bc5ae735fa5c21", "target": "n_7ed4852542d47540", "sourceHandle": "continue" }, { "source": "n_7ed4852542d47540", "target": "n_9be1db5c88d1ffc5" }, { "source": "n_9be1db5c88d1ffc5", "target": "n_0e71a7ced983b82f" }, { "source": "n_0e71a7ced983b82f", "target": "n_72bc5ae735fa5c21", "sourceHandle": "otherwise" } ] } }, "modules": { "n_c74363c821efde99": { "name": "Prepare SQL statements", "imports": [], "source": "export default function prepare({account}){if(typeof account!=='string'||!/^https:\\/\\/[a-z0-9][a-z0-9.-]*\\.snowflakecomputing\\.com$/i.test(account))throw Error('Enter the Snowflake account URL without a trailing slash');return{url:account+'/api/v2/statements',body:{statement:\"CREATE TABLE docs (id INT, name STRING); INSERT INTO docs (id,name) VALUES (1,'n8n'); UPDATE docs SET name='nodemation' WHERE id=1;\",parameters:{MULTI_STATEMENT_COUNT:'3'}}}}\n" }, "n_8452ab484ee77b62": { "name": "Check submission", "imports": [], "source": "export default function result({body,statusCode,account,previous}){if(!body||typeof body!=='object'||Array.isArray(body))throw Error('Invalid Snowflake response');const count=(previous?.count||0)+1;if(statusCode===200&&(!Array.isArray(body.statementHandles)||body.statementHandles.length!==3))throw Error('Snowflake did not confirm all three statements');if(statusCode===200)return{done:true,url:'',state:{count,url:''},result:body};if(statusCode!==202||typeof body.statementHandle!=='string'||!/^[a-z0-9-]+$/i.test(body.statementHandle)||count>60)throw Error('Snowflake execution not confirmed; inspect its status before retrying');return{done:false,url:account+'/api/v2/statements/'+body.statementHandle,state:{count,url:account+'/api/v2/statements/'+body.statementHandle},result:{}}}\n" }, "n_27ca27a041834622": { "name": "Check completion", "imports": [], "source": "export default function result({body,statusCode,account,previous}){if(!body||typeof body!=='object'||Array.isArray(body))throw Error('Invalid Snowflake response');const count=(previous?.count||0)+1;if(statusCode===200&&(!Array.isArray(body.statementHandles)||body.statementHandles.length!==3))throw Error('Snowflake did not confirm all three statements');if(statusCode===200)return{done:true,url:'',state:{count,url:''},result:body};if(statusCode!==202||typeof body.statementHandle!=='string'||!/^[a-z0-9-]+$/i.test(body.statementHandle)||count>60)throw Error('Snowflake execution not confirmed; inspect its status before retrying');return{done:false,url:account+'/api/v2/statements/'+body.statementHandle,state:{count,url:account+'/api/v2/statements/'+body.statementHandle},result:{}}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }