Skip to content

Commit

Permalink
馃敡 Update config with new pymdown extensions (#712)
Browse files Browse the repository at this point in the history
* 馃敡 Update config with new pymdown extensions

* 馃摑 Update admonition blocks syntax

* 馃摑 Update syntax for tabs with new pymdown extensions
  • Loading branch information
tiangolo committed Nov 28, 2023
1 parent 71baff6 commit a95bd38
Show file tree
Hide file tree
Showing 39 changed files with 709 additions and 360 deletions.
32 changes: 22 additions & 10 deletions docs/advanced/decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ In most cases this would probably not be a problem, for example measuring views

Pydantic has special support for `Decimal` types using the <a href="https://pydantic-docs.helpmanual.io/usage/types/#arguments-to-condecimal" class="external-link" target="_blank">`condecimal()` special function</a>.

!!! tip
Pydantic 1.9, that will be released soon, has improved support for `Decimal` types, without needing to use the `condecimal()` function.
/// tip

But meanwhile, you can already use this feature with `condecimal()` in **SQLModel** it as it's explained here.
Pydantic 1.9, that will be released soon, has improved support for `Decimal` types, without needing to use the `condecimal()` function.

But meanwhile, you can already use this feature with `condecimal()` in **SQLModel** it as it's explained here.

///

When you use `condecimal()` you can specify the number of digits and decimal places to support. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns.

!!! info
For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.
/// info

For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.DECIMAL" class="external-link" target="_blank">SQLAlchemy's `DECIMAL` type</a>.

///

## Decimals in SQLModel

Expand Down Expand Up @@ -72,8 +78,11 @@ We are also saying that the number of decimal places (to the right of the decima
* `123`
* Even though this number doesn't have any decimals, we still have 3 places saved for them, which means that we can **only use 2 places** for the **integer part**, and this number has 3 integer digits. So, the allowed number of integer digits is `max_digits` - `decimal_places` = 2.

!!! tip
Make sure you adjust the number of digits and decimal places for your own needs, in your own application. 馃
/// tip

Make sure you adjust the number of digits and decimal places for your own needs, in your own application. 馃

///

## Create models with Decimals

Expand Down Expand Up @@ -142,7 +151,10 @@ Total money: 3.300

</div>

!!! warning
Although Decimal types are supported and used in the Python side, not all databases support it. In particular, SQLite doesn't support decimals, so it will convert them to the same floating `NUMERIC` type it supports.
/// warning

Although Decimal types are supported and used in the Python side, not all databases support it. In particular, SQLite doesn't support decimals, so it will convert them to the same floating `NUMERIC` type it supports.

But decimals are supported by most of the other SQL databases. 馃帀

But decimals are supported by most of the other SQL databases. 馃帀
///
30 changes: 21 additions & 9 deletions docs/databases.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Intro to Databases

!!! info
Are you a seasoned developer and already know everything about databases? 馃
/// info

Then you can skip to the [Tutorial - User Guide: First Steps](tutorial/index.md){.internal-link target=_blank} right away.
Are you a seasoned developer and already know everything about databases? 馃

Then you can skip to the [Tutorial - User Guide: First Steps](tutorial/index.md){.internal-link target=_blank} right away.

///

If you don't know everything about databases, here's a quick overview.

Expand All @@ -17,8 +20,11 @@ So, what is a database?

A **database** is a system to store and manage data in a structured and very efficient way.

!!! tip
It's very common to abbreviate the word "database" as **"DB"**.
/// tip

It's very common to abbreviate the word "database" as **"DB"**.

///

As there's a lot of information about databases, and it can get very technical and academic, I'll give you a quick overview about some of the main concepts here.

Expand All @@ -28,8 +34,11 @@ I'll even tell you a bit about different types of databases, including the ones

When starting to program, it might **not be obvious** why having a database apart from the code for your program is a **good idea**. Let's start with that.

!!! tip
If that's obvious to you, just continue in the next section below. 馃憞
/// tip

If that's obvious to you, just continue in the next section below. 馃憞

///

In your code you already have **variables**, **dictionaries**, **lists**, etc. They all store **data** in some way already. Why would you need to have a separate database?

Expand Down Expand Up @@ -308,8 +317,11 @@ Next, it receives the data and puts it in Python objects that you can continue t

I'll tell you more about SQL, SQLModel, how to use them, and how they are related in the next sections.

!!! info "Technical Details"
SQLModel is built on top of SQLAlchemy. It is, in fact, just <a href="https://www.sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a> and <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> mixed together with some sugar on top.
/// info | Technical Details

SQLModel is built on top of SQLAlchemy. It is, in fact, just <a href="https://www.sqlalchemy.org/" class="external-link" target="_blank">SQLAlchemy</a> and <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a> mixed together with some sugar on top.

///

## NoSQL Databases

Expand Down
28 changes: 20 additions & 8 deletions docs/db-to-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ The difference in the final SQL statement is subtle, but it changes the meaning
SELECT * FROM hero WHERE id = "2; DROP TABLE hero;";
```

!!! tip
Notice the double quotes (`"`) making it a string instead of more raw SQL.
/// tip

Notice the double quotes (`"`) making it a string instead of more raw SQL.

///

The database will not find any record with that ID:

Expand All @@ -187,8 +190,11 @@ Then your code will continue to execute and calmly tell the user that it couldn'

But we never deleted the `hero` table. 馃帀

!!! info
Of course, there are also other ways to do SQL data sanitization without using a tool like **SQLModel**, but it's still a nice feature you get by default.
/// info

Of course, there are also other ways to do SQL data sanitization without using a tool like **SQLModel**, but it's still a nice feature you get by default.

///

### Editor Support

Expand Down Expand Up @@ -291,8 +297,11 @@ There are many ORMs available apart from **SQLModel**, you can read more about s

## SQL Table Names

!!! info "Technical Background"
This is a bit of boring background for SQL purists. Feel free to skip this section. 馃槈
/// info | Technical Background

This is a bit of boring background for SQL purists. Feel free to skip this section. 馃槈

///

When working with pure SQL, it's common to name the tables in plural. So, the table would be named `heroes` instead of `hero`, because it could contain multiple rows, each with one hero.

Expand All @@ -304,5 +313,8 @@ You will see **your own code** a lot more than the internal table names, so it's

So, to keep things consistent, I'll keep using the same table names that **SQLModel** would have generated.

!!! tip
You can also override the table name. You can read about it in the Advanced User Guide.
/// tip

You can also override the table name. You can read about it in the Advanced User Guide.

///
11 changes: 7 additions & 4 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ You won't need to keep guessing the types of different attributes in your models

<img class="shadow" src="/img/index/autocompletion01.png">

!!! info
Don't worry, adopting this in-development standard only affects/improves editor support.
/// info

It doesn't affect performance or correctness. And if the in-progress standard was deprecated your code won't be affected.
Don't worry, adopting this in-development standard only affects/improves editor support.

Meanwhile, you will get inline errors (like type checks) and autocompletion on places you wouldn't get with any other library. 馃帀
It doesn't affect performance or correctness. And if the in-progress standard was deprecated your code won't be affected.

Meanwhile, you will get inline errors (like type checks) and autocompletion on places you wouldn't get with any other library. 馃帀

///

## Short

Expand Down
20 changes: 13 additions & 7 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@ And if there's any other style or consistency need, I'll ask directly for that,

* Then **comment** saying that you did that, that's how I will know you really checked it.

!!! info
Unfortunately, I can't simply trust PRs that just have several approvals.
/// info

Several times it has happened that there are PRs with 3, 5 or more approvals, probably because the description is appealing, but when I check the PRs, they are actually broken, have a bug, or don't solve the problem they claim to solve. 馃槄
Unfortunately, I can't simply trust PRs that just have several approvals.

So, it's really important that you actually read and run the code, and let me know in the comments that you did. 馃
Several times it has happened that there are PRs with 3, 5 or more approvals, probably because the description is appealing, but when I check the PRs, they are actually broken, have a bug, or don't solve the problem they claim to solve. 馃槄

So, it's really important that you actually read and run the code, and let me know in the comments that you did. 馃

///

* If the PR can be simplified in a way, you can ask for that, but there's no need to be too picky, there might be a lot of subjective points of view (and I will have my own as well 馃檲), so it's better if you can focus on the fundamental things.

Expand Down Expand Up @@ -209,10 +212,13 @@ If you can help me with that, **you are helping me maintain SQLModel** and makin

Join the 馃懃 <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">FastAPI and Friends Discord chat server</a> 馃懃 and hang out with others in the community. There's a `#sqlmodel` channel.

!!! tip
For questions, ask them in <a href="https://github.com/tiangolo/sqlmodel/discussions/new?category=questions" class="external-link" target="_blank">GitHub Discussions</a>, there's a much better chance you will receive help there.
/// tip

For questions, ask them in <a href="https://github.com/tiangolo/sqlmodel/discussions/new?category=questions" class="external-link" target="_blank">GitHub Discussions</a>, there's a much better chance you will receive help there.

Use the chat only for other general conversations.

Use the chat only for other general conversations.
///

### Don't use the chat for questions

Expand Down
9 changes: 6 additions & 3 deletions docs/tutorial/automatic-id-none-refresh.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,13 @@ Hero 3: age=48 id=3 name='Rusty-Man' secret_name='Tommy Sharp'

Now let's review all this code once again.

!!! tip
Each one of the numbered bubbles shows what each line will print in the output.
/// tip

And as we created the **engine** with `echo=True`, we can see the SQL statements being executed at each step.
Each one of the numbered bubbles shows what each line will print in the output.

And as we created the **engine** with `echo=True`, we can see the SQL statements being executed at each step.

///

```{ .python .annotate }
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial002.py!}
Expand Down
9 changes: 6 additions & 3 deletions docs/tutorial/code-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ Let's say that for some reason you hate the idea of having all the database mode

You can also do it. 馃槑 There's a couple of things to keep in mind. 馃

!!! warning
This is a bit more advanced.
/// warning

If the solution above already worked for you, that might be enough for you, and you can continue in the next chapter. 馃
This is a bit more advanced.

If the solution above already worked for you, that might be enough for you, and you can continue in the next chapter. 馃

///

Let's assume that now the file structure is:

Expand Down
7 changes: 5 additions & 2 deletions docs/tutorial/connect/create-connected-rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ Each row in the table `hero` will point to a row in the table `team`:

<img alt="table relationships" src="/img/tutorial/relationships/select/relationships2.svg">

!!! info
We will later update **Spider-Boy** to add him to the **Preventers** team too, but not yet.
/// info

We will later update **Spider-Boy** to add him to the **Preventers** team too, but not yet.

///

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

Expand Down
14 changes: 10 additions & 4 deletions docs/tutorial/connect/create-connected-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ This is the name of the **table** in the database, so it is `"team"`, not the na

If you had a custom table name, you would use that custom table name.

!!! info
You can learn about setting a custom table name for a model in the Advanced User Guide.
/// info

You can learn about setting a custom table name for a model in the Advanced User Guide.

///

### Create the Tables

Expand Down Expand Up @@ -167,8 +170,11 @@ And as before, we'll call this function from another function `main()`, and we'l

## Run the Code

!!! tip
Before running the code, make sure you delete the file `database.db` to make sure you start from scratch.
/// tip

Before running the code, make sure you delete the file `database.db` to make sure you start from scratch.

///

If we run the code we have up to now, it will go and create the database file `database.db` and the tables in it we just defined, `team` and `hero`:

Expand Down
9 changes: 6 additions & 3 deletions docs/tutorial/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ But the main advantage and feature of SQL databases is being able to handle rela

Let's see how to use **SQLModel** to manage connected data in the next chapters. 馃

!!! tip
We will extend this further in the next group of chapters making it even more convenient to work with in Python code, using **relationship attributes**.
/// tip

But you should start in this group of chapters first. 馃
We will extend this further in the next group of chapters making it even more convenient to work with in Python code, using **relationship attributes**.

But you should start in this group of chapters first. 馃

///
45 changes: 30 additions & 15 deletions docs/tutorial/connect/read-connected-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ FROM hero, team
WHERE hero.team_id = team.id
```

!!! info
Because we have two columns called `name`, one for `hero` and one for `team`, we can specify them with the prefix of the table name and the dot to make it explicit what we refer to.
/// info

Because we have two columns called `name`, one for `hero` and one for `team`, we can specify them with the prefix of the table name and the dot to make it explicit what we refer to.

///

Notice that now in the `WHERE` part we are not comparing one column with a literal value (like `hero.name = "Deadpond"`), but we are comparing two columns.

Expand Down Expand Up @@ -99,14 +102,17 @@ You can go ahead and try it in **DB Browser for SQLite**:

<img class="shadow" src="/img/tutorial/relationships/select/image01.png">

!!! note
Wait, what about Spider-Boy? 馃槺
/// note

Wait, what about Spider-Boy? 馃槺

He doesn't have a team, so his `team_id` is `NULL` in the database. And this SQL is comparing that `NULL` from the `team_id` with all the `id` fields in the rows in the `team` table.
He doesn't have a team, so his `team_id` is `NULL` in the database. And this SQL is comparing that `NULL` from the `team_id` with all the `id` fields in the rows in the `team` table.

As there's no team with an ID of `NULL`, it doesn't find a match.
As there's no team with an ID of `NULL`, it doesn't find a match.

But we'll see how to fix that later with a `LEFT JOIN`.
But we'll see how to fix that later with a `LEFT JOIN`.

///

## Select Related Data with **SQLModel**

Expand Down Expand Up @@ -164,10 +170,13 @@ For each iteration in the `for` loop we get a a tuple with an instance of the cl

And in this `for` loop we assign them to the variable `hero` and the variable `team`.

!!! info
There was a lot of research, design, and work behind **SQLModel** to make this provide the best possible developer experience.
/// info

There was a lot of research, design, and work behind **SQLModel** to make this provide the best possible developer experience.

And you should get autocompletion and inline errors in your editor for both `hero` and `team`. 馃帀
And you should get autocompletion and inline errors in your editor for both `hero` and `team`. 馃帀

///

## Add It to Main

Expand Down Expand Up @@ -281,10 +290,13 @@ Also in **DB Browser for SQLite**:

<img class="shadow" src="/img/tutorial/relationships/select/image02.png">

!!! tip
Why bother with all this if the result is the same?
/// tip

Why bother with all this if the result is the same?

This `JOIN` will be useful in a bit to be able to also get Spider-Boy, even if he doesn't have a team.

This `JOIN` will be useful in a bit to be able to also get Spider-Boy, even if he doesn't have a team.
///

## Join Tables in **SQLModel**

Expand Down Expand Up @@ -420,8 +432,11 @@ And that would return the following result, including **Spider-Boy** 馃帀:
</tr>
</table>

!!! tip
The only difference between this query and the previous is that extra `LEFT OUTER`.
/// tip

The only difference between this query and the previous is that extra `LEFT OUTER`.

///

And here's another of the SQL variations, you could write `LEFT OUTER JOIN` or just `LEFT JOIN`, it means the same.

Expand Down
Loading

0 comments on commit a95bd38

Please sign in to comment.