Skip to content

Commit 16cdf77

Browse files
authored
Pin database to sql (windmill-labs#535)
1 parent 96e0407 commit 16cdf77

File tree

19 files changed

+126
-34
lines changed

19 files changed

+126
-34
lines changed

blog/2023-11-22-why-is-windmill-the-fastest-workflow-engine/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ hand-built workflow engine written on top of the amazing [BEAM](<https://en.wiki
134134

135135
There are tons of workflow engines, but not many of them are self-hostable and generic enough to support arbitrary workloads of jobs defined in code,
136136
and even those have restrictions:
137-
Some like Airflow and Prefect support only one runtime (Python). Windmill on the other hand supports Typescript/Javascript, Python, Go, Bash and direct SQL queries to BigQuery, Snowflake, Mysql, Postgresql, MSSQL. And its design makes it easy to add more upon request.
137+
Some like Airflow and Prefect support only one runtime (Python). Windmill on the other hand supports Typescript/Javascript, Python, Go, Bash and direct SQL queries to BigQuery, Snowflake, Mysql, Postgresql, MS SQL. And its design makes it easy to add more upon request.
138138
Some are notoriously hard to write for (because of complex SDKs, looking at you Airflow's XCOM or Temporal idempotency primitives) and deploy to. Windmill offers an [integrated DX to build and test workflows](/docs/flows/flow_editor) in a few minutes interactively in a mix of raw code for the steps and low-code (or YAML) for the DAG itself. It is also possible to define them wholly with code and full version control using our [VS Code extension](/blog/launch-week-1/vscode-extension).
139139

140140
One benefit of being very fast is that it makes running tests very fast too both in terms of latency to start and to run. Wasting time waiting for previews and tests to run is not fun.
@@ -303,7 +303,7 @@ json*path.map(|x| x.split(".").map(|x| x.to_string()).collect::<Vec<*>>())
303303

304304
## Workers efficiency
305305

306-
In normal mode, workers pull job one at a time, identify the language used by the job (Python, TypeScript, Go, Bash, SnowFlake, PostgreSql, MySql, MSSQL, BigQquery) and then spawn the corresponding runtime then run the job.
306+
In normal mode, workers pull job one at a time, identify the language used by the job (Python, TypeScript, Go, Bash, SnowFlake, PostgreSql, MySql, MS SQL, BigQquery) and then spawn the corresponding runtime then run the job.
307307

308308
Workers run jobs bare, without running containers which gives us a performance boost compared to container based workflow engines. However, for sandboxing purposes, workers themselves can be run inside containers and can run each job in an nsjail sandbox.
309309

changelog/2023-12-17-decision-tree/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: v1.227.0
44
title: Decision Tree
55
tags: ['App Editor', 'Component']
66
image: ./decision-tree.png
7-
description: This component allows you to create a decision tree. The decision tree is controlled by a flow-like structure. Each node in the tree represents a decision point and can lead to one or more subsequent nodes based on specified conditions.
7+
description: This app component allows you to create a decision tree controlled by a flow-like structure. Each node in the tree represents a decision point with a dedicated subgrid and can lead to one or more subsequent nodes based on specified conditions.
88
features:
99
[
1010
'Each node has its dedicated container',

changelog/2024-01-23-rich-render/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: v1.251.1
44
title: Rich results render
55
tags: ['Scripts', 'Flow Editor']
66
image: ./rich-render.png
7-
description: Added rich results render for arrays of objects and markdown.
7+
description: Added rich results render for arrays of objects and markdown in scripts and flows.
88
features:
99
[
1010
'Support for arrays of objects.',
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
slug: pin-database
3+
version: v1.280.0
4+
title: Pin Database in SQL Scripts
5+
tags: ['Scripts', 'SQL']
6+
video: /videos/pin_database.mp4
7+
description: Pin database resource path directly within a SQL script instead of filling it through the UI.
8+
features:
9+
[
10+
'Use "-- database resource_path" in your script.',
11+
'Works with PostgreSQL, MySQL, BigQuery, Snowflake, MS SQL, GraphQL.'
12+
]
13+
docs: /docs/getting_started/scripts_quickstart/sql
14+
---

docs/apps/4_app_configuration_settings/1_app_component_library.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ The Carousel List component enables duplication of cards or rows with consistent
127127

128128
### [Decision Tree](./decision_tree.mdx)
129129

130-
This component allows you to create a decision tree. The decision tree is controlled by a flow-like structure. Each node in the tree represents a decision point and can lead to one or more subsequent nodes based on specified conditions.
130+
This app component allows you to create a decision tree controlled by a flow-like structure. Each node in the tree represents a decision point with a dedicated subgrid and can lead to one or more subsequent nodes based on specified conditions.
131131

132132
![Decision Tree](../../assets/apps/4_app_component_library/decision-tree.png.webp)
133133

docs/apps/4_app_configuration_settings/database_studio.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ This component allows you to create a database studio. The database studio is a
2525

2626
The component can be configured with the following properties:
2727

28-
- `resource`: The PostgreSQL resource to use.
28+
- `resource`: The [PostgreSQL](../../getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx#postgresql) / [MySQL](../../getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx#mysql) / [MS SQL](../../getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx#ms-sql) / [Snowflake](../../getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx#snowflake) / [BigQuery](../../getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx#bigquery) resource to use.
2929
- `table`: The table to use. Once the resource is selected, the list will be populated with the tables available in the database.
3030

3131
Once a resource is selected, you can explore the schema: It will open a drawer the schema of the database.
3232

3333
## Column definition
3434

35-
When the table is selected, the column definitions will automatically synchronise with the columns of the table.
35+
When the table is selected, the column definitions will automatically synchronize with the columns of the table.
3636

3737
The column can be configured with the following properties:
3838

docs/apps/4_app_configuration_settings/decision_tree.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DocCard from '@site/src/components/DocCard';
22

33
# Decision Tree
44

5-
This component allows you to create a decision tree. The decision tree is controlled by a flow-like structure. Each node in the tree represents a decision point and can lead to one or more subsequent nodes based on specified conditions.
5+
This app component allows you to create a decision tree controlled by a flow-like structure. Each node in the tree represents a decision point with a dedicated subgrid and can lead to one or more subsequent nodes based on specified conditions.
66

77
<video
88
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"

docs/core_concepts/3_resources_and_types/index.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,38 @@ _Python_
180180
/>
181181
</div>
182182

183+
### States Path
184+
185+
States are stored in a [path](../16_roles_and_permissions/index.mdx#path) that is unique to the script, script within a flow or schedule. The state path [is defined](https://github.com/windmill-labs/windmill/blob/19547e90c681db1566559c31a508eb093eb05968/backend/windmill-common/src/variables.rs#L150) as:
186+
187+
```rust
188+
let state_path = {
189+
let trigger = if schedule_path.is_some() {
190+
username.to_string()
191+
} else {
192+
"user".to_string()
193+
};
194+
195+
if let Some(flow_path) = flow_path.clone() {
196+
format!(
197+
"{flow_path}/{}_{trigger}",
198+
step_id.clone().unwrap_or_else(|| "nostep".to_string())
199+
)
200+
} else if let Some(script_path) = path.clone() {
201+
let script_path = if script_path.ends_with("/") {
202+
"noname".to_string()
203+
} else {
204+
script_path
205+
};
206+
format!("{script_path}/{trigger}")
207+
} else {
208+
format!("u/{username}/tmp_state")
209+
}
210+
};
211+
```
212+
213+
For example, if a script using states is used within a flow that is scheduled, the state will take a new path as: `folder/flow_path/script_path/schedule_path`, or more concretely: `u/username/u/username/flow_name/u/username/script_name/u/username/schedule_name`.
214+
183215
## Using Resources
184216

185217
Resources can be used [passed as script parameters](#passing-resources-as-parameters-to-scripts-preferred) or [directly fetched](#fetching-them-from-within-a-script-by-using-the-wmill-client-in-the-respective-language) within code.

docs/flows/3_editor_components.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ There are special kinds of scripts, [SQL and query languages](../getting_started
290290

291291
- Postgres
292292
- MySQL
293-
- MSSQL
293+
- MS SQL
294294
- BigQuery
295295
- Snowflake
296296

docs/getting_started/0_scripts_quickstart/5_sql_quickstart/index.mdx

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: 'Quickstart PostgreSQL, MySQL, MSSQL, BigQuery, Snowflake'
2+
title: 'Quickstart PostgreSQL, MySQL, MS SQL, BigQuery, Snowflake'
33
slug: '/getting_started/scripts_quickstart/sql'
44
---
55

66
import DocCard from '@site/src/components/DocCard';
77

8-
# PostgreSQL, MySQL, MSSQL, BigQuery, Snowflake
8+
# PostgreSQL, MySQL, MS SQL, BigQuery, Snowflake
99

1010
In this quick start guide, we will write our first script in SQL. We will see how to connect a Windmill instance to an external SQL service and then send queries to the database using Windmill Scripts.
1111

@@ -27,7 +27,7 @@ Windmill supports [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www
2727
Windmill provides integrations with many different apps and services with the use
2828
of [Resources](../../../core_concepts/3_resources_and_types/index.mdx). Resources are rich objects in JSON that allow to store configuration and credentials.
2929

30-
Each Resource has a _Resource Type_ ([PostgreSQL](https://hub.windmill.dev/resource_types/114/postgresql), [MySQL](https://hub.windmill.dev/resource_types/111/mysql), [MSSQL](https://hub.windmill.dev/resource_types/132/ms_sql_server), [BigQuery](https://hub.windmill.dev/resource_types/108/bigquery), [Snowflake](https://hub.windmill.dev/resource_types/107/snowflake))
30+
Each Resource has a _Resource Type_ ([PostgreSQL](https://hub.windmill.dev/resource_types/114/postgresql), [MySQL](https://hub.windmill.dev/resource_types/111/mysql), [MS SQL](https://hub.windmill.dev/resource_types/132/ms_sql_server), [BigQuery](https://hub.windmill.dev/resource_types/108/bigquery), [Snowflake](https://hub.windmill.dev/resource_types/107/snowflake))
3131
that defines the schema that the resource of this type needs to implement. Schemas implement the
3232
[JSON Schema specification](https://json-schema.org/).
3333

@@ -114,7 +114,7 @@ Fill out the form with the information of your MySQL instance and "Test connecti
114114
| database | string | Database name | | true | Created in MySQL (e.g., via phpMyAdmin or MySQL Workbench) or provided by your hosting |
115115
| password | string | User's password | | true | Created in MySQL (e.g., via phpMyAdmin or MySQL Workbench) or provided by your hosting |
116116

117-
### MSSQL
117+
### MS SQL
118118

119119
To be able to connect to a [Microsoft SQL Server](https://www.microsoft.com/sql-server) instance, we'll need to define a Resource with the `ms_sql_server` Resource Type first.
120120

@@ -129,11 +129,11 @@ Fill out the form with the information of your MySQL instance and "Test connecti
129129

130130
| Property | Type | Description | Default | Required | Where to Find |
131131
| -------- | ------ | --------------- | ------- | -------- | ------------------------------------------------------------------------------------- |
132-
| host | string | Instance host | | true | Your hosting provider's control panel or in your server's MSSQL configuration file |
133-
| port | number | Instance port | | false | Your hosting provider's control panel or in your server's MSSQL configuration file |
134-
| user | string | Username | | true | Created in MSSQL (e.g., via SQL Server Management Studio) or provided by your hosting |
135-
| dbname | string | Database name | | true | Created in MSSQL (e.g., via SQL Server Management Studio) or provided by your hosting |
136-
| password | string | User's password | | true | Created in MSSQL (e.g., via SQL Server Management Studio) or provided by your hosting |
132+
| host | string | Instance host | | true | Your hosting provider's control panel or in your server's MS SQL configuration file |
133+
| port | number | Instance port | | false | Your hosting provider's control panel or in your server's MS SQL configuration file |
134+
| user | string | Username | | true | Created in MS SQL (e.g., via SQL Server Management Studio) or provided by your hosting |
135+
| dbname | string | Database name | | true | Created in MS SQL (e.g., via SQL Server Management Studio) or provided by your hosting |
136+
| password | string | User's password | | true | Created in MS SQL (e.g., via SQL Server Management Studio) or provided by your hosting |
137137

138138
### BigQuery
139139

@@ -262,7 +262,7 @@ You can directly "Test connection" if needed.
262262
## Create Script
263263

264264
Next, let's create a script that will use the newly created Resource. From the <a href="https://app.windmill.dev/" rel="nofollow">Home</a> page,
265-
click on the "+Script" button. Name the Script, give it a summary, and select your preferred language, [PostgreSQL](#postgresql-1), [MySQL](#mysql-1), [MSSQL](#mssql-1), [BigQuery](#bigquery-1), [Snowflake](#snowflake-1).
265+
click on the "+Script" button. Name the Script, give it a summary, and select your preferred language, [PostgreSQL](#postgresql-1), [MySQL](#mysql-1), [MS SQL](#ms-sql-1), [BigQuery](#bigquery-1), [Snowflake](#snowflake-1).
266266

267267
![Script creation first step](../../../assets/integrations/sql_new_script.png.webp)
268268

@@ -280,6 +280,16 @@ INSERT INTO demo VALUES ($1::TEXT, $2::INT) RETURNING *
280280

281281
"name1", "name2" being the names of the arguments, and "default arg" the optional default value.
282282

283+
Database resource can be specified from the UI or directly within script with a line `-- database resource_path`.
284+
285+
<video
286+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
287+
controls
288+
src="/videos/pin_database.mp4"
289+
/>
290+
291+
<br/>
292+
283293
You can then write your prepared statement.
284294

285295
<video
@@ -300,11 +310,20 @@ INSERT INTO demo VALUES (?, ?)
300310

301311
"name1", "name2" being the names of the arguments, and "default arg" the optional default value.
302312

313+
Database resource can be specified from the UI or directly within script with a line `-- database resource_path`.
314+
315+
<video
316+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
317+
controls
318+
src="/videos/pin_database.mp4"
319+
/>
320+
321+
<br/>
303322
You can then write your prepared statement.
304323

305324
![Mysql statement](./mysql_statement.png.webp)
306325

307-
### MSSQL
326+
### MS SQL
308327

309328
Arguments need to be passed in the given format:
310329

@@ -316,6 +335,15 @@ INSERT INTO demo VALUES (@p1, @p2)
316335

317336
"name1", "name2" being the names of the arguments, and "default arg" the optional default value.
318337

338+
Database resource can be specified from the UI or directly within script with a line `-- database resource_path`.
339+
340+
<video
341+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
342+
controls
343+
src="/videos/pin_database.mp4"
344+
/>
345+
346+
<br/>
319347
You can then write your prepared statement.
320348

321349
![Mysql statement](./mssql_statement.png.webp)
@@ -333,6 +361,15 @@ INSERT INTO `demodb.demo` VALUES (@name1, @name2, @name3)
333361

334362
"name1", "name2", "name3" being the names of the arguments, "default arg" the optional default value and `string`, `integer` and `string[]` the types.
335363

364+
Database resource can be specified from the UI or directly within script with a line `-- database resource_path`.
365+
366+
<video
367+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
368+
controls
369+
src="/videos/pin_database.mp4"
370+
/>
371+
372+
<br/>
336373
You can then write your prepared statement.
337374

338375
<video
@@ -353,6 +390,15 @@ INSERT INTO demo VALUES (?, ?)
353390

354391
"name1", "name2" being the names of the arguments, "default arg" the optional default value and `varchar` & `int` the types.
355392

393+
Database resource can be specified from the UI or directly within script with a line `-- database resource_path`.
394+
395+
<video
396+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
397+
controls
398+
src="/videos/pin_database.mp4"
399+
/>
400+
401+
<br/>
356402
You can then write your prepared statement.
357403

358404
![Snowflake statement](./snowflake_statement.png.webp)

0 commit comments

Comments
 (0)