-
Notifications
You must be signed in to change notification settings - Fork 83
Move feat from %sqlrender to %sqlcmd snippets #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| --- | ||
|
|
@@ -73,28 +72,48 @@ 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 the `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`. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this add some sentence like, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please click the |
||
|
|
||
| Now, let's see how to delete a stored snippet. | ||
|
|
||
| ```{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. | ||
| Now, let's see how to delete a stored snippet that other snippets are dependent on. Recall we have created `chinstrap_sub` which is dependent on `chinstrap`. | ||
|
|
||
| ```{code-cell} ipython3 | ||
| :tags: [hide-output] | ||
|
|
||
| %%sql --save chinstrap_sub | ||
| SELECT * FROM chinstrap where island == 'Dream' | ||
| print(chinstrap_sub_snippet) | ||
| ``` | ||
| +++ | ||
|
|
||
| Trying to delete the `chinstrap` snippet will display an error message: | ||
|
|
||
|
|
@@ -104,10 +123,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: | ||
neelasha23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```{code-cell} ipython3 | ||
|
|
||
| %sqlcmd snippets -D chinstrap | ||
| ``` | ||
|
|
||
|
|
@@ -130,6 +148,5 @@ SELECT * FROM chinstrap where island == 'Dream' | |
| Now, force delete `chinstrap` and its dependent `chinstrap_sub`: | ||
|
|
||
| ```{code-cell} ipython3 | ||
|
|
||
| %sqlcmd snippets -A chinstrap | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -144,10 +144,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) | ||
| ``` | ||
|
|
||
|
|
@@ -160,4 +160,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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly changed here?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||

Uh oh!
There was an error while loading. Please reload this page.