Skip to content

Commit

Permalink
Move feat from %sqlrender to %sqlcmd snippets
Browse files Browse the repository at this point in the history
Moved features, added FutureWarning, update API Reference documentation, modified test functions

update changelog

update changelog for #647

Update CHANGELOG.md

documentation change of moving sqlrender feature

manually relocating changes

resolving docs build failed

lint

fixing readthedocs

remove invalid snippet from documenation

subquery and more detailed error message added

lint

change in formatting

update toc
  • Loading branch information
bbeat2782 committed Jun 28, 2023
1 parent ece54c1 commit b84b85b
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 132 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## 0.7.10dev

* [Feature] Modified `TableDescription` to add styling, generate messages and format the calculated outputs (#459)
* [Feature] Support flexible spacing `myvar=<<` operator ([#525](https://github.com/ploomber/jupysql/issues/525))
* [Feature] Moved `%sqlrender` feature to `%sqlcmd snippets` (#647)
* [Feature] Modified `TableDescription` to add styling, generate messages and format the calculated outputs (#459)
* [Doc] Modified integrations content to ensure they're all consistent (#523)
* [Doc] Document --persist-replace in API section (#539)
* [Fix] Fixed CI issue by updating `invalid_connection_string_duckdb` in `test_magic.py` (#631)
Expand Down
1 change: 0 additions & 1 deletion doc/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ parts:
chapters:
- file: api/magic-sql
- file: api/magic-plot
- file: api/magic-render
- file: api/magic-snippets
- file: api/configuration
- file: api/python
Expand Down
82 changes: 0 additions & 82 deletions doc/api/magic-render.md

This file was deleted.

39 changes: 27 additions & 12 deletions doc/api/magic-snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
myst:
html_meta:
description lang=en: Documentation for %sqlcmd snippets
from JupySQL
description lang=en: Documentation for %sqlcmd snippets from JupySQL
keywords: jupyter, sql, jupysql, snippets
property=og:locale: en_US
---
Expand Down Expand Up @@ -73,28 +72,46 @@ Returns all the snippets saved in the environment

Arguments:

`{snippet_name}` Return a snippet.

`-d`/`--delete` Delete a snippet.

`-D`/`--delete-force` Force delete a snippet. This may be useful if there are other dependent snippets, and you still need to delete this snippet.

`-A`/`--delete-force-all` Force delete a snippet and all dependent snippets.

```{code-cell} ipython3
chinstrap_snippet = %sqlcmd snippets chinstrap
print(chinstrap_snippet)
```

This returns the stored snippet `chinstrap`.

Calling `%sqlcmd snippets {snippet_name}` also works on a snippet that is dependent on others. To demonstrate it, let's create a snippet dependent on `chinstrap` snippet.

```{code-cell} ipython3
%%sql --save chinstrap_sub
SELECT * FROM chinstrap where island == 'Dream'
```

```{code-cell} ipython3
chinstrap_sub_snippet = %sqlcmd snippets chinstrap_sub
print(chinstrap_sub_snippet)
```

This returns the stored snippet `chinstrap_sub`.

```{code-cell} ipython3
%sqlcmd snippets -d gentoo
```

This deletes the stored snippet `gentoo`.

To demonstrate `force-delete` let's create a snippet dependent on `chinstrap` snippet.
To demonstrate `force-delete` let's first confirm there is a snippet dependent on `chinstrap` snippet.

```{code-cell} ipython3
:tags: [hide-output]
%%sql --save chinstrap_sub
SELECT * FROM chinstrap where island == 'Dream'
%sqlcmd snippets
```
+++

Trying to delete the `chinstrap` snippet will display an error message:

Expand All @@ -104,10 +121,9 @@ Trying to delete the `chinstrap` snippet will display an error message:
%sqlcmd snippets -d chinstrap
```

If you still wish to delete this snippet, you can run the below command:
If you still wish to delete this snippet, you should use `force-delete` by running the below command:

```{code-cell} ipython3
%sqlcmd snippets -D chinstrap
```

Expand All @@ -130,6 +146,5 @@ SELECT * FROM chinstrap where island == 'Dream'
Now, force delete `chinstrap` and its dependent `chinstrap_sub`:

```{code-cell} ipython3
%sqlcmd snippets -A chinstrap
```
16 changes: 7 additions & 9 deletions doc/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.4
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
myst:
html_meta:
description lang=en: "Use JupySQL to organize large SQL queries in a Jupyter notebook"
keywords: "jupyter, sql, jupysql"
property=og:locale: "en_US"
description lang=en: Use JupySQL to organize large SQL queries in a Jupyter notebook
keywords: jupyter, sql, jupysql
property=og:locale: en_US
---

# Organizing Large Queries
Expand Down Expand Up @@ -109,7 +109,6 @@ Join the filtered genres and tracks, so we only get Rock and Metal tracks, and s

We automatically extract the tables from the query and infer the dependencies from all the saved snippets.


```{code-cell} ipython3
%%sql --save track_fav
SELECT t.*
Expand All @@ -127,7 +126,6 @@ GROUP BY artist
ORDER BY COUNT(*) DESC
```


```{note}
A saved snippet will override an existing table with the same name during query formation. If you wish to delete a snippet please refer to [sqlcmd snippets API](api/magic-snippets.md).
Expand All @@ -144,10 +142,10 @@ top_artist.bar()

It looks like Iron Maiden had the highest number of rock and metal songs in the table.

We can render the full query with the `%sqlrender` magic:
We can render the full query with the `%sqlcmd snippets {name}` magic:

```{code-cell} ipython3
final = %sqlrender top_artist
final = %sqlcmd snippets top_artist
print(final)
```

Expand All @@ -160,4 +158,4 @@ We can verify the retrieved query returns the same result:

## Summary

In the given example, we demonstrated JupySQL's usage as a tool for managing large SQL queries in Jupyter Notebooks. It effectively broke down a complex query into smaller, organized parts, simplifying the process of analyzing a record store's sales database. By using JupySQL, users can easily maintain and reuse their queries, enhancing the overall data analysis experience.
In the given example, we demonstrated JupySQL's usage as a tool for managing large SQL queries in Jupyter Notebooks. It effectively broke down a complex query into smaller, organized parts, simplifying the process of analyzing a record store's sales database. By using JupySQL, users can easily maintain and reuse their queries, enhancing the overall data analysis experience.
2 changes: 1 addition & 1 deletion doc/integrations/mariadb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
}
],
"source": [
"query = %sqlrender trip_stats\n",
"query = %sqlcmd snippets trip_stats\n",
"print(query)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/integrations/mssql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@
}
],
"source": [
"query = %sqlrender trip_stats\n",
"query = %sqlcmd snippets trip_stats\n",
"print(query)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/integrations/mysql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@
}
],
"source": [
"query = %sqlrender trip_stats\n",
"query = %sqlcmd snippets trip_stats\n",
"print(query)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions doc/integrations/oracle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@
}
],
"source": [
"query = %sqlrender saved_cte\n",
"query = %sqlcmd snippets saved_cte\n",
"print(query)"
]
},
Expand Down Expand Up @@ -757,7 +757,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
"version": "3.10.11"
},
"myst": {
"html_meta": {
Expand Down
4 changes: 2 additions & 2 deletions doc/integrations/postgres-connect.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@
}
],
"source": [
"query = %sqlrender trip_stats\n",
"query = %sqlcmd snippets trip_stats\n",
"print(query)"
]
},
Expand Down Expand Up @@ -1058,7 +1058,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.11"
},
"myst": {
"html_meta": {
Expand Down
2 changes: 1 addition & 1 deletion doc/integrations/snowflake.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@
}
],
"source": [
"final = %sqlrender no_nulls\n",
"final = %sqlcmd snippets no_nulls\n",
"print(final)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion doc/integrations/trinodb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@
}
],
"source": [
"query = %sqlrender trip_stats\n",
"query = %sqlcmd snippets trip_stats\n",
"print(query)"
]
},
Expand Down
Loading

0 comments on commit b84b85b

Please sign in to comment.