🔧 Update config with new pymdown extensions (#712)
* 🔧 Update config with new pymdown extensions * 📝 Update admonition blocks syntax * 📝 Update syntax for tabs with new pymdown extensions
This commit is contained in:
committed by
GitHub
parent
71baff6015
commit
a95bd3873d
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`:
|
||||
|
||||
|
||||
@@ -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. 🤓
|
||||
|
||||
///
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
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.
|
||||
Wait, what about Spider-Boy? 😱
|
||||
|
||||
As there's no team with an ID of `NULL`, it doesn't find a match.
|
||||
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.
|
||||
|
||||
But we'll see how to fix that later with a `LEFT JOIN`.
|
||||
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`.
|
||||
|
||||
///
|
||||
|
||||
## Select Related Data with **SQLModel**
|
||||
|
||||
@@ -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
|
||||
|
||||
And you should get autocompletion and inline errors in your editor for both `hero` and `team`. 🎉
|
||||
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`. 🎉
|
||||
|
||||
///
|
||||
|
||||
## Add It to Main
|
||||
|
||||
@@ -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
|
||||
|
||||
This `JOIN` will be useful in a bit to be able to also get Spider-Boy, even if he doesn't have a team.
|
||||
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.
|
||||
|
||||
///
|
||||
|
||||
## Join Tables in **SQLModel**
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user