Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions docs/advanced/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ Let's say that each hero in the database will have an amount of money. We could
# More code here later 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/advanced/decimal/tutorial001.py!}
```

</details>
///

Here we are saying that `money` can have at most `5` digits with `max_digits`, **this includes the integers** (to the left of the decimal dot) **and the decimals** (to the right of the decimal dot).

Expand Down Expand Up @@ -96,14 +95,13 @@ When creating new models you can actually pass normal (`float`) numbers, Pydanti
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/advanced/decimal/tutorial001.py!}
```

</details>
///

## Select Decimal data

Expand All @@ -117,14 +115,13 @@ Then, when working with Decimal types, you can confirm that they indeed avoid th
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/advanced/decimal/tutorial001.py!}
```

</details>
///

## Review the results

Expand Down
40 changes: 16 additions & 24 deletions docs/tutorial/automatic-id-none-refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ But the same `id` field actually **can be `None`** in the Python code, so we dec
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

Next, I'll show you a bit more about the synchronization of data between the database and the Python code.

Expand All @@ -39,14 +38,13 @@ When we create a new `Hero` instance, we don't set the `id`:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

### How `Optional` Helps

Expand Down Expand Up @@ -82,14 +80,13 @@ We can confirm that by printing our heroes before adding them to the database:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

That will output:

Expand Down Expand Up @@ -128,14 +125,13 @@ We can verify by creating a session using a `with` block and adding the objects.
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

This will, again, output the `id`s of the objects as `None`:

Expand Down Expand Up @@ -168,14 +164,13 @@ Then we can `commit` the changes in the session, and print again:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

And now, something unexpected happens, look at the output, it seems as if the `Hero` instance objects had no data at all:

Expand Down Expand Up @@ -241,14 +236,13 @@ To confirm and understand how this **automatic expiration and refresh** of data
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

Now we are actually accessing the attributes, because instead of printing the whole object `hero_1`:

Expand Down Expand Up @@ -338,14 +332,13 @@ You can do that too with `session.refresh(object)`:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

When Python executes this code:

Expand Down Expand Up @@ -411,14 +404,13 @@ There are no surprises here, it still works:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py!}
```

</details>
///

And the output shows again the same data:

Expand Down
30 changes: 12 additions & 18 deletions docs/tutorial/connect/create-connected-rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ We will later update **Spider-Boy** to add him to the **Preventers** team too, b

We will continue with the code in the previous example and we will add more things to it.

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/create_tables/tutorial001.py!}
```

</details>
///

Make sure you remove the `database.db` file before running the examples to get the same results.

Expand All @@ -72,14 +71,13 @@ Let's start by creating two teams:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/insert/tutorial001.py!}
```

</details>
///

This would hopefully look already familiar.

Expand All @@ -103,14 +101,13 @@ Let's not forget to add this function `create_heroes()` to the `main()` function
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/insert/tutorial001.py!}
```

</details>
///

## Run it

Expand Down Expand Up @@ -151,14 +148,13 @@ As the `Hero` class model now has a field (column, attribute) `team_id`, we can
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/insert/tutorial001.py!}
```

</details>
///

We haven't committed this hero to the database yet, but there are already a couple of things to pay **attention** to.

Expand Down Expand Up @@ -190,14 +186,13 @@ Let's now create two more heroes:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/insert/tutorial001.py!}
```

</details>
///

When creating `hero_rusty_man`, we are accessing `team_preventers.id`, so that will also trigger a refresh of its data, generating an output of:

Expand Down Expand Up @@ -236,14 +231,13 @@ Now let's refresh and print those new heroes to see their new ID pointing to the
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/insert/tutorial001.py!}
```

</details>
///


If we execute that in the command line, it will output:
Expand Down
20 changes: 8 additions & 12 deletions docs/tutorial/connect/create-connected-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ Import the things we need from `sqlmodel` and create a new `Team` model:
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/create_tables/tutorial001.py!}
```

</details>
///

This is very similar to what we have been doing with the `Hero` model.

Expand All @@ -95,14 +94,13 @@ This is the same model we have been using up to now, we are just adding the new
# Code below omitted 👇
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/create_tables/tutorial001.py!}
```

</details>
///

Most of that should look familiar:

Expand Down Expand Up @@ -142,14 +140,13 @@ Now we can add the same code as before to create the engine and the function to
{!./docs_src/tutorial/connect/create_tables/tutorial001.py[ln:21-28]!}
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/create_tables/tutorial001.py!}
```

</details>
///

And as before, we'll call this function from another function `main()`, and we'll add that function `main()` to the main block of the file:

Expand All @@ -159,14 +156,13 @@ And as before, we'll call this function from another function `main()`, and we'l
{!./docs_src/tutorial/connect/create_tables/tutorial001.py[ln:31-36]!}
```

<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview

```Python
{!./docs_src/tutorial/connect/create_tables/tutorial001.py!}
```

</details>
///

## Run the Code

Expand Down
Loading