📝 Update markdown includes format (#1254)

This commit is contained in:
Sebastián Ramírez
2024-12-22 14:30:05 +00:00
committed by GitHub
parent 0c65fed61b
commit 5100200bea
39 changed files with 213 additions and 10659 deletions

View File

@@ -6,25 +6,7 @@ Now let's see how to update data using **SQLModel**.
As before, we'll continue from where we left off with the previous code.
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/indexes/tutorial002_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/indexes/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/indexes/tutorial002_py310.py ln[0] *}
Remember to remove the `database.db` file before running the examples to get the same results.
@@ -105,91 +87,11 @@ To get the same results, delete the `database.db` file before running the exampl
We'll start by selecting the hero `"Spider-Boy"`, this is the one we will update:
//// tab | Python 3.10+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-47]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-49]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:47] hl[44] *}
Let's not forget to add that `update_heroes()` function to the `main()` function so that we call it when executing the program from the command line:
//// tab | Python 3.10+
```Python hl_lines="6"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:56-63]!}
```
////
//// tab | Python 3.7+
```Python hl_lines="6"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:58-65]!}
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[56:63] hl[59] *}
Up to that point, running that in the command line will output:
@@ -224,49 +126,7 @@ Now that you have a `hero` object, you can simply set the value of the field (th
In this case, we will set the `age` to `16`:
//// tab | Python 3.10+
```Python hl_lines="10"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-49]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="10"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-51]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:49] hl[49] *}
## Add the Hero to the Session
@@ -274,49 +134,7 @@ Now that the hero object in memory has a change, in this case a new value for th
This is the same we did when creating new hero instances:
//// tab | Python 3.10+
```Python hl_lines="11"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-50]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="11"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-52]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:50] hl[50] *}
## Commit the Session
@@ -324,49 +142,7 @@ To save the current changes in the session, **commit** it.
This will save the updated hero in the database:
//// tab | Python 3.10+
```Python hl_lines="12"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-51]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="12"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-53]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:51] hl[51] *}
It will also save anything else that was added to the session.
@@ -399,49 +175,7 @@ The data in the object would be automatically refreshed if we accessed an attrib
But in this example we are not accessing any attribute, we will only print the object. And we also want to be explicit, so we will `.refresh()` the object directly:
//// tab | Python 3.10+
```Python hl_lines="13"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-52]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="13"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-54]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:52] hl[52] *}
This refresh will trigger the same SQL query that would be automatically triggered by accessing an attribute. So it will generate this output:
@@ -467,49 +201,7 @@ INFO Engine [generated in 0.00018s] (2,)
Now we can just print the hero:
//// tab | Python 3.10+
```Python hl_lines="14"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001_py310.py[ln:42-53]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="14"
# Code above omitted 👆
{!./docs_src/tutorial/update/tutorial001.py[ln:44-55]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/update/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/update/tutorial001.py!}
```
////
///
{* ./docs_src/tutorial/update/tutorial001_py310.py ln[42:53] hl[53] *}
Because we refreshed it right after updating it, it has fresh data, including the new `age` we just updated.