Compare commits
118 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9522b3913 | ||
|
|
e7848923ec | ||
|
|
eb12bbc640 | ||
|
|
6216409f96 | ||
|
|
6fe256ec2c | ||
|
|
92f52a3fc5 | ||
|
|
2bc915ed04 | ||
|
|
42b0e6eace | ||
|
|
1ca288028c | ||
|
|
a2cda8377f | ||
|
|
8ac82e7101 | ||
|
|
5429e9b6aa | ||
|
|
c743647a52 | ||
|
|
475578757f | ||
|
|
5e0ac5b56c | ||
|
|
d380736043 | ||
|
|
71d6fcc31b | ||
|
|
680602b7eb | ||
|
|
9c68ce12ec | ||
|
|
eef0b7770b | ||
|
|
2fab4817fe | ||
|
|
5ea9340def | ||
|
|
db3ad598c5 | ||
|
|
9830ee0d89 | ||
|
|
2407ecd2bf | ||
|
|
ee576ab279 | ||
|
|
ae1b8b5585 | ||
|
|
e48fb2874b | ||
|
|
7d3bf70a76 | ||
|
|
91d0785b1c | ||
|
|
5dfef7ede7 | ||
|
|
0aaf39d539 | ||
|
|
c0a6b2dd8b | ||
|
|
87a02b4c46 | ||
|
|
14fc1f510e | ||
|
|
ad0766fe3e | ||
|
|
1e69c00538 | ||
|
|
bf15380733 | ||
|
|
a993c2141d | ||
|
|
deed65095f | ||
|
|
61294af824 | ||
|
|
106fb1fe9b | ||
|
|
6b433a0de4 | ||
|
|
4de5a41720 | ||
|
|
dc5876c727 | ||
|
|
5f6b5bfd7f | ||
|
|
e5fdc371f6 | ||
|
|
452f18d8bc | ||
|
|
04b8b3eedf | ||
|
|
426da7c443 | ||
|
|
a5116a372c | ||
|
|
015f7acbc5 | ||
|
|
34e125357f | ||
|
|
c0efc7b370 | ||
|
|
48ada0cd5d | ||
|
|
aa5803fbbb | ||
|
|
8bee55e23b | ||
|
|
6f1ffccd4f | ||
|
|
13544c0f44 | ||
|
|
184c8eb5a9 | ||
|
|
acc27dabc9 | ||
|
|
d032c3cfea | ||
|
|
006cf488e8 | ||
|
|
63dd44dc86 | ||
|
|
f602794f07 | ||
|
|
f3063a8e16 | ||
|
|
f67a13a5fb | ||
|
|
5dff4d15e8 | ||
|
|
943892ddb2 | ||
|
|
31beaf1017 | ||
|
|
9664c8814c | ||
|
|
7bb99f2bd5 | ||
|
|
4a08ee89ee | ||
|
|
0197c6e211 | ||
|
|
6da8dcfc8e | ||
|
|
dc4dc42ec5 | ||
|
|
db29f53295 | ||
|
|
bc6dc0bafc | ||
|
|
36b0c1ba08 | ||
|
|
dc0ecbb2c2 | ||
|
|
aca18da21e | ||
|
|
f7d1bbe5b6 | ||
|
|
296a0935d1 | ||
|
|
0049436cd4 | ||
|
|
f4500c6ba4 | ||
|
|
c830c71e28 | ||
|
|
ea18162391 | ||
|
|
4dd7b890d4 | ||
|
|
4d20051793 | ||
|
|
88683f6e2c | ||
|
|
d6229b3937 | ||
|
|
e523e1e4c3 | ||
|
|
6d969c5845 | ||
|
|
b94d393924 | ||
|
|
e009ecb704 | ||
|
|
03e861d048 | ||
|
|
8e97c93de0 | ||
|
|
7176d89e48 | ||
|
|
e6f8c00bbe | ||
|
|
c873aa3930 | ||
|
|
800a5f232f | ||
|
|
8d1b6f079a | ||
|
|
7fcd4fd7c5 | ||
|
|
9203df6af1 | ||
|
|
d6d77a9ee4 | ||
|
|
155c6178cd | ||
|
|
3d7b74746c | ||
|
|
410d7af6b6 | ||
|
|
1b99c3148f | ||
|
|
6cf94a9797 | ||
|
|
a159f31945 | ||
|
|
dc3acda4ed | ||
|
|
ead1bdc532 | ||
|
|
2013c69c4d | ||
|
|
6615b111d9 | ||
|
|
50e62cdcd9 | ||
|
|
64d7f53357 | ||
|
|
32b5b39f2d |
6
.github/dependabot.yml
vendored
@@ -1,5 +1,11 @@
|
||||
version: 2
|
||||
updates:
|
||||
# GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
# Python
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/"
|
||||
schedule:
|
||||
|
||||
2
.github/workflows/build-docs.yml
vendored
@@ -1,6 +1,8 @@
|
||||
name: Build Docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
workflow_dispatch:
|
||||
|
||||
8
.github/workflows/test.yml
vendored
@@ -2,6 +2,8 @@ name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
workflow_dispatch:
|
||||
@@ -16,7 +18,7 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.6, 3.7, 3.8, 3.9]
|
||||
python-version: ["3.6.15", "3.7", "3.8", "3.9", "3.10"]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
@@ -52,9 +54,9 @@ jobs:
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: python -m poetry install
|
||||
- name: Lint
|
||||
if: ${{ matrix.python-version != '3.6' }}
|
||||
if: ${{ matrix.python-version != '3.6.15' }}
|
||||
run: python -m poetry run bash scripts/lint.sh
|
||||
- name: Test
|
||||
run: python -m poetry run bash scripts/test.sh
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v1
|
||||
uses: codecov/codecov-action@v2
|
||||
|
||||
@@ -212,4 +212,4 @@ And at the same time, ✨ it is also a **Pydantic** model ✨. You can use inher
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the terms of the MIT license.
|
||||
This project is licensed under the terms of the [MIT license](https://github.com/tiangolo/sqlmodel/blob/main/LICENSE).
|
||||
|
||||
@@ -42,7 +42,7 @@ $ poetry shell
|
||||
|
||||
</div>
|
||||
|
||||
That will set up the environment variables needed dand will start a new shell with them.
|
||||
That will set up the environment variables needed and start a new shell with them.
|
||||
|
||||
#### Using your local SQLModel
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ Some examples of databases that work like this could be **PostgreSQL**, **MySQL*
|
||||
|
||||
### Distributed servers
|
||||
|
||||
In some cases, the database could even be a group server applications running on different machines, working together and communicating between them to be more efficient and handle more data.
|
||||
In some cases, the database could even be a group of server applications running on different machines, working together and communicating between them to be more efficient and handle more data.
|
||||
|
||||
In this case, your code would talk to one or more of these server applications running on different machines.
|
||||
|
||||
@@ -250,7 +250,7 @@ As these **primary key** IDs can uniquely identify each row on the table for tea
|
||||
|
||||
<img alt="table relationships" src="/img/databases/relationships.svg">
|
||||
|
||||
So, in the table for heroes, we use the `team_id` column to define a relationship to the *foreign* table for teams. Each value in the `team_id` column on the table with heroes will be the same value as the `id` column of one row in the table wiwth teams.
|
||||
So, in the table for heroes, we use the `team_id` column to define a relationship to the *foreign* table for teams. Each value in the `team_id` column on the table with heroes will be the same value as the `id` column of one row in the table with teams.
|
||||
|
||||
In the table for heroes we have a **primary key** that is the `id`. But we also have another column `team_id` that refers to a **key** in a **foreign** table. There's a technical term for that too, the `team_id` is a "**foreign key**".
|
||||
|
||||
@@ -274,7 +274,7 @@ The language is called **SQL**, the name comes from for **Structured Query Langu
|
||||
|
||||
Nevertheless, the language is not only used to *query* for data. It is also used to create records/rows, to update them, to delete them. And to manipulate the database, create tables, etc.
|
||||
|
||||
This language is supported by all these databases that handle multiple tables, that's why they are called **SQL Databases**. Although, each database has small variations in the SQL language they support.
|
||||
This language is supported by all these databases that handle multiple tables, that's why they are called **SQL Databases**. Although, each database has small variations in the SQL language they support (*dialect*).
|
||||
|
||||
Let's imagine that the table holding the heroes is called the `hero` table. An example of a SQL query to get all the data from it could look like:
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ If the user provides this ID:
|
||||
2
|
||||
```
|
||||
|
||||
...the would be this table (with a single row):
|
||||
...the result would be this table (with a single row):
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
||||
@@ -12,7 +12,7 @@ And there are several ways to get help too.
|
||||
|
||||
## Subscribe to the FastAPI and Friends newsletter
|
||||
|
||||
You can subscribe to the (infrequent) [**FastAPI and friends** newsletter](/newsletter/){.internal-link target=_blank} to stay updated about:
|
||||
You can subscribe to the (infrequent) <a href="https://fastapi.tiangolo.com/newsletter" class="external-link" target="_blank">**FastAPI and friends** newsletter</a> to stay updated about:
|
||||
|
||||
* News about FastAPI and friends, including SQLModel 🚀
|
||||
* Guides 📝
|
||||
|
||||
97
docs/img/tutorial/indexes/dictionary001.drawio
Normal file
@@ -0,0 +1,97 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1463" dy="1403" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" vertex="1" parent="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="68" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" vertex="1" parent="1">
|
||||
<mxGeometry x="580" y="1030" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
57
docs/img/tutorial/indexes/dictionary001.svg
Normal file
|
After Width: | Height: | Size: 30 KiB |
97
docs/img/tutorial/indexes/dictionary002.drawio
Normal file
@@ -0,0 +1,97 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1707" dy="1637" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeWidth=3;strokeColor=#b85450;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="68" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="1030" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary002.svg
Normal file
|
After Width: | Height: | Size: 28 KiB |
97
docs/img/tutorial/indexes/dictionary003.drawio
Normal file
@@ -0,0 +1,97 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1205" dy="1155" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeWidth=3;strokeColor=#b85450;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" vertex="1" parent="1">
|
||||
<mxGeometry x="580" y="1030" width="560" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary003.svg
Normal file
|
After Width: | Height: | Size: 27 KiB |
100
docs/img/tutorial/indexes/dictionary004.drawio
Normal file
@@ -0,0 +1,100 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1463" dy="1403" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="68" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="1030" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="1030" width="560" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary004.svg
Normal file
|
After Width: | Height: | Size: 28 KiB |
97
docs/img/tutorial/indexes/dictionary005.drawio
Normal file
@@ -0,0 +1,97 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1024" dy="982" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeWidth=3;strokeColor=#b85450;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="1030" width="840" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary005.svg
Normal file
|
After Width: | Height: | Size: 27 KiB |
100
docs/img/tutorial/indexes/dictionary006.drawio
Normal file
@@ -0,0 +1,100 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1024" dy="982" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="1030" width="840" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="70" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" vertex="1" parent="1">
|
||||
<mxGeometry x="180" y="1030" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary006.svg
Normal file
|
After Width: | Height: | Size: 28 KiB |
100
docs/img/tutorial/indexes/dictionary007.drawio
Normal file
@@ -0,0 +1,100 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1024" dy="982" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeWidth=3;strokeColor=#b85450;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="1030" width="840" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="71" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" vertex="1" parent="1">
|
||||
<mxGeometry x="100" y="1030" width="120" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary007.svg
Normal file
|
After Width: | Height: | Size: 27 KiB |
103
docs/img/tutorial/indexes/dictionary008.drawio
Normal file
@@ -0,0 +1,103 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1024" dy="982" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="950" width="1040" height="160" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="<font style="font-size: 24px">A</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="40" value="<font style="font-size: 24px">B</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="140" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="<font style="font-size: 24px">C</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="180" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeWidth=3;strokeColor=#82b366;" parent="1" vertex="1">
|
||||
<mxGeometry x="220" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="<font style="font-size: 24px">E</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="<font style="font-size: 24px">F</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="<font style="font-size: 24px">G</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="340" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="<font style="font-size: 24px">H</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="380" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="<font style="font-size: 24px">I</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="420" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="48" value="<font style="font-size: 24px">J</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="460" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="<font style="font-size: 24px">K</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="500" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="<font style="font-size: 24px">L</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="540" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="<font style="font-size: 24px">M</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="580" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="<font style="font-size: 24px">N</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="620" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="<font style="font-size: 24px">O</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="660" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="<font style="font-size: 24px">P</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="700" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="<font style="font-size: 24px">Q</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="740" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="56" value="<font style="font-size: 24px">R</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="780" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="57" value="<font style="font-size: 24px">S</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="820" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="<font style="font-size: 24px">T</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="860" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="<font style="font-size: 24px">U</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="900" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="<font style="font-size: 24px">V</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="940" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="<font style="font-size: 24px">W</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="980" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="<font style="font-size: 24px">X</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1020" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="<font style="font-size: 24px">Y</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1060" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="<font style="font-size: 24px">Z</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="1100" y="840" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Dictionary</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="565" y="960" width="110" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="69" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="1030" width="880" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="71" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeWidth=3;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
|
||||
<mxGeometry x="100" y="1030" width="120" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="72" value="<font style="font-size: 24px">D</font>" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeWidth=3;strokeColor=#82b366;" vertex="1" parent="1">
|
||||
<mxGeometry x="220" y="1030" width="40" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/dictionary008.svg
Normal file
|
After Width: | Height: | Size: 28 KiB |
92
docs/img/tutorial/indexes/techbook001.drawio
Normal file
@@ -0,0 +1,92 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="objTApYHlBqCKos3M7rL" name="Page-1">
|
||||
<mxGraphModel dx="1707" dy="1637" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1920" pageHeight="1200" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="4" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="80" y="420" width="1020" height="490" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="66" value="<font style="font-size: 24px">Technical Book</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
|
||||
<mxGeometry x="492.5" y="440" width="195" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="77" value="<font style="font-size: 24px">Chapter 1</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="100" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="83" value="<font style="font-size: 24px">Chapter 2</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="240" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="84" value="<font style="font-size: 24px">Chapter 3</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="380" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="85" value="<font style="font-size: 24px">Chapter 4</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="520" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="86" value="<font style="font-size: 24px">Chapter 5</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="660" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="87" value="<font style="font-size: 24px">Chapter 6</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="800" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="88" value="<font style="font-size: 24px">Chapter 7</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
|
||||
<mxGeometry x="940" y="490" width="140" height="90" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="74" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeWidth=3;strokeColor=#d6b656;" vertex="1" parent="1">
|
||||
<mxGeometry x="100" y="580" width="980" height="310" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="75" value="<font style="font-size: 24px">Book Index</font>" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
|
||||
<mxGeometry x="498.125" y="840" width="183.75" height="30" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="89" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="42" target="77">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="92" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="42" target="86">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="<font style="font-size: 24px">Database</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" parent="1" vertex="1">
|
||||
<mxGeometry x="119.99615384615385" y="690" width="150.76923076923077" height="70" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="94" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="93" target="83">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="330" y="820"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="95" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="93" target="85">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="590" y="800"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="93" value="<font style="font-size: 24px">Python</font>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="909.9961538461539" y="780" width="150.76923076923077" height="70" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="97" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="96" target="87">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="98" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="96" target="86">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="770" y="725"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="96" value="<span style="font-size: 24px">Files</span>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="909.9961538461539" y="690" width="150.76923076923077" height="70" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="100" style="edgeStyle=orthogonalEdgeStyle;html=1;strokeWidth=3;" edge="1" parent="1" source="99" target="84">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="450" y="800"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="99" value="<span style="font-size: 24px">Editors</span>" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=3;" vertex="1" parent="1">
|
||||
<mxGeometry x="119.9961538461539" y="780" width="150.76923076923077" height="70" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
1
docs/img/tutorial/indexes/techbook001.svg
Normal file
|
After Width: | Height: | Size: 17 KiB |
@@ -212,4 +212,4 @@ And at the same time, ✨ it is also a **Pydantic** model ✨. You can use inher
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the terms of the MIT license.
|
||||
This project is licensed under the terms of the [MIT license](https://github.com/tiangolo/sqlmodel/blob/main/LICENSE).
|
||||
|
||||
31
docs/overrides/main.html
Normal file
@@ -0,0 +1,31 @@
|
||||
{% extends "base.html" %}
|
||||
{%- block scripts %}
|
||||
{{ super() }}
|
||||
<script src="https://cdn.jsdelivr.net/npm/qabot@0.4"></script>
|
||||
<script>
|
||||
// This prevents the global search from interfering with qa-bot's internal text input.
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('qa-bot').forEach((x) => {
|
||||
x.addEventListener('keydown', (event) => {
|
||||
event.stopPropagation();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<qa-bot
|
||||
server="https://tiangolo-sqlmodel.docsqa.jina.ai"
|
||||
theme="infer"
|
||||
title="SQLModel Bot"
|
||||
description="SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness."
|
||||
style="font-size: 0.8rem"
|
||||
>
|
||||
<template>
|
||||
<dl>
|
||||
<dt>You can ask questions about SQLModel. Try:</dt>
|
||||
<dd>Which Python version is supported?</dd>
|
||||
<dd>How SQLModel interacts with the database?</dd>
|
||||
<dd>How can I link tables?</dd>
|
||||
</dl>
|
||||
</template>
|
||||
</qa-bot>
|
||||
{%- endblock %}
|
||||
@@ -3,6 +3,141 @@
|
||||
## Latest Changes
|
||||
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Features
|
||||
|
||||
* ✨ Allow setting `unique` in `Field()` for a column. PR [#83](https://github.com/tiangolo/sqlmodel/pull/83) by [@raphaelgibson](https://github.com/raphaelgibson).
|
||||
* ✨ Update GUID handling to use stdlib `UUID.hex` instead of an `int`. PR [#26](https://github.com/tiangolo/sqlmodel/pull/26) by [@andrewbolster](https://github.com/andrewbolster).
|
||||
* ✨ Raise an exception when using a Pydantic field type with no matching SQLAlchemy type. PR [#18](https://github.com/tiangolo/sqlmodel/pull/18) by [@elben10](https://github.com/elben10).
|
||||
* ⬆ Upgrade constrain for SQLAlchemy = ">=1.4.17,<=1.4.41". PR [#371](https://github.com/tiangolo/sqlmodel/pull/371) by [@RobertRosca](https://github.com/RobertRosca).
|
||||
* ✨ Add new `Session.get()` parameter `execution_options`. PR [#302](https://github.com/tiangolo/sqlmodel/pull/302) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
### Fixes
|
||||
|
||||
* 🐛 Fix type annotations for `Model.parse_obj()`, and `Model.validate()`. PR [#321](https://github.com/tiangolo/sqlmodel/pull/321) by [@phi-friday](https://github.com/phi-friday).
|
||||
* 🐛 Fix `Select` and `SelectOfScalar` to inherit cache to avoid warning: `SAWarning: Class SelectOfScalar will not make use of SQL compilation caching`. PR [#234](https://github.com/tiangolo/sqlmodel/pull/234) by [@rabinadk1](https://github.com/rabinadk1).
|
||||
* 🐛 Fix handling validators for non-default values. PR [#253](https://github.com/tiangolo/sqlmodel/pull/253) by [@byrman](https://github.com/byrman).
|
||||
* 🐛 Fix fields marked as "set" in models. PR [#117](https://github.com/tiangolo/sqlmodel/pull/117) by [@statt8900](https://github.com/statt8900).
|
||||
* 🐛 Fix Enum handling in SQLAlchemy. PR [#165](https://github.com/tiangolo/sqlmodel/pull/165) by [@chriswhite199](https://github.com/chriswhite199).
|
||||
* 🐛 Fix setting nullable property of Fields that don't accept `None`. PR [#79](https://github.com/tiangolo/sqlmodel/pull/79) by [@van51](https://github.com/van51).
|
||||
* 🐛 Fix SQLAlchemy version 1.4.36 breaks SQLModel relationships (#315). PR [#322](https://github.com/tiangolo/sqlmodel/pull/322) by [@byrman](https://github.com/byrman).
|
||||
|
||||
### Docs
|
||||
|
||||
* 📝 Update docs for models for updating, `id` should not be updatable. PR [#335](https://github.com/tiangolo/sqlmodel/pull/335) by [@kurtportelli](https://github.com/kurtportelli).
|
||||
* ✏ Fix broken variable/typo in docs for Read Relationships, `hero_spider_boy.id` => `hero_spider_boy.team_id`. PR [#106](https://github.com/tiangolo/sqlmodel/pull/106) by [@yoannmos](https://github.com/yoannmos).
|
||||
* 🎨 Remove unwanted highlight in the docs. PR [#233](https://github.com/tiangolo/sqlmodel/pull/233) by [@jalvaradosegura](https://github.com/jalvaradosegura).
|
||||
* ✏ Fix typos in `docs/databases.md` and `docs/tutorial/index.md`. PR [#35](https://github.com/tiangolo/sqlmodel/pull/35) by [@prrao87](https://github.com/prrao87).
|
||||
* ✏ Fix typo in `docs/tutorial/relationship-attributes/define-relationships-attributes.md`. PR [#239](https://github.com/tiangolo/sqlmodel/pull/239) by [@jalvaradosegura](https://github.com/jalvaradosegura).
|
||||
* ✏ Fix typo in `docs/tutorial/fastapi/simple-hero-api.md`. PR [#80](https://github.com/tiangolo/sqlmodel/pull/80) by [@joemudryk](https://github.com/joemudryk).
|
||||
* ✏ Fix typos in multiple files in the docs. PR [#400](https://github.com/tiangolo/sqlmodel/pull/400) by [@VictorGambarini](https://github.com/VictorGambarini).
|
||||
* ✏ Fix typo in `docs/tutorial/code-structure.md`. PR [#344](https://github.com/tiangolo/sqlmodel/pull/344) by [@marciomazza](https://github.com/marciomazza).
|
||||
* ✏ Fix typo in `docs/db-to-code.md`. PR [#155](https://github.com/tiangolo/sqlmodel/pull/155) by [@gr8jam](https://github.com/gr8jam).
|
||||
* ✏ Fix typo in `docs/contributing.md`. PR [#323](https://github.com/tiangolo/sqlmodel/pull/323) by [@Fardad13](https://github.com/Fardad13).
|
||||
* ✏ Fix typo in `docs/tutorial/fastapi/tests.md`. PR [#265](https://github.com/tiangolo/sqlmodel/pull/265) by [@johnhoman](https://github.com/johnhoman).
|
||||
* ✏ Fix typo in `docs/tutorial/where.md`. PR [#286](https://github.com/tiangolo/sqlmodel/pull/286) by [@jalvaradosegura](https://github.com/jalvaradosegura).
|
||||
* ✏ Fix typos in `docs/tutorial/fastapi/update.md`. PR [#268](https://github.com/tiangolo/sqlmodel/pull/268) by [@cirrusj](https://github.com/cirrusj).
|
||||
* ✏ Fix typo in `docs/tutorial/fastapi/simple-hero-api.md`. PR [#247](https://github.com/tiangolo/sqlmodel/pull/247) by [@hao-wang](https://github.com/hao-wang).
|
||||
* ✏ Fix typos in `docs/tutorial/automatic-id-none-refresh.md`, `docs/tutorial/fastapi/update.md`, `docs/tutorial/select.md`. PR [#185](https://github.com/tiangolo/sqlmodel/pull/185) by [@rootux](https://github.com/rootux).
|
||||
* ✏ Fix typo in `docs/databases.md`. PR [#177](https://github.com/tiangolo/sqlmodel/pull/177) by [@seandlg](https://github.com/seandlg).
|
||||
* ✏ Fix typos in `docs/tutorial/fastapi/update.md`. PR [#162](https://github.com/tiangolo/sqlmodel/pull/162) by [@wmcgee3](https://github.com/wmcgee3).
|
||||
* ✏ Fix typos in `docs/tutorial/code-structure.md`, `docs/tutorial/fastapi/multiple-models.md`, `docs/tutorial/fastapi/simple-hero-api.md`, `docs/tutorial/many-to-many/index.md`. PR [#116](https://github.com/tiangolo/sqlmodel/pull/116) by [@moonso](https://github.com/moonso).
|
||||
* ✏ Fix typo in `docs/tutorial/fastapi/teams.md`. PR [#154](https://github.com/tiangolo/sqlmodel/pull/154) by [@chrisgoddard](https://github.com/chrisgoddard).
|
||||
* ✏ Fix typo variable in example about relationships and `back_populates`, always use `hero` instead of `owner`. PR [#120](https://github.com/tiangolo/sqlmodel/pull/120) by [@onionj](https://github.com/onionj).
|
||||
* ✏ Fix typo in `docs/tutorial/fastapi/tests.md`. PR [#113](https://github.com/tiangolo/sqlmodel/pull/113) by [@feanil](https://github.com/feanil).
|
||||
* ✏ Fix typo in `docs/tutorial/where.md`. PR [#72](https://github.com/tiangolo/sqlmodel/pull/72) by [@ZettZet](https://github.com/ZettZet).
|
||||
* ✏ Fix typo in `docs/tutorial/code-structure.md`. PR [#91](https://github.com/tiangolo/sqlmodel/pull/91) by [@dhiraj](https://github.com/dhiraj).
|
||||
* ✏ Fix broken link to newsletter sign-up in `docs/help.md`. PR [#84](https://github.com/tiangolo/sqlmodel/pull/84) by [@mborus](https://github.com/mborus).
|
||||
* ✏ Fix typos in `docs/tutorial/many-to-many/create-models-with-link.md`. PR [#45](https://github.com/tiangolo/sqlmodel/pull/45) by [@xginn8](https://github.com/xginn8).
|
||||
* ✏ Fix typo in `docs/tutorial/index.md`. PR [#398](https://github.com/tiangolo/sqlmodel/pull/398) by [@ryangrose](https://github.com/ryangrose).
|
||||
|
||||
### Internal
|
||||
|
||||
* ♻ Refactor internal statements to simplify code. PR [#53](https://github.com/tiangolo/sqlmodel/pull/53) by [@yezz123](https://github.com/yezz123).
|
||||
* ♻ Refactor internal imports to reduce redundancy. PR [#272](https://github.com/tiangolo/sqlmodel/pull/272) by [@aminalaee](https://github.com/aminalaee).
|
||||
* ⬆ Update development requirement for FastAPI from `^0.68.0` to `^0.68.1`. PR [#48](https://github.com/tiangolo/sqlmodel/pull/48) by [@alucarddelta](https://github.com/alucarddelta).
|
||||
* ⏪ Revert upgrade Poetry, to make a release that supports Python 3.6 first. PR [#417](https://github.com/tiangolo/sqlmodel/pull/417) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 👷 Add dependabot for GitHub Actions. PR [#410](https://github.com/tiangolo/sqlmodel/pull/410) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ⬆️ Upgrade Poetry to version `==1.2.0b1`. PR [#303](https://github.com/tiangolo/sqlmodel/pull/303) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 👷 Add CI for Python 3.10. PR [#305](https://github.com/tiangolo/sqlmodel/pull/305) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 📝 Add Jina's QA Bot to the docs to help people that want to ask quick questions. PR [#263](https://github.com/tiangolo/sqlmodel/pull/263) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 👷 Upgrade Codecov GitHub Action. PR [#304](https://github.com/tiangolo/sqlmodel/pull/304) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 💚 Only run CI on push when on master, to avoid duplicate runs on PRs. PR [#244](https://github.com/tiangolo/sqlmodel/pull/244) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 🔧 Upgrade MkDocs Material and update configs. PR [#217](https://github.com/tiangolo/sqlmodel/pull/217) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ⬆ Upgrade mypy, fix type annotations. PR [#218](https://github.com/tiangolo/sqlmodel/pull/218) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
**SQLModel** no longer creates indexes by default for every column, indexes are now opt-in. You can read more about it in PR [#205](https://github.com/tiangolo/sqlmodel/pull/205).
|
||||
|
||||
Before this change, if you had a model like this:
|
||||
|
||||
```Python
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
```
|
||||
|
||||
...when creating the tables, SQLModel version `0.0.5` and below, would also create an index for `name`, one for `secret_name`, and one for `age` (`id` is the primary key, so it doesn't need an additional index).
|
||||
|
||||
If you depended on having an index for each one of those columns, now you can (and would have to) define them explicitly:
|
||||
|
||||
```Python
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str = Field(index=True)
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
```
|
||||
|
||||
There's a high chance you don't need indexes for all the columns. For example, you might only need indexes for `name` and `age`, but not for `secret_name`. In that case, you could define the model as:
|
||||
|
||||
```Python
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
```
|
||||
|
||||
If you already created your database tables with SQLModel using versions `0.0.5` or below, it would have also created those indexes in the database. In that case, you might want to manually drop (remove) some of those indexes, if they are unnecessary, to avoid the extra cost in performance and space.
|
||||
|
||||
Depending on the database you are using, there will be a different way to find the available indexes.
|
||||
|
||||
For example, let's say you no longer need the index for `secret_name`. You could check the current indexes in the database and find the one for `secret_name`, it could be named `ix_hero_secret_name`. Then you can remove it with SQL:
|
||||
|
||||
```SQL
|
||||
DROP INDEX ix_hero_secret_name
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```SQL
|
||||
DROP INDEX ix_hero_secret_name ON hero;
|
||||
```
|
||||
|
||||
Here's the new, extensive documentation explaining indexes and how to use them: [Indexes - Optimize Queries](https://sqlmodel.tiangolo.com/tutorial/indexes/).
|
||||
|
||||
### Docs
|
||||
|
||||
* ✨ Document indexes and make them opt-in. Here's the new documentation: [Indexes - Optimize Queries](https://sqlmodel.tiangolo.com/tutorial/indexes/). This is the same change described above in **Breaking Changes**. PR [#205](https://github.com/tiangolo/sqlmodel/pull/205) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ✏ Fix typo in FastAPI tutorial. PR [#192](https://github.com/tiangolo/sqlmodel/pull/192) by [@yaquelinehoyos](https://github.com/yaquelinehoyos).
|
||||
* 📝 Add links to the license file. PR [#29](https://github.com/tiangolo/sqlmodel/pull/29) by [@sobolevn](https://github.com/sobolevn).
|
||||
* ✏ Fix typos in docs titles. PR [#28](https://github.com/tiangolo/sqlmodel/pull/28) by [@Batalex](https://github.com/Batalex).
|
||||
* ✏ Fix multiple typos and some rewording. PR [#22](https://github.com/tiangolo/sqlmodel/pull/22) by [@egrim](https://github.com/egrim).
|
||||
* ✏ Fix typo in `docs/tutorial/automatic-id-none-refresh.md`. PR [#14](https://github.com/tiangolo/sqlmodel/pull/14) by [@leynier](https://github.com/leynier).
|
||||
* ✏ Fix typos in `docs/tutorial/index.md` and `docs/databases.md`. PR [#5](https://github.com/tiangolo/sqlmodel/pull/5) by [@sebastianmarines](https://github.com/sebastianmarines).
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Features
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Automatic IDs, None Defaults, and Refreshing Data
|
||||
|
||||
In the previous chapter we saw how to add rows to the database using **SQLModel**.
|
||||
In the previous chapter, we saw how to add rows to the database using **SQLModel**.
|
||||
|
||||
Now let's talk a bit about why the `id` field **can't be `NULL`** on the database because it's a **primary key**, and we declare it using `Field(primary_key=True)`.
|
||||
|
||||
@@ -11,7 +11,7 @@ But the same `id` field actually **can be `None`** in the Python code, so we dec
|
||||
|
||||
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py[ln:6-10]!}
|
||||
|
||||
# Code below ommitted 👇
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -68,7 +68,7 @@ If we ran this code before saving the hero to the database and the `hero_1.id` w
|
||||
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
|
||||
```
|
||||
|
||||
But by declaring it with `Optional[int]` the editor will help us to avoid writing broken code by showing us a warning telling us that the code could be invalid if `hero_1.id` is `None`. 🔍
|
||||
But by declaring it with `Optional[int]`, the editor will help us to avoid writing broken code by showing us a warning telling us that the code could be invalid if `hero_1.id` is `None`. 🔍
|
||||
|
||||
## Print the Default `id` Values
|
||||
|
||||
@@ -79,7 +79,7 @@ We can confirm that by printing our heroes before adding them to the database:
|
||||
|
||||
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py[ln:23-31]!}
|
||||
|
||||
# Code below ommitted 👇
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -98,7 +98,7 @@ That will output:
|
||||
```console
|
||||
$ python app.py
|
||||
|
||||
// Output above ommitted 👆
|
||||
// Output above omitted 👆
|
||||
|
||||
Before interacting with the database
|
||||
Hero 1: id=None name='Deadpond' secret_name='Dive Wilson' age=None
|
||||
@@ -118,7 +118,7 @@ What happens when we `add` these objects to the **session**?
|
||||
|
||||
After we add the `Hero` instance objects to the **session**, the IDs are *still* `None`.
|
||||
|
||||
We can verify by creating a session using a `with` block, and adding the objects. And then printing them again:
|
||||
We can verify by creating a session using a `with` block and adding the objects. And then printing them again:
|
||||
|
||||
```Python hl_lines="19-21"
|
||||
# Code above omitted 👆
|
||||
@@ -144,7 +144,7 @@ This will, again, output the `id`s of the objects as `None`:
|
||||
```console
|
||||
$ python app.py
|
||||
|
||||
// Output above ommitted 👆
|
||||
// Output above omitted 👆
|
||||
|
||||
After adding to the session
|
||||
Hero 1: id=None name='Deadpond' secret_name='Dive Wilson' age=None
|
||||
@@ -165,7 +165,7 @@ Then we can `commit` the changes in the session, and print again:
|
||||
|
||||
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial001.py[ln:33-48]!}
|
||||
|
||||
# Code below ommitted 👇
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -184,7 +184,7 @@ And now, something unexpected happens, look at the output, it seems as if the `H
|
||||
```console
|
||||
$ python app.py
|
||||
|
||||
// Output above ommitted 👆
|
||||
// Output above omitted 👆
|
||||
|
||||
// Here the engine talks to the database, the SQL part
|
||||
INFO Engine BEGIN (implicit)
|
||||
@@ -399,7 +399,7 @@ In this case, after committing the object to the database with the **session**,
|
||||
|
||||
## Print Data After Closing the Session
|
||||
|
||||
Now, as a fnal experiment, we can also print data after the **session** is closed.
|
||||
Now, as a final experiment, we can also print data after the **session** is closed.
|
||||
|
||||
There are no surprises here, it still works:
|
||||
|
||||
@@ -450,7 +450,7 @@ Now let's review all this code once again.
|
||||
|
||||
And as we created the **engine** with `echo=True`, we can see the SQL statements being executed at each step.
|
||||
|
||||
```{ .python .annotate hl_lines="54" }
|
||||
```{ .python .annotate }
|
||||
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial002.py!}
|
||||
```
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ The class `Hero` has a reference to the class `Team` internally.
|
||||
|
||||
But the class `Team` also has a reference to the class `Hero`.
|
||||
|
||||
So, if those two classes where in separate files and you tried to import the classes in each other's file directly, it would result in a **circular import**. 🔄
|
||||
So, if those two classes were in separate files and you tried to import the classes in each other's file directly, it would result in a **circular import**. 🔄
|
||||
|
||||
And Python will not be able to handle it and will throw an error. 🚨
|
||||
|
||||
@@ -170,7 +170,7 @@ Let's assume that now the file structure is:
|
||||
|
||||
The problem with circular imports is that Python can't resolve them at <abbr title="While it is executing the program, as oposed to the code as just text in a file stored on disk.">*runtime*</abbr>.
|
||||
|
||||
but when using Python **type annotations** it's very common to need to declare the type of some variables with classes imported from other files.
|
||||
But when using Python **type annotations** it's very common to need to declare the type of some variables with classes imported from other files.
|
||||
|
||||
And the files with those classes might **also need to import** more things from the first files.
|
||||
|
||||
@@ -198,7 +198,7 @@ It has a value of `True` for editors and tools that analyze the code with the ty
|
||||
|
||||
But when Python is executing, its value is `False`.
|
||||
|
||||
So, we can us it in an `if` block and import things inside the `if` block. And they will be "imported" only for editors, but not at runtime.
|
||||
So, we can use it in an `if` block and import things inside the `if` block. And they will be "imported" only for editors, but not at runtime.
|
||||
|
||||
### Hero Model File
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ The `Team` model will be in a table automatically named `"team"`, and it will ha
|
||||
|
||||
* `id`, the primary key, automatically generated by the database
|
||||
* `name`, the name of the team
|
||||
* We also tell **SQLModel** to create an index for this column
|
||||
* `headquarters`, the headquarters of the team
|
||||
|
||||
And finally we mark it as a table in the config.
|
||||
@@ -107,7 +108,7 @@ Most of that should look familiar:
|
||||
|
||||
The column will be named `team_id`. It will be an integer, and it could be `NULL` in the database (or `None` in Python), becase there could be some heroes that don't belong to any team.
|
||||
|
||||
As we don't have to explicitly pass `team_id=None` when creating a hero, we add a default of `None` to the `Field()`.
|
||||
We add a default of `None` to the `Field()` so we don't have to explicitly pass `team_id=None` when creating a hero.
|
||||
|
||||
Now, here's the new part:
|
||||
|
||||
|
||||
@@ -39,6 +39,6 @@ After deleting it successfully, we just return a response of:
|
||||
|
||||
## Recap
|
||||
|
||||
That's it, feel free to try it out in the interactve docs UI to delete some heroes. 💥
|
||||
That's it, feel free to try it out in the interactive docs UI to delete some heroes. 💥
|
||||
|
||||
Using **FastAPI** to read data and combining it with **SQLModel** makes it quite straightforward to delete data from the database.
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# Read Heroes with Limit and Offset wtih FastAPI
|
||||
# Read Heroes with Limit and Offset with FastAPI
|
||||
|
||||
When a client sends a request to get all the heroes, we have been returning them all.
|
||||
|
||||
But if we had **thousands** of heroes that could consume a lot of **computational resources**, network bandwith, etc.
|
||||
But if we had **thousands** of heroes that could consume a lot of **computational resources**, network bandwidth, etc.
|
||||
|
||||
So we probably want to limit it.
|
||||
So, we probably want to limit it.
|
||||
|
||||
Let's use the same **offset** and **limit** we learned about in the previous tutorial chapters for the API.
|
||||
|
||||
!!! info
|
||||
In many cases this is also called **pagination**.
|
||||
In many cases, this is also called **pagination**.
|
||||
|
||||
## Add a Limit and Offset to the Query Parameters
|
||||
|
||||
@@ -38,13 +38,13 @@ And by default, we will return a maximum of `100` heroes, so `limit` will have a
|
||||
|
||||
</details>
|
||||
|
||||
We want to allow clients to set a different `offset` and `limit` values.
|
||||
We want to allow clients to set different `offset` and `limit` values.
|
||||
|
||||
But we don't want them to be able to set a `limit` of something like `9999`, that's over `9000`! 😱
|
||||
|
||||
So, to prevent it, we add additional validation to the `limit` query parameter, declaring that it has to be **l**ess **t**han or **e**qual to `100` with `lte=100`.
|
||||
|
||||
This way, a client can decide to take less heroes if they want, but not more.
|
||||
This way, a client can decide to take fewer heroes if they want, but not more.
|
||||
|
||||
!!! info
|
||||
If you need to refresh how query parameters and their validation work, check out the docs in FastAPI:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
We have been using the same `Hero` model to declare the schema of the data we receive in the API, the table model in the database, and the schema of the data we send back in responses.
|
||||
|
||||
But in most of the cases there are slight differences, let's use multiple models to solve it.
|
||||
But in most of the cases, there are slight differences. Let's use multiple models to solve it.
|
||||
|
||||
Here you will see the main and biggest feature of **SQLModel**. 😎
|
||||
|
||||
@@ -10,7 +10,7 @@ Here you will see the main and biggest feature of **SQLModel**. 😎
|
||||
|
||||
Let's start by reviewing the automatically generated schemas from the docs UI.
|
||||
|
||||
For input we have:
|
||||
For input, we have:
|
||||
|
||||
<img class="shadow" alt="Interactive API docs UI" src="/img/tutorial/fastapi/simple-hero-api/image01.png">
|
||||
|
||||
@@ -20,7 +20,7 @@ This means that the client could try to use the same ID that already exists in t
|
||||
|
||||
That's not what we want.
|
||||
|
||||
We want the client to only send the data that is needed to create a new hero:
|
||||
We want the client only to send the data that is needed to create a new hero:
|
||||
|
||||
* `name`
|
||||
* `secret_name`
|
||||
@@ -63,7 +63,7 @@ The ultimate goal of an API is for some **clients to use it**.
|
||||
|
||||
The clients could be a frontend application, a command line program, a graphical user interface, a mobile application, another backend application, etc.
|
||||
|
||||
And the code those clients write depend on what our API tells them they **need to send**, and what they can **expect to receive**.
|
||||
And the code those clients write depends on what our API tells them they **need to send**, and what they can **expect to receive**.
|
||||
|
||||
Making both sides very clear will make it much easier to interact with the API.
|
||||
|
||||
@@ -164,7 +164,7 @@ Let's first check how is the process to create a hero now:
|
||||
|
||||
Let's check that in detail.
|
||||
|
||||
Now we use the type annotation `HeroCreate` for the request JSON data, in the `hero` parameter of the **path operation function**.
|
||||
Now we use the type annotation `HeroCreate` for the request JSON data in the `hero` parameter of the **path operation function**.
|
||||
|
||||
```Python hl_lines="3"
|
||||
# Code above omitted 👆
|
||||
@@ -180,9 +180,9 @@ The method `.from_orm()` reads data from another object with attributes and crea
|
||||
|
||||
The alternative is `Hero.parse_obj()` that reads data from a dictionary.
|
||||
|
||||
But as in this case we have a `HeroCreate` instance in the `hero` variable, this is an object with attributes, so we use `.from_orm()` to read those attributes.
|
||||
But as in this case, we have a `HeroCreate` instance in the `hero` variable. This is an object with attributes, so we use `.from_orm()` to read those attributes.
|
||||
|
||||
With this we create a new `Hero` instance (the one for the database) and put it in the variable `db_hero` from the data in the `hero` variable that is the `HeroCreate` instance we received from the request.
|
||||
With this, we create a new `Hero` instance (the one for the database) and put it in the variable `db_hero` from the data in the `hero` variable that is the `HeroCreate` instance we received from the request.
|
||||
|
||||
```Python hl_lines="3"
|
||||
# Code above omitted 👆
|
||||
@@ -192,7 +192,7 @@ With this we create a new `Hero` instance (the one for the database) and put it
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
Then we just `add` it to the **session**, `commit`, and `refresh` it, and finally we return the same `db_hero` variable that has the just refreshed `Hero` instance.
|
||||
Then we just `add` it to the **session**, `commit`, and `refresh` it, and finally, we return the same `db_hero` variable that has the just refreshed `Hero` instance.
|
||||
|
||||
Because it is just refreshed, it has the `id` field set with a new ID taken from the database.
|
||||
|
||||
@@ -206,30 +206,30 @@ And now that we return it, FastAPI will validate the data with the `response_mod
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
This will validate that all the data that we promised is there, and will remove any data we didn't declare.
|
||||
This will validate that all the data that we promised is there and will remove any data we didn't declare.
|
||||
|
||||
!!! tip
|
||||
This filtering could be very important, and could be a very good security feature, for example to make sure you filter private data, hashed passwords, etc.
|
||||
This filtering could be very important and could be a very good security feature, for example, to make sure you filter private data, hashed passwords, etc.
|
||||
|
||||
You can read more about it in the <a href="https://fastapi.tiangolo.com/tutorial/response-model/" class="external-link" target="_blank">FastAPI docs about Response Model</a>.
|
||||
|
||||
In particular, it will make sure that the `id` is there, and that it is indeed an integer (and not `None`).
|
||||
In particular, it will make sure that the `id` is there and that it is indeed an integer (and not `None`).
|
||||
|
||||
## Shared Fields
|
||||
|
||||
But looking closely, we could see that these models have a lot of **duplicated information**.
|
||||
|
||||
All **the 3 models** declare that thay share some **common fields** that look exactly the same:
|
||||
All **the 3 models** declare that they share some **common fields** that look exactly the same:
|
||||
|
||||
* `name`, required
|
||||
* `secret_name`, required
|
||||
* `age`, optional
|
||||
|
||||
And then they declare other fields with some differences (in this case only about the `id`).
|
||||
And then they declare other fields with some differences (in this case, only about the `id`).
|
||||
|
||||
We want to **avoid duplicated information** if possible.
|
||||
|
||||
This is important if, for example, in the future we decide to **refactor the code** and rename one field (column). For example, from `secret_name` to `secret_identity`.
|
||||
This is important if, for example, in the future, we decide to **refactor the code** and rename one field (column). For example, from `secret_name` to `secret_identity`.
|
||||
|
||||
If we have that duplicated in multiple models, we could easily forget to update one of them. But if we **avoid duplication**, there's only one place that would need updating. ✨
|
||||
|
||||
@@ -305,6 +305,31 @@ And of course, all these fields will be in the columns for the resulting `hero`
|
||||
|
||||
And those inherited fields will also be in the **autocompletion** and **inline errors** in editors, etc.
|
||||
|
||||
### Columns and Inheritance with Multiple Models
|
||||
|
||||
Notice that the parent model `HeroBase` is not a **table model**, but still, we can declare `name` and `age` using `Field(index=True)`.
|
||||
|
||||
```Python hl_lines="4 6 9"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/fastapi/multiple_models/tutorial002.py[ln:7-14]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/fastapi/multiple_models/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
This won't affect this parent **data model** `HeroBase`.
|
||||
|
||||
But once the child model `Hero` (the actual **table model**) inherits those fields, it will use those field configurations to create the indexes when creating the tables in the database.
|
||||
|
||||
### The `HeroCreate` **Data Model**
|
||||
|
||||
Now let's see the `HeroCreate` model that will be used to define the data that we want to receive in the API when creating a new hero.
|
||||
@@ -336,9 +361,9 @@ And because we can't leave the empty space when creating a new class, but we don
|
||||
|
||||
This means that there's nothing else special in this class apart from the fact that it is named `HeroCreate` and that it inherits from `HeroBase`.
|
||||
|
||||
As an alternative, we could use `HeroBase` directly in the API code instead of `HeroCreate`, but it would show up in the auomatic docs UI with that name "`HeroBase`" which could be **confusing** for clients. Instead, "`HeroCreate`" is a bit more explicit about what it is for.
|
||||
As an alternative, we could use `HeroBase` directly in the API code instead of `HeroCreate`, but it would show up in the automatic docs UI with that name "`HeroBase`" which could be **confusing** for clients. Instead, "`HeroCreate`" is a bit more explicit about what it is for.
|
||||
|
||||
On top of that, we could easily decide in the future that we want to receive **more data** when creating a new hero apart from the data in `HeroBase` (for example a password), and now we already have the class to put those extra fields.
|
||||
On top of that, we could easily decide in the future that we want to receive **more data** when creating a new hero apart from the data in `HeroBase` (for example, a password), and now we already have the class to put those extra fields.
|
||||
|
||||
### The `HeroRead` **Data Model**
|
||||
|
||||
@@ -365,7 +390,7 @@ This one just declares that the `id` field is required when reading a hero from
|
||||
|
||||
## Review the Updated Docs UI
|
||||
|
||||
The FastAPI code is still the same as above, we still use `Hero`, `HeroCreate`, and `HeroRead`. But now we define them in a smarter way with inheritance.
|
||||
The FastAPI code is still the same as above, we still use `Hero`, `HeroCreate`, and `HeroRead`. But now, we define them in a smarter way with inheritance.
|
||||
|
||||
So, we can jump to the docs UI right away and see how they look with the updated data.
|
||||
|
||||
@@ -375,7 +400,7 @@ Let's see the new UI for creating a hero:
|
||||
|
||||
<img class="shadow" alt="Interactive API docs UI" src="/img/tutorial/fastapi/multiple-models/image02.png">
|
||||
|
||||
Nice! It now shows that to create a hero, we just pass the `name`, `secret_name`, and optinally `age`.
|
||||
Nice! It now shows that to create a hero, we just pass the `name`, `secret_name`, and optionally `age`.
|
||||
|
||||
We no longer pass an `id`.
|
||||
|
||||
@@ -391,7 +416,7 @@ And if we check the schema for the **Read Heroes** *path operation* it will also
|
||||
|
||||
## Inheritance and Table Models
|
||||
|
||||
We just saw how powerful inheritance of these models can be.
|
||||
We just saw how powerful the inheritance of these models could be.
|
||||
|
||||
This is a very simple example, and it might look a bit... meh. 😅
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ But if the integer is not the ID of any hero in the database, it will not find a
|
||||
|
||||
So, we check it in an `if` block, if it's `None`, we raise an `HTTPException` with a `404` status code.
|
||||
|
||||
And to use it we first import `HTTPException` from `fastapi`.
|
||||
And to use it, we first import `HTTPException` from `fastapi`.
|
||||
|
||||
This will let the client know that they probably made a mistake on their side and requested a hero that doesn't exist in the database.
|
||||
|
||||
|
||||
@@ -55,11 +55,11 @@ And the same way, we declared the `TeamRead` with only the same base fields of t
|
||||
|
||||
# Code here omitted 👈
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:32-37]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:31-36]!}
|
||||
|
||||
# Code here omitted 👈
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:46-47]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:45-46]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -80,11 +80,11 @@ In this case, we used `response_model=TeamRead` and `response_model=HeroRead`, s
|
||||
```Python hl_lines="3 8 12 17"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:105-110]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:104-109]!}
|
||||
|
||||
# Code here omitted 👈
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:160-165]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:159-164]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -102,7 +102,7 @@ In this case, we used `response_model=TeamRead` and `response_model=HeroRead`, s
|
||||
|
||||
Now let's stop for a second and think about it.
|
||||
|
||||
We cannot simply include *all* the data including all the internal relationships, because each **hero** has an attribute `team` with their team, and then that **team** also has an attribute `heroes` with all the **heroes** in the team, including this one.
|
||||
We cannot simply include *all* the data, including all the internal relationships, because each **hero** has an attribute `team` with their team, and then that **team** also has an attribute `heroes` with all the **heroes** in the team, including this one.
|
||||
|
||||
If we tried to include everything, we could make the server application **crash** trying to extract **infinite data**, going through the same hero and team over and over again internally, something like this:
|
||||
|
||||
@@ -152,7 +152,7 @@ If we tried to include everything, we could make the server application **crash*
|
||||
}
|
||||
```
|
||||
|
||||
As you can see, in this example we would get the hero **Rusty-Man**, and from this hero we would get the team **Preventers**, and then from this team we would get its heroes, of course, including **Rusty-Man**... 😱
|
||||
As you can see, in this example, we would get the hero **Rusty-Man**, and from this hero we would get the team **Preventers**, and then from this team we would get its heroes, of course, including **Rusty-Man**... 😱
|
||||
|
||||
So we start again, and in the end, the server would just crash trying to get all the data with a `"Maximum recursion error"`, we would not even get a response like the one above.
|
||||
|
||||
@@ -164,7 +164,7 @@ This is a decision that will depend on **each application**.
|
||||
|
||||
In our case, let's say that if we get a **list of heroes**, we don't want to also include each of their teams in each one.
|
||||
|
||||
And if we get a **list of teams**, we don't want to get a a list of the heroes for each one.
|
||||
And if we get a **list of teams**, we don't want to get a list of the heroes for each one.
|
||||
|
||||
But if we get a **single hero**, we want to include the team data (without the team's heroes).
|
||||
|
||||
@@ -195,7 +195,7 @@ We'll add them **after** the other models so that we can easily reference the pr
|
||||
|
||||
</details>
|
||||
|
||||
These two models are very **simple in code**, but there's a lot happening here, let's check it out.
|
||||
These two models are very **simple in code**, but there's a lot happening here. Let's check it out.
|
||||
|
||||
### Inheritance and Type Annotations
|
||||
|
||||
@@ -203,7 +203,7 @@ The `HeroReadWithTeam` **inherits** from `HeroRead`, which means that it will ha
|
||||
|
||||
And then it adds the **new field** `team`, which could be `None`, and is declared with the type `TeamRead` with the base fields for reading a team.
|
||||
|
||||
Then we do the same for the `TeamReadWithHeroes`, it **inherits** from `TeamRead`, and declare the **new field** `heroes` which is a list of `HeroRead`.
|
||||
Then we do the same for the `TeamReadWithHeroes`, it **inherits** from `TeamRead`, and declares the **new field** `heroes`, which is a list of `HeroRead`.
|
||||
|
||||
### Data Models Without Relationship Attributes
|
||||
|
||||
@@ -213,7 +213,7 @@ Instead, here these are only **data models** that will tell FastAPI **which attr
|
||||
|
||||
### Reference to Other Models
|
||||
|
||||
Also notice that the field `team` is not declared with this new `TeamReadWithHeroes`, because that would again create that infinite recursion of data. Instead, we declare it with the normal `TeamRead` model.
|
||||
Also, notice that the field `team` is not declared with this new `TeamReadWithHeroes`, because that would again create that infinite recursion of data. Instead, we declare it with the normal `TeamRead` model.
|
||||
|
||||
And the same for `TeamReadWithHeroes`, the model used for the new field `heroes` uses `HeroRead` to get only each hero's data.
|
||||
|
||||
@@ -326,7 +326,7 @@ Now we get the list of **heroes** included:
|
||||
|
||||
## Recap
|
||||
|
||||
Using the same techniques to declare additonal **data models** we can tell FastAPI what data to return in the responses, even when we return **table models**.
|
||||
Using the same techniques to declare additional **data models**, we can tell FastAPI what data to return in the responses, even when we return **table models**.
|
||||
|
||||
Here we almost **didn't have to change the FastAPI app** code, but of course, there will be cases where you need to get the data and process it in different ways in the *path operation function* before returning it.
|
||||
|
||||
@@ -334,4 +334,4 @@ But even in those cases, you will be able to define the **data models** to use i
|
||||
|
||||
By this point, you already have a very robust API to handle data in a SQL database combining **SQLModel** with **FastAPI**, and implementing **best practices**, like data validation, conversion, filtering, and documentation. ✨
|
||||
|
||||
In the next chapter I'll tell you how to implement automated **testing** for your application using FastAPI and SQLModel. ✅
|
||||
In the next chapter, I'll tell you how to implement automated **testing** for your application using FastAPI and SQLModel. ✅
|
||||
|
||||
@@ -22,7 +22,7 @@ You can see that there's a possible "Successful Response" with a code `200`, but
|
||||
|
||||
<img class="shadow" alt="API docs UI without response data schemas" src="/img/tutorial/fastapi/response-model/image01.png">
|
||||
|
||||
Right now we only tell FastAPI the data we want to receive, but we don't tell it yet the data we want to send back.
|
||||
Right now, we only tell FastAPI the data we want to receive, but we don't tell it yet the data we want to send back.
|
||||
|
||||
Let's do that now. 🤓
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ We import `Depends()` from `fastapi`. Then we use it in the *path operation func
|
||||
|
||||
You can read more about it in the FastAPI documentation <a href="https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#order-the-parameters-as-you-need-tricks" class="external-link" target="_blank">Path Parameters and Numeric Validations - Order the parameters as you need, tricks</a>
|
||||
|
||||
The value of a dependency will **only be used for one request**, FastAPI will call it right before calling your code, and will give you the value from that dependency.
|
||||
The value of a dependency will **only be used for one request**, FastAPI will call it right before calling your code and will give you the value from that dependency.
|
||||
|
||||
If it had `yield`, then it will continue the rest of the execution once you are done sending the response. In the case of the **session**, it will finish the cleanup code from the `with` block, closing the session, etc.
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ $ python -m pip install fastapi "uvicorn[standard]"
|
||||
```
|
||||
|
||||
</div>
|
||||
s
|
||||
|
||||
## **SQLModel** Code - Models, Engine
|
||||
|
||||
Now let's start with the SQLModel code.
|
||||
@@ -152,13 +152,13 @@ It will be called when a user sends a request with a `POST` **operation** to the
|
||||
|
||||
## The **SQLModel** Advantage
|
||||
|
||||
Here's where having our **SQLModel** class models be both **SQLAlchemy** models and **Pydantic** models at the same tieme shine. ✨
|
||||
Here's where having our **SQLModel** class models be both **SQLAlchemy** models and **Pydantic** models at the same time shine. ✨
|
||||
|
||||
Here we use the **same** class model to define the **request body** that will be received by our API.
|
||||
|
||||
Because **FastAPI** is based on Pydantic, it will use the same model (the Pydantic part) to do automatic data validation and <abbr title="also called serialization, marshalling">conversion</abbr> from the JSON request to an object that is an actual instance of the `Hero` class.
|
||||
|
||||
And then because this same **SQLModel** object is not only a **Pydantic** model instance but also a **SQLAlchemy** model instance, we can use it directly in a **session** to create the row in the database.
|
||||
And then, because this same **SQLModel** object is not only a **Pydantic** model instance but also a **SQLAlchemy** model instance, we can use it directly in a **session** to create the row in the database.
|
||||
|
||||
So we can use intuitive standard Python **type annotations**, and we don't have to duplicate a lot of the code for the database models and the API data models. 🎉
|
||||
|
||||
@@ -190,13 +190,13 @@ When a client sends a request to the **path** `/heroes/` with a `GET` HTTP **ope
|
||||
|
||||
## One Session per Request
|
||||
|
||||
Remember that we shoud use a SQLModel **session** per each group of operations and if we need other unrelated operations we should use a different session?
|
||||
Remember that we should use a SQLModel **session** per each group of operations and if we need other unrelated operations we should use a different session?
|
||||
|
||||
Here it is much more obvious.
|
||||
|
||||
We should normally have **one session per request** in most of the cases.
|
||||
|
||||
In some isolated cases we would want to have new sessions inside, so, **more than one session** per request.
|
||||
In some isolated cases, we would want to have new sessions inside, so, **more than one session** per request.
|
||||
|
||||
But we would **never want to *share* the same session** among different requests.
|
||||
|
||||
@@ -277,7 +277,7 @@ And then you can get them back with the **Read Heroes** *path operation*:
|
||||
|
||||
Now you can terminate that Uvicorn server by going back to the terminal and pressing <kbd>Ctrl+C</kbd>.
|
||||
|
||||
And then you can open **DB Browser for SQLite** and check the database, to explore the data and confirm that it indeed saved the heroes. 🎉
|
||||
And then, you can open **DB Browser for SQLite** and check the database, to explore the data and confirm that it indeed saved the heroes. 🎉
|
||||
|
||||
<img class="shadow" alt="DB Browser for SQLite showing the heroes" src="/img/tutorial/fastapi/simple-hero-api/db-browser-01.png">
|
||||
|
||||
@@ -287,4 +287,4 @@ Good job! This is already a FastAPI **web API** application to interact with the
|
||||
|
||||
There are several things we can improve and extend. For example, we want the database to decide the ID of each new hero, we don't want to allow a user to send it.
|
||||
|
||||
We will do all those improvements in the next chapters. 🚀
|
||||
We will make all those improvements in the next chapters. 🚀
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# FastAPI Path Opeartions for Teams - Other Models
|
||||
# FastAPI Path Operations for Teams - Other Models
|
||||
|
||||
Let's now update the **FastAPI** application to handle data for teams.
|
||||
|
||||
@@ -12,14 +12,14 @@ Let's add the models for the teams.
|
||||
|
||||
It's the same process we did for heroes, with a base model, a **table model**, and some other **data models**.
|
||||
|
||||
We have a `TeamBase` **data model**, and from it we inherit with a `Team` **table model**.
|
||||
We have a `TeamBase` **data model**, and from it, we inherit with a `Team` **table model**.
|
||||
|
||||
Then we also inherit from the `TeamBase` for the `TeamCreate` and `TeamRead` **data models**.
|
||||
|
||||
And we also create a `TeamUpdate` **data model**.
|
||||
|
||||
```Python hl_lines="7-9 12-15 18-19 22-23 26-29"
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:1-29]!}
|
||||
```Python hl_lines="7-9 12-15 18-19 22-23 26-28"
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:1-28]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -42,7 +42,7 @@ Let's now update the `Hero` models too.
|
||||
```Python hl_lines="3-8 11-15 17-18 21-22 25-29"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:32-58]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:31-57]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -66,10 +66,10 @@ And even though the `HeroBase` is *not* a **table model**, we can declare `team_
|
||||
|
||||
Notice that the **relationship attributes**, the ones with `Relationship()`, are **only** in the **table models**, as those are the ones that are handled by **SQLModel** with SQLAlchemy and that can have the automatic fetching of data from the database when we access them.
|
||||
|
||||
```Python hl_lines="11 39"
|
||||
```Python hl_lines="11 38"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:7-58]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:7-57]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -92,7 +92,7 @@ These are equivalent and very similar to the **path operations** for the **heroe
|
||||
```Python hl_lines="3-9 12-20 23-28 31-47 50-57"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:140-194]!}
|
||||
{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:139-193]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -108,9 +108,9 @@ These are equivalent and very similar to the **path operations** for the **heroe
|
||||
|
||||
## Using Relationships Attributes
|
||||
|
||||
Up to this point we are actually not using the **relationship attributes**, but we could access them in our code.
|
||||
Up to this point, we are actually not using the **relationship attributes**, but we could access them in our code.
|
||||
|
||||
In the next chapter we will play more with them.
|
||||
In the next chapter, we will play more with them.
|
||||
|
||||
## Check the Docs UI
|
||||
|
||||
|
||||
@@ -76,13 +76,13 @@ Let's start with a simple test, with just the basic test code we need the check
|
||||
|
||||
That's the **core** of the code we need for all the tests later.
|
||||
|
||||
But now we need to deal with a bit of logistics and details we are not paying attention to just yet. 🤓
|
||||
But now, we need to deal with a bit of logistics and details we are not paying attention to just yet. 🤓
|
||||
|
||||
## Testing Database
|
||||
|
||||
This test looks fine, but there's a problem.
|
||||
|
||||
If we run it, it will use the same **production database** that we are using to store our very important **heroes**, and we will end up adding adding unnecesary data to it, or even worse, in future tests we could end up removing production data.
|
||||
If we run it, it will use the same **production database** that we are using to store our very important **heroes**, and we will end up adding unnecesary data to it, or even worse, in future tests we could end up removing production data.
|
||||
|
||||
So, we should use an independent **testing database**, just for the tests.
|
||||
|
||||
@@ -155,7 +155,7 @@ That way, when we call `.create_all()` all the **table models** are correctly re
|
||||
|
||||
## Memory Database
|
||||
|
||||
Now we are not using the production database, instead we use a **new testing database** with the `testing.db` file, which is great.
|
||||
Now we are not using the production database. Instead, we use a **new testing database** with the `testing.db` file, which is great.
|
||||
|
||||
But SQLite also supports having an **in memory** database. This means that all the database is only in memory, and it is never saved in a file on disk.
|
||||
|
||||
@@ -171,7 +171,7 @@ Other alternatives and ideas 👀
|
||||
</summary>
|
||||
Before arriving at the idea of using an **in-memory database** we could have explored other alternatives and ideas.
|
||||
|
||||
The first, is that we are not deleting the file after we finish the test, so, the next test could have **leftover data**. So, the right thing would be to delete the file right after finishing the test. 🔥
|
||||
The first is that we are not deleting the file after we finish the test, so the next test could have **leftover data**. So, the right thing would be to delete the file right after finishing the test. 🔥
|
||||
|
||||
But if each test has to create a new file and then delete it afterwards, running all the tests could be **a bit slow**.
|
||||
|
||||
@@ -179,7 +179,7 @@ Right now, we have a file `testing.db` that is used by all the tests (we only ha
|
||||
|
||||
So, if we tried to run the tests at the same time **in parallel** to try to speed things up a bit, they would clash trying to use the *same* `testing.db` file.
|
||||
|
||||
Of couse, we could also fix that, using some **random name** for each testing database file... but in the case of SQLite, we have an even better alternative with just using an **in-memory database**. ✨
|
||||
Of course, we could also fix that, using some **random name** for each testing database file... but in the case of SQLite, we have an even better alternative by just using an **in-memory database**. ✨
|
||||
|
||||
</details>
|
||||
|
||||
@@ -208,7 +208,7 @@ And all the other tests can do the same.
|
||||
|
||||
Great, that works, and you could replicate all that process in each of the test functions.
|
||||
|
||||
But we had to add a lot of **boilerplate code** to handle the custom database, creating it in memory, the custom session, the dependency override.
|
||||
But we had to add a lot of **boilerplate code** to handle the custom database, creating it in memory, the custom session, and the dependency override.
|
||||
|
||||
Do we really have to duplicate all that for **each test**? No, we can do better! 😎
|
||||
|
||||
@@ -242,12 +242,12 @@ Let's see the first code example with a fixture:
|
||||
|
||||
**pytest** fixtures work in a very similar way to FastAPI dependencies, but have some minor differences:
|
||||
|
||||
* In pytest fixtures we need to add a decorator of `@pytest.fixture()` on top.
|
||||
* In pytest fixtures, we need to add a decorator of `@pytest.fixture()` on top.
|
||||
* To use a pytest fixture in a function, we have to declare the parameter with the **exact same name**. In FastAPI we have to **explicitly use `Depends()`** with the actual function inside it.
|
||||
|
||||
But apart from the way we declare them and how we tell the framework that we want to have them in the function, they **work in a very similar way**.
|
||||
|
||||
Now we create lot's of tests, and re-use that same fixture in all of them, saving us that **boilerplate code**.
|
||||
Now we create lot's of tests and re-use that same fixture in all of them, saving us that **boilerplate code**.
|
||||
|
||||
**pytest** will make sure to run them right before (and finish them right after) each test function. So, each test function will actually have its own database, engine, and session.
|
||||
|
||||
@@ -255,7 +255,7 @@ Now we create lot's of tests, and re-use that same fixture in all of them, savin
|
||||
|
||||
Awesome, that fixture helps us prevent a lot of duplicated code.
|
||||
|
||||
But currently we still have to write some code in the test function that will be repetitive for other tests, right now we:
|
||||
But currently, we still have to write some code in the test function that will be repetitive for other tests, right now we:
|
||||
|
||||
* create the **dependency override**
|
||||
* put it in the `app.dependency_overrides`
|
||||
@@ -277,7 +277,7 @@ So, we can create a **client fixture** that will be used in all the tests, and i
|
||||
!!! tip
|
||||
Check out the number bubbles to see what is done by each line of code.
|
||||
|
||||
Now we have a **client fixture** that in turns uses the **session fixture**.
|
||||
Now we have a **client fixture** that, in turn, uses the **session fixture**.
|
||||
|
||||
And in the actual test function, we just have to declare that we require this **client fixture**.
|
||||
|
||||
@@ -285,7 +285,7 @@ And in the actual test function, we just have to declare that we require this **
|
||||
|
||||
At this point, it all might seem like we just did a lot of changes for nothing, to get **the same result**. 🤔
|
||||
|
||||
But normally we will create **lots of other test functions**. And now all the boilerplate and complexity is **writen only once**, in those two fixtures.
|
||||
But normally we will create **lots of other test functions**. And now all the boilerplate and complexity is **written only once**, in those two fixtures.
|
||||
|
||||
Let's add some more tests:
|
||||
|
||||
@@ -311,13 +311,13 @@ Let's add some more tests:
|
||||
|
||||
That's why we add these two extra tests here.
|
||||
|
||||
Now, any additional test functions can be as **simple** as the first one, they just have to **declate the `client` parameter** to get the `TestClient` **fixture** with all the database stuff setup. Nice! 😎
|
||||
Now, any additional test functions can be as **simple** as the first one, they just have to **declare the `client` parameter** to get the `TestClient` **fixture** with all the database stuff setup. Nice! 😎
|
||||
|
||||
## Why Two Fixtures
|
||||
|
||||
Now, seeing the code we could think, why do we put **two fixtures** instead of **just one** with all the code? And that makes total sense!
|
||||
Now, seeing the code, we could think, why do we put **two fixtures** instead of **just one** with all the code? And that makes total sense!
|
||||
|
||||
For these examples, **that would have been simpler**, there's no need to separate that code in two fixtures for them...
|
||||
For these examples, **that would have been simpler**, there's no need to separate that code into two fixtures for them...
|
||||
|
||||
But for the next test function, we will require **both fixtures**, the **client** and the **session**.
|
||||
|
||||
@@ -340,7 +340,7 @@ But for the next test function, we will require **both fixtures**, the **client*
|
||||
|
||||
</details>
|
||||
|
||||
In this test function we want to check that the *path operation* to **read a list of heroes** actually sends us heroes.
|
||||
In this test function, we want to check that the *path operation* to **read a list of heroes** actually sends us heroes.
|
||||
|
||||
But if the **database is empty**, we would get an **empty list**, and we wouldn't know if the hero data is being sent correctly or not.
|
||||
|
||||
@@ -362,7 +362,7 @@ The function for the **client fixture** and the actual testing function will **b
|
||||
|
||||
## Add the Rest of the Tests
|
||||
|
||||
Using the same ideas, requiring the fixtures, creating data that we need for the tests, etc. we can now add the rest of the tests, they look quite similar to what we have done up to now.
|
||||
Using the same ideas, requiring the fixtures, creating data that we need for the tests, etc., we can now add the rest of the tests. They look quite similar to what we have done up to now.
|
||||
|
||||
```Python hl_lines="3 18 33"
|
||||
# Code above omitted 👆
|
||||
@@ -406,9 +406,9 @@ project/test_main.py <font color="#A6E22E">....... [100%]</font>
|
||||
|
||||
Did you read all that? Wow, I'm impressed! 😎
|
||||
|
||||
Adding tests to your application will give you a lot of **certainty** that everything is **working correctly**, as you indended.
|
||||
Adding tests to your application will give you a lot of **certainty** that everything is **working correctly**, as you intended.
|
||||
|
||||
And tests will be notoriously useful when **refactoring** your code, **changing things**, **adding features**. Because tests they can help catch a lot of errors that can be easily introduced by refactoring.
|
||||
And tests will be notoriously useful when **refactoring** your code, **changing things**, **adding features**. Because tests can help catch a lot of errors that can be easily introduced by refactoring.
|
||||
|
||||
And they will give you the confidence to work faster and **more efficiently**, because you know that you are checking if you are **not breaking anything**. 😅
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Now let's see how to update data in the database with a **FastAPI** *path operat
|
||||
|
||||
## `HeroUpdate` Model
|
||||
|
||||
We want clients to be able to udpate the `name`, the `secret_name`, and the `age` of a hero.
|
||||
We want clients to be able to update the `name`, the `secret_name`, and the `age` of a hero.
|
||||
|
||||
But we don't want them to have to include all the data again just to **update a single field**.
|
||||
|
||||
@@ -61,7 +61,7 @@ We will use a `PATCH` HTTP operation. This is used to **partially update data**,
|
||||
|
||||
</details>
|
||||
|
||||
We also read the `hero_id` from the *path parameter* an the request body, a `HeroUpdate`.
|
||||
We also read the `hero_id` from the *path parameter* and the request body, a `HeroUpdate`.
|
||||
|
||||
### Read the Existing Hero
|
||||
|
||||
@@ -100,7 +100,7 @@ But that also means that if we just call `hero.dict()` we will get a dictionary
|
||||
}
|
||||
```
|
||||
|
||||
And then if we update the hero in the database with this data, we would be removing any existing values, and that's probably **not what the client intended**.
|
||||
And then, if we update the hero in the database with this data, we would be removing any existing values, and that's probably **not what the client intended**.
|
||||
|
||||
But fortunately Pydantic models (and so SQLModel models) have a parameter we can pass to the `.dict()` method for that: `exclude_unset=True`.
|
||||
|
||||
@@ -200,7 +200,7 @@ We are **not simply omitting** the data that has the **default values**.
|
||||
|
||||
And we are **not simply omitting** anything that is `None`.
|
||||
|
||||
This means that, if a model in the database **has a value different than the default**, the client could **reset it to the same value as the default**, or even `None`, and we would **still notice it** and **update it accordingly**. 🤯🚀
|
||||
This means that if a model in the database **has a value different than the default**, the client could **reset it to the same value as the default**, or even `None`, and we would **still notice it** and **update it accordingly**. 🤯🚀
|
||||
|
||||
So, if the client wanted to intentionally remove the `age` of a hero, they could just send a JSON with:
|
||||
|
||||
@@ -218,11 +218,11 @@ And when getting the data with `hero.dict(exclude_unset=True)`, we would get:
|
||||
}
|
||||
```
|
||||
|
||||
So, we would use that value and upate the `age` to `None` in the database, **just as the client intended**.
|
||||
So, we would use that value and update the `age` to `None` in the database, **just as the client intended**.
|
||||
|
||||
Notice that `age` here is `None`, and **we still detected it**.
|
||||
|
||||
Also that `name` was not even sent, and we don't *accidentaly* set it to `None` or something, we just didn't touch it, because the client didn't sent it, so we are **pefectly fine**, even in these corner cases. ✨
|
||||
Also, that `name` was not even sent, and we don't *accidentally* set it to `None` or something. We just didn't touch it because the client didn't send it, so we are **perfectly fine**, even in these corner cases. ✨
|
||||
|
||||
These are some of the advantages of Pydantic, that we can use with SQLModel. 🎉
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
## Type hints
|
||||
|
||||
If you need a refreshed about how to use Python type hints (type annotations), check <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.
|
||||
If you need a refresher about how to use Python type hints (type annotations), check <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.
|
||||
|
||||
You can also check the <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">mypy cheat sheet</a>.
|
||||
|
||||
**SQLModel** uses type annotations for everything, this way you can use a familiar Python syntax and get all the editor support posible, with autocompletion and in-editor error checking.
|
||||
**SQLModel** uses type annotations for everything, this way you can use a familiar Python syntax and get all the editor support possible, with autocompletion and in-editor error checking.
|
||||
|
||||
## Intro
|
||||
|
||||
@@ -97,7 +97,7 @@ $ python3 --version
|
||||
// This is too old! 😱
|
||||
Python 3.5.6
|
||||
// Let's see if python3.10 is available
|
||||
$ python3.10 --verson
|
||||
$ python3.10 --version
|
||||
// Oh, no, this one is not available 😔
|
||||
command not found: python3.10
|
||||
$ python3.9 --version
|
||||
|
||||
406
docs/tutorial/indexes.md
Normal file
@@ -0,0 +1,406 @@
|
||||
# Indexes - Optimize Queries
|
||||
|
||||
We just saw how to get some data `WHERE` a **condition** is true. For example, where the hero **name is "Deadpond"**.
|
||||
|
||||
If we just create the tables and the data as we have been doing, when we `SELECT` some data using `WHERE`, the database would have to **scan** through **each one of the records** to find the ones that **match**. This is not a problem with 3 heroes as in these examples.
|
||||
|
||||
But imagine that your database has **thousands** or **millions** of **records**, if every time you want to find the heroes with the name "Deadpond" it has to scan through **all** of the records to find all the possible matches, then that becomes problematic, as it would be too slow.
|
||||
|
||||
I'll show you how to handle it with a database **index**.
|
||||
|
||||
The change in the code is **extremely small**, but it's useful to understand what's happening behind the scenes, so I'll show you **how it all works** and what it means.
|
||||
|
||||
---
|
||||
|
||||
If you already executed the previous examples and have a database with data, **remove the database file** before running each example, that way you won't have duplicate data and you will be able to get the same results.
|
||||
|
||||
## No Time to Explain
|
||||
|
||||
Are you already a **SQL expert** and don't have time for all my explanations?
|
||||
|
||||
Fine, in that case, you can **sneak peek** the final code to create indexes here.
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python hl_lines="8 10"
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
..but if you are not an expert, **continue reading**, this will probably be useful. 🤓
|
||||
|
||||
## What is an Index
|
||||
|
||||
In general, an **index** is just something we can have to help us **find things faster**. It normally works by having things in **order**. Let's think about some real-life examples before even thinking about databases and code.
|
||||
|
||||
### An Index and a Dictionary
|
||||
|
||||
Imagine a **dictionary**, a book with definitions of words. 📔 ...not a Python `dict`. 😅
|
||||
|
||||
Let's say that you want to **find a word**, for example the word "**database**". You take the dictionary, and open it somewhere, for example in the middle. Maybe you see some definitions of words that start with `m`, like `manual`, so you conclude that you are in the letter `m` in the dictionary.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary001.svg">
|
||||
|
||||
You know that in the alphabet, the letter `d` for `database` comes **before** the letter `m` for `manual`.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary002.svg">
|
||||
|
||||
So, you know you have to search in the dictionary **before** the point you currently are. You still don't know where the word `database` is, because you don't know exactly where the letter `d` is in the dictionary, but you know that **it is not after** that point, you can now **discard the right half** of the dictionary in your search.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary003.svg">
|
||||
|
||||
Next, you **open the dictionary again**, but only taking into account the **half of the dictionary** that can contain the word you want, the **left part of the dictionary**. You open it in the middle of that left part and now you arrive maybe at the letter `f`.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary004.svg">
|
||||
|
||||
You know that `d` from `database` comes before `f`. So it has to be **before** that. But now you know that `database` **is not after** that point, and you can discard the dictionary from that point onward.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary005.svg">
|
||||
|
||||
Now you have a **small section of dictionary** to search (only a **quarter** of dictionary can have your word). You take that **quarter** of the pages at the start of the dictionary that can contain your word, and open it in the middle of that section. Maybe you arrive at the letter `c`.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary006.svg">
|
||||
|
||||
You know the word `database` has to be **after** that and **not before** that point, so you can discard the left part of that block of pages.
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary007.svg">
|
||||
|
||||
You repeat this process **a few more times**, and you finally arrive at the letter `d`, you continue with the same process in that section for the letter `d` and you finally **find the word** `database`. 🎉
|
||||
|
||||
<img src="/img/tutorial/indexes/dictionary008.svg">
|
||||
|
||||
You had to open the dictionary a few times, maybe **5 or 10**. That's actually **very little work** compared to what it could have been.
|
||||
|
||||
!!! note "Technical Details"
|
||||
Do you like **fancy words**? Cool! Programmers tend to like fancy words. 😅
|
||||
|
||||
That <abbr title="a recipe, a sequence of predefined steps that achieve a result">algorithm</abbr> I showed you above is called **Binary Search**.
|
||||
|
||||
It's called like that because you **search** something by splitting the dictionary (or any ordered list of things) in **two** ("binary" means "two") parts. And you do that process multiple times until you find what you want.
|
||||
|
||||
### An Index and a Novel
|
||||
|
||||
Let's now imagine you are reading a **novel book**. And someone told you that at some point, they mention a **database**, and you want to find that chapter.
|
||||
|
||||
How do you find the word "*database*" there? You might have to read **the entire book** to find where the word "*database*" is located in the book. So, instead of opening the book 5 or 10 times, you would have to open each of the **500 pages** and read them one by one until you find the word. You might enjoy the book, though. 😅
|
||||
|
||||
But if we are only interested in **quickly finding information** (as when working with SQL databases), then reading each of the 500 pages is **too inefficient** when there could be an option to open the book in 5 or 10 places and find what you're looking for.
|
||||
|
||||
### A Technical Book with an Index
|
||||
|
||||
Now let's imagine you are reading a technical book. For example, with several topics about programming. And there's a couple of sections where it talks about a **database**.
|
||||
|
||||
This book might have a **book index**: a section in the book that has some **names of topics covered** and the **page numbers** in the book where you can read about them. And the topic names are **sorted** in alphabetic order, pretty much like a dictionary (a book with words, as in the previous example).
|
||||
|
||||
In this case, you can open that book in the end (or in the beginning) to find the **book index** section, it would have only a few pages. And then, you can do the same process as with the **dictionary** example above.
|
||||
|
||||
Open the index, and after **5 or 10 steps**, quickly find the topic "**database**" with the page numbers where that is covered, for example "page 253 in Chapter 5". Now you used the dictionary technique to find the **topic**, and that topic gave you a **page number**.
|
||||
|
||||
Now you know that you need to find "**page 253**". But by looking at the closed book you still don't know where that page is, so you have to **find that page**. To find it, you can do the same process again, but this time, instead of searching for a **topic** in the **index**, you are searching for a **page number** in the **entire book**. And after **5 or 10 more steps**, you find the page 253 in Chapter 5.
|
||||
|
||||
<img src="/img/tutorial/indexes/techbook001.svg">
|
||||
|
||||
After this, even though this book is not a dictionary and has some particular content, you were able to **find the section** in the book that talks about a "**database**" in a **few steps** (say 10 or 20, instead of reading all the 500 pages).
|
||||
|
||||
The main point is that the index is **sorted**, so we can use the same process we used for the **dictionary** to find the topic. And then that gives us a page number, and the **page numbers are also sorted**! 😅
|
||||
|
||||
When we have a list of sorted things we can apply the same technique, and that's the whole trick here, we use the same technique first for the **topics** in the index and then for the **page numbers** to find the actual chapter.
|
||||
|
||||
Such efficiency! 😎
|
||||
|
||||
## What are Database Indexes
|
||||
|
||||
**Database indexes** are very similar to **book indexes**.
|
||||
|
||||
Database indexes store some info, some keys, in a way that makes it **easy and fast to find** (for example sorted), and then for each key they **point to some data somewhere else** in the database.
|
||||
|
||||
Let's see a more clear example. Let's say you have this table in a database:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>id</th><th>name</th><th>secret_name</th><th>age</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td><td>Deadpond</td><td>Dive Wilson</td><td>null</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td><td>Spider-Boy</td><td>Pedro Parqueador</td><td>null</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td><td>Rusty-Man</td><td>Tommy Sharp</td><td>48</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
And let's imagine you have **many more rows**, many more heroes. Probably **thousands**.
|
||||
|
||||
If you tell the SQL database to get you a hero by a specific name, for example `Spider-Boy` (by using the `name` in the `WHERE` part of the SQL query), the database will have to **scan** all the heroes, checking **one by one** to find all the ones with a name of `Spider-Boy`.
|
||||
|
||||
In this case, there's only one, but there's nothing limiting the database from having **more records with the same name**. And because of that, the database would **continue searching** and checking each one of the records, which would be very slow.
|
||||
|
||||
But now let's say that the database has an index for the column `name`. The index could look something like this, we could imagine that the index is like an additional special table that the database manages automatically:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th><th>id</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Deadpond</td><td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Rusty-Man</td><td>3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spider-Boy</td><td>2</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
It would have each `name` field from the `hero` table **in order**. It would not be sorted by `id`, but by `name` (in alphabetical order, as the `name` is a string). So, first it would have `Deadpond`, then `Rusty-Man`, and last `Spider-Boy`. It would also include the `id` of each hero. Remember that this could have **thousands** of heroes.
|
||||
|
||||
Then the database would be able to use more or less the same ideas in the examples above with the **dictionary** and the **book index**.
|
||||
|
||||
It could start somewhere (for example, in the middle of the index). It could arrive at some hero there in the middle, like `Rusty-Man`. And because the **index** has the `name` fields in order, the database would know that it can **discard all the previous index rows** and **only search** in the following index rows.
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th><th>id</th>
|
||||
</tr>
|
||||
<tr style="background-color: #F5F5F5; color: #999999;">
|
||||
<td>Deadpond</td><td>1</td>
|
||||
</tr>
|
||||
<tr style="background-color: #F5F5F5; color: #999999;">
|
||||
<td>Rusty-Man</td><td>3</td>
|
||||
</tr>
|
||||
<tr style="background-color: #FFF2CC;">
|
||||
<td>Spider-Boy</td><td>2</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
And that way, as with the example with the dictionary above, **instead of reading thousands of heroes**, the database would be able to do a few steps, say **5 or 10 steps**, and arrive at the row of the index that has `Spider-Boy`, even if the table (and index) has thousands of rows:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th><th>id</th>
|
||||
</tr>
|
||||
<tr style="background-color: #F5F5F5; color: #999999;">
|
||||
<td>Deadpond</td><td>1</td>
|
||||
</tr>
|
||||
<tr style="background-color: #F5F5F5; color: #999999;">
|
||||
<td>Rusty-Man</td><td>3</td>
|
||||
</tr>
|
||||
<tr style="background-color: #D5E8D4;">
|
||||
<td>✨ Spider-Boy ✨</td><td>2</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Then by looking at **this index row**, it would know that the `id` for `Spider-Boy` in the `hero` table is `2`.
|
||||
|
||||
So then it could **search that `id`** in the `hero` table using more or less the **same technique**.
|
||||
|
||||
That way, in the end, instead of reading thousands of records, the database only had to do **a few steps** to find the hero we wanted.
|
||||
|
||||
## Updating the Index
|
||||
|
||||
As you can imagine, for all this to work, the index would need to be **up to date** with the data in the database.
|
||||
|
||||
If you had to update it **manually** in code, it would be very cumbersome and **error-prone**, as it would be easy to end up in a state where the index is not up to date and points to incorrect data. 😱
|
||||
|
||||
Here's the good news: when you create an index in a **SQL Database**, the database takes care of **updating** it **automatically** whenever it's necessary. 😎🎉
|
||||
|
||||
If you **add new records** to the `hero` table, the database will **automatically** update the index. It will do the **same process** of **finding** the right place to put the new index data (those **5 or 10 steps** described above), and then it will save the new index information there. The same would happen when you **update** or **delete** data.
|
||||
|
||||
Defining and creating an index is very **easy** with SQL databases. And then **using it** is even easier... it's transparent. The database will figure out which index to use automatically, the SQL queries don't even change.
|
||||
|
||||
So, in SQL databases **indexes are great**! And are super **easy to use**. Why not just have indexes for everything? .....Because indexes also have a "**cost**" in computation and storage (disk space).
|
||||
|
||||
## Index Cost
|
||||
|
||||
There's a **cost** associated with **indexes**. 💰
|
||||
|
||||
When you don't have an index and add a **new row** to the table `hero`, the database has to perform **1 operation** to add the new hero row at the end of the table.
|
||||
|
||||
But if you have an **index** for the **hero names**, now the database has to perform the same **1 operation** to add that row **plus** some extra **5 or 10 operations** in the index, to find the right spot for the name, to then add that **index record** there.
|
||||
|
||||
And if you have an index for the `name`, one for the `age`, and one for the `secret_name`, now the database has to perform the same **1 operation** to add that row **plus** some extra **5 or 10 operations** in the index **times 3**, for each of the indexes. This means that now adding one row takes something like **31 operations**.
|
||||
|
||||
This also means that you are **exchanging** the time it takes to **read** data for the time it takes to **write** data plus some extra **space** in the database.
|
||||
|
||||
If you have queries that get data out of the database comparing each one of those fields (for example using `WHERE`), then it makes total sense to have indexes for each one of them. Because **31 operations** while creating or updating data (plus the space of the index) is much, much better than the possible **500 or 1000 operations** to read all the rows to be able to compare them using each field.
|
||||
|
||||
But if you **never** have queries that find records by the `secret_name` (you never use `secret_name` in the `WHERE` part) it probably doesn't make sense to have an index for the `secret_name` field/column, as that will increase the computational and space **cost** of writing and updating the database.
|
||||
|
||||
## Create an Index with SQL
|
||||
|
||||
Phew, that was a lot of theory and explanations. 😅
|
||||
|
||||
The most important thing about indexes is **understanding** them, how, and when to use them.
|
||||
|
||||
Let's now see the **SQL** syntax to create an **index**. It is very simple:
|
||||
|
||||
```SQL hl_lines="3"
|
||||
CREATE INDEX ix_hero_name
|
||||
ON hero (name)
|
||||
```
|
||||
|
||||
This means, more or less:
|
||||
|
||||
> Hey SQL database 👋, please `CREATE` an `INDEX` for me.
|
||||
>
|
||||
> I want the name of the index to be `ix_hero_name`.
|
||||
>
|
||||
> This index should be `ON` the table `hero`, it refers to that table.
|
||||
>
|
||||
> The column I want you to use for it is `name`.
|
||||
|
||||
## Declare Indexes with SQLModel
|
||||
|
||||
And now let's see how to define indexes in **SQLModel**.
|
||||
|
||||
The change in code is underwhelming, it's very simple. 😆
|
||||
|
||||
Here's the `Hero` model we had before:
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!./docs_src/tutorial/where/tutorial001.py[ln:1-10]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/where/tutorial001.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
Let's now update it to tell **SQLModel** to create an index for the `name` field when creating the table:
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!./docs_src/tutorial/indexes/tutorial001.py[ln:1-10]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/indexes/tutorial001.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
We use the same `Field()` again as we did before, and set `index=True`. That's it! 🚀
|
||||
|
||||
Notice that we didn't set an argument of `default=None` or anything similar. This means that **SQLModel** (thanks to Pydantic) will keep it as a **required** field.
|
||||
|
||||
!!! info
|
||||
SQLModel (actually SQLAlchemy) will **automatically generate the index name** for you.
|
||||
|
||||
In this case the generated name would be `ix_hero_name`.
|
||||
|
||||
## Query Data
|
||||
|
||||
Now, to query the data using the field `name` and the new index we don't have to do anything special or different in the code, it's just **the same code**.
|
||||
|
||||
The SQL database will figure it out **automatically**. ✨
|
||||
|
||||
This is great because it means that indexes are very **simple to use**. But it might also feel counterintuitive at first, as you are **not doing anything** explicitly in the code to make it obvious that the index is useful, it all happens in the database behind the scenes.
|
||||
|
||||
```Python hl_lines="5"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/indexes/tutorial001.py[ln:36-41]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/indexes/tutorial001.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
This is exactly the same code as we had before, but now the database will **use the index** underneath.
|
||||
|
||||
## Run the Program
|
||||
|
||||
If you run the program now, you will see an output like this:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python app.py
|
||||
|
||||
// Some boilerplate output omitted 😉
|
||||
|
||||
// Create the table
|
||||
CREATE TABLE hero (
|
||||
id INTEGER,
|
||||
name VARCHAR NOT NULL,
|
||||
secret_name VARCHAR NOT NULL,
|
||||
age INTEGER,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
|
||||
// Create the index 🤓🎉
|
||||
CREATE INDEX ix_hero_name ON hero (name)
|
||||
|
||||
// The SELECT with WHERE looks the same
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age
|
||||
FROM hero
|
||||
WHERE hero.name = ?
|
||||
INFO Engine [no key 0.00014s] ('Deadpond',)
|
||||
|
||||
// The resulting hero
|
||||
secret_name='Dive Wilson' age=None id=1 name='Deadpond'
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## More Indexes
|
||||
|
||||
We are going to query the `hero` table doing comparisons on the `age` field too, so we should **define an index** for that one as well:
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py[ln:1-10]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
In this case, we want the default value of `age` to continue being `None`, so we set `default=None` when using `Field()`.
|
||||
|
||||
Now when we use **SQLModel** to create the database and tables, it will also create the **indexes** for these two columns in the `hero` table.
|
||||
|
||||
So, when we query the database for the `hero` table and use those **two columns** to define what data we get, the database will be able to **use those indexes** to improve the **reading performance**. 🚀
|
||||
|
||||
## Primary Key and Indexes
|
||||
|
||||
You probably noticed that we didn't set `index=True` for the `id` field.
|
||||
|
||||
Because the `id` is already the **primary key**, the database will automatically create an internal **index** for it.
|
||||
|
||||
The database always creates an internal index for **primary keys** automatically, as those are the primary way to organize, store, and retrieve data. 🤓
|
||||
|
||||
But if you want to be **frequently querying** the SQL database for any **other field** (e.g. using any other field in the `WHERE` section), you will probably want to have at least an **index** for that.
|
||||
|
||||
## Recap
|
||||
|
||||
**Indexes** are very important to improve **reading performance** and speed when querying the database. 🏎
|
||||
|
||||
Creating and using them is very **simple** and easy. The most important part is to understand **how** they work, **when** to create them, and for **which columns**.
|
||||
@@ -81,7 +81,7 @@ In this case, instead of getting all the 7 rows, we are limiting them to only ge
|
||||
|
||||
<img class="shadow" alt="table with first 3 rows selected" src="/img/tutorial/offset-and-limit/limit.svg">
|
||||
|
||||
## Run the Program on the Comamnd Line
|
||||
## Run the Program on the Command Line
|
||||
|
||||
If we run it on the command line, it will output:
|
||||
|
||||
@@ -153,7 +153,7 @@ Each of those methods applies the change in the internal special select statemen
|
||||
|
||||
**Offset** means "skip this many rows", and as we want to skip the ones we already saw, the first three, we use `.offset(3)`.
|
||||
|
||||
## Run the Program with Offset on the Comamnd Line
|
||||
## Run the Program with Offset on the Command Line
|
||||
|
||||
Now we can run the program on the command line, and it will output:
|
||||
|
||||
@@ -207,9 +207,9 @@ The database right now has **only 7 rows**, so this query can only get 1 row.
|
||||
|
||||
But don't worry, the database won't throw an error trying to get 3 rows when there's only one (as would happen with a Python list).
|
||||
|
||||
The database knows that we want to **limit** the number of results, but it doesn't necessarily has to find those many results.
|
||||
The database knows that we want to **limit** the number of results, but it doesn't necessarily have to find that many results.
|
||||
|
||||
## Run the Program with the Last Batch on the Comamnd Line
|
||||
## Run the Program with the Last Batch on the Command Line
|
||||
|
||||
And if we run it in the command line, it will output:
|
||||
|
||||
@@ -271,7 +271,7 @@ Of course, you can also combine `.limit()` and `.offset()` with `.where()` and o
|
||||
|
||||
</details>
|
||||
|
||||
## Run the Program with Limit and Where on the Comamnd Line
|
||||
## Run the Program with Limit and Where on the Command Line
|
||||
|
||||
If we run it on the command line, it will find all the heroes in the database with an age above 32. That would normally be 4 heroes.
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ And **both fields are primary keys**. We hadn't used this before. 🤓
|
||||
Let's see the `Team` model, it's almost identical as before, but with a little change:
|
||||
|
||||
```Python hl_lines="8"
|
||||
# Code above ommited 👆
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/many_to_many/tutorial001.py[ln:15-20]!}
|
||||
|
||||
@@ -56,7 +56,7 @@ Let's see the `Team` model, it's almost identical as before, but with a little c
|
||||
|
||||
</details>
|
||||
|
||||
The **relationship attribute `heroes`** is still a list of heroes, annotatted as `List["Hero"]`. Again, we use `"Hero"` in quotes because we haven't declared that class yet by this point in the code (but as you know, editors and **SQLModel** understand that).
|
||||
The **relationship attribute `heroes`** is still a list of heroes, annotated as `List["Hero"]`. Again, we use `"Hero"` in quotes because we haven't declared that class yet by this point in the code (but as you know, editors and **SQLModel** understand that).
|
||||
|
||||
We use the same **`Relationship()`** function.
|
||||
|
||||
@@ -69,7 +69,7 @@ And here's the important part to allow the **many-to-many** relationship, we use
|
||||
Let's see the other side, here's the `Hero` model:
|
||||
|
||||
```Python hl_lines="9"
|
||||
# Code above ommited 👆
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/many_to_many/tutorial001.py[ln:23-29]!}
|
||||
|
||||
@@ -102,7 +102,7 @@ And now we have a **`link_model=HeroTeamLink`**. ✨
|
||||
The same as before, we will have the rest of the code to create the **engine**, and a function to create all the tables `create_db_and_tables()`.
|
||||
|
||||
```Python hl_lines="9"
|
||||
# Code above ommited 👆
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/many_to_many/tutorial001.py[ln:32-39]!}
|
||||
|
||||
@@ -122,7 +122,7 @@ The same as before, we will have the rest of the code to create the **engine**,
|
||||
And as in previous examples, we will add that function to a function `main()`, and we will call that `main()` function in the main block:
|
||||
|
||||
```Python hl_lines="4"
|
||||
# Code above ommited 👆
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/many_to_many/tutorial001.py[ln:78-79]!}
|
||||
# We will do more stuff here later 👈
|
||||
@@ -149,7 +149,7 @@ If you run the code in the command line, it would output:
|
||||
```console
|
||||
$ python app.py
|
||||
|
||||
// Boilerplate ommited 😉
|
||||
// Boilerplate omitted 😉
|
||||
|
||||
INFO Engine
|
||||
CREATE TABLE team (
|
||||
|
||||
@@ -60,7 +60,7 @@ Notice that each hero can only have **one** connection. But each team can receiv
|
||||
|
||||
## Introduce Many-to-Many
|
||||
|
||||
But let's say that as **Deadpond** is a great chracter, they recruit him to the new **Preventers** team, but he's still part of the **Z-Force** team too.
|
||||
But let's say that as **Deadpond** is a great character, they recruit him to the new **Preventers** team, but he's still part of the **Z-Force** team too.
|
||||
|
||||
So, now, we need to be able to have a hero that is connected to **many** teams. And then, each team, should still be able to receive **many** heroes. So we need a **Many-to-Many** relationship.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ We'll continue with the same examples we have been using in the previous chapter
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/where/tutorial006.py!}
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -32,7 +32,7 @@ We have been iterating over the rows in a `result` object like:
|
||||
```Python hl_lines="7-8"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/where/tutorial006.py[ln:44-49]!}
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py[ln:44-49]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
@@ -41,7 +41,7 @@ We have been iterating over the rows in a `result` object like:
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/where/tutorial006.py!}
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
@@ -96,7 +96,7 @@ Next, use that `Relationship` to declare a new attribute in the model classes:
|
||||
|
||||
## What Are These Relationship Attributes
|
||||
|
||||
This new attributes are not the same as fields, they **don't represent a column** directly in the database, and their value is not a singular value like an integer. Their value is the actual **entire object** that is related.
|
||||
These new attributes are not the same as fields, they **don't represent a column** directly in the database, and their value is not a singular value like an integer. Their value is the actual **entire object** that is related.
|
||||
|
||||
So, in the case of a `Hero` instance, if you call `hero.team`, you will get the entire `Team` instance object that this hero belongs to. ✨
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ You can try that out in **DB Browser for SQLite**:
|
||||
|
||||
### A SQL Shortcut
|
||||
|
||||
If we want to get all the columns like in this case above, in SQL there's a shortcut, instead of specifying each of the column names wew could write a `*`:
|
||||
If we want to get all the columns like in this case above, in SQL there's a shortcut, instead of specifying each of the column names we could write a `*`:
|
||||
|
||||
```SQL
|
||||
SELECT *
|
||||
@@ -97,9 +97,9 @@ FROM hero
|
||||
|
||||
That would end up in the same result. Although we won't use that for **SQLModel**.
|
||||
|
||||
### `SELECT` Less Columns
|
||||
### `SELECT` Fewer Columns
|
||||
|
||||
We can also `SELECT` less columns, for example:
|
||||
We can also `SELECT` fewer columns, for example:
|
||||
|
||||
```SQL
|
||||
SELECT id, name
|
||||
@@ -150,7 +150,7 @@ Another variation is that most of the SQL keywords like `SELECT` can also be wri
|
||||
|
||||
This is the interesting part. The tables returned by SQL databases **don't have to exist** in the database as independent tables. 🧙
|
||||
|
||||
For example, in our database, we only have one table that has all the columns, `id`, `name`, `secret_name`, `age`. And here we are getting a result table with less columns.
|
||||
For example, in our database, we only have one table that has all the columns, `id`, `name`, `secret_name`, `age`. And here we are getting a result table with fewer columns.
|
||||
|
||||
One of the main points of SQL is to be able to keep the data structured in different tables, without repeating data, etc, and then query the database in many ways and get many different tables as a result.
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ As before, we'll continue from where we left off with the previous code.
|
||||
<summary>👀 Full file preview</summary>
|
||||
|
||||
```Python
|
||||
{!./docs_src/tutorial/where/tutorial006.py!}
|
||||
{!./docs_src/tutorial/indexes/tutorial002.py!}
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -39,7 +39,7 @@ In a similar way to `SELECT` statements, the first part defines the columns to w
|
||||
|
||||
And the second part, with the `WHERE`, defines to which rows it should apply that update.
|
||||
|
||||
In this case, as we only have one hero with the name `"Spider-Boy"`, it will only apply the udpate in that row.
|
||||
In this case, as we only have one hero with the name `"Spider-Boy"`, it will only apply the update in that row.
|
||||
|
||||
!!! info
|
||||
Notice that in the `UPDATE` the single equals sign (`=`) means **assignment**, setting a column to some value.
|
||||
@@ -70,7 +70,7 @@ After that update, the data in the table will look like this, with the new age f
|
||||
</table>
|
||||
|
||||
!!! tip
|
||||
It will probably be more common to find the row to update by Id, for example:
|
||||
It will probably be more common to find the row to update by `id`, for example:
|
||||
|
||||
```SQL
|
||||
UPDATE hero
|
||||
@@ -340,7 +340,7 @@ Now let's review all that code:
|
||||
|
||||
The update process with **SQLModel** is more or less the same as with creating new objects, you add them to the session, and then commit them.
|
||||
|
||||
This also means that you can update several fields (atributes, columns) at once, and you can also update several objects (heroes) at once:
|
||||
This also means that you can update several fields (attributes, columns) at once, and you can also update several objects (heroes) at once:
|
||||
|
||||
```{ .python .annotate hl_lines="15-17 19-21 23" }
|
||||
# Code above omitted 👆
|
||||
|
||||
@@ -204,7 +204,7 @@ We care specially about the **select** statement:
|
||||
|
||||
</details>
|
||||
|
||||
## Filter Rows Using `WHERE` wtih **SQLModel**
|
||||
## Filter Rows Using `WHERE` with **SQLModel**
|
||||
|
||||
Now, the same way that we add `WHERE` to a SQL statement to filter rows, we can add a `.where()` to a **SQLModel** `select()` statment to filter rows, which will filter the objects returned:
|
||||
|
||||
@@ -233,7 +233,7 @@ The object returned by `select(Hero)` is a special type of object with some meth
|
||||
|
||||
One of those methods is `.where()` used to (unsurprisingly) add a `WHERE` to the SQL statement in that **select** object.
|
||||
|
||||
There are other methods that will will explore later. 💡
|
||||
There are other methods that we will explore later. 💡
|
||||
|
||||
Most of these methods return the same object again after modifying it.
|
||||
|
||||
@@ -271,7 +271,7 @@ In the example above we are using two equal signs (`==`). That's called the "**e
|
||||
!!! tip
|
||||
An **operator** is just a symbol that is put beside one value or in the middle of two values to do something with them.
|
||||
|
||||
`==` is called **equality** operator because it checks if two things are **equal**.
|
||||
`==` is called the **equality** operator because it checks if two things are **equal**.
|
||||
|
||||
When writing Python, if you write something using this equality operator (`==`) like:
|
||||
|
||||
@@ -698,7 +698,7 @@ age=35 id=5 name='Black Lion' secret_name='Trevor Challa'
|
||||
|
||||
Here's a good moment to see that being able to use these pure Python expressions instead of keyword arguments can help a lot. ✨
|
||||
|
||||
We can use the same standard Python comparison operators like `.
|
||||
We can use the same standard Python comparison operators like `<`, `<=`, `>`, `>=`, `==`, etc.
|
||||
|
||||
## Multiple `.where()`
|
||||
|
||||
@@ -865,7 +865,7 @@ It would be an error telling you that
|
||||
|
||||
This is because as we are using pure and plain Python annotations for the fields, `age` is indeed annotated as `Optional[int]`, which means `int` or `None`.
|
||||
|
||||
By using this simple and standard Python type annotations We get the benefit of the extra simplicity and the inline error checks when creating or using instances. ✨
|
||||
By using this simple and standard Python type annotations we get the benefit of the extra simplicity and the inline error checks when creating or using instances. ✨
|
||||
|
||||
And when we use these special **class attributes** in a `.where()`, during execution of the program, the special class attribute will know that the comparison only applies for the values that are not `NULL` in the database, and it will work correctly.
|
||||
|
||||
@@ -933,3 +933,7 @@ And with that the editor knows this code is actually fine, because this is a spe
|
||||
## Recap
|
||||
|
||||
You can use `.where()` with powerful expressions using **SQLModel** columns (the special class attributes) to filter the rows that you want. 🚀
|
||||
|
||||
Up to now, the database would have been **looking through each one of the records** (rows) to find the ones that match what you want. If you have thousands or millions of records, this could be very **slow**. 😱
|
||||
|
||||
In the next section I'll tell you how to add **indexes** to the database, this is what will make the queries **very efficient**. 😎
|
||||
|
||||
@@ -6,9 +6,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
money: condecimal(max_digits=5, decimal_places=3) = Field(default=0)
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlmodel import Field, Relationship, SQLModel
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
heroes: List["Hero"] = Relationship(back_populates="team")
|
||||
@@ -13,9 +13,9 @@ class Team(SQLModel, table=True):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional[Team] = Relationship(back_populates="heroes")
|
||||
|
||||
@@ -8,9 +8,9 @@ if TYPE_CHECKING:
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional["Team"] = Relationship(back_populates="heroes")
|
||||
|
||||
@@ -8,7 +8,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
heroes: List["Hero"] = Relationship(back_populates="team")
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, SQLModel, create_engine
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -6,9 +6,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class HeroCreate(SQLModel):
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, sele
|
||||
|
||||
|
||||
class TeamBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ class TeamUpdate(SQLModel):
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
@@ -6,9 +6,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, sele
|
||||
|
||||
|
||||
class TeamBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
|
||||
@@ -24,15 +24,14 @@ class TeamRead(TeamBase):
|
||||
|
||||
|
||||
class TeamUpdate(SQLModel):
|
||||
id: Optional[int] = None
|
||||
name: Optional[str] = None
|
||||
headquarters: Optional[str] = None
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class HeroBase(SQLModel):
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
class Hero(HeroBase, table=True):
|
||||
|
||||
0
docs_src/tutorial/indexes/__init__.py
Normal file
51
docs_src/tutorial/indexes/tutorial001.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
|
||||
engine = create_engine(sqlite_url, echo=True)
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
||||
def create_heroes():
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
hero_2 = Hero(name="Spider-Boy", secret_name="Pedro Parqueador")
|
||||
hero_3 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48)
|
||||
|
||||
with Session(engine) as session:
|
||||
session.add(hero_1)
|
||||
session.add(hero_2)
|
||||
session.add(hero_3)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
def select_heroes():
|
||||
with Session(engine) as session:
|
||||
statement = select(Hero).where(Hero.name == "Deadpond")
|
||||
results = session.exec(statement)
|
||||
for hero in results:
|
||||
print(hero)
|
||||
|
||||
|
||||
def main():
|
||||
create_db_and_tables()
|
||||
create_heroes()
|
||||
select_heroes()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
59
docs_src/tutorial/indexes/tutorial002.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
|
||||
engine = create_engine(sqlite_url, echo=True)
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
||||
def create_heroes():
|
||||
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
|
||||
hero_2 = Hero(name="Spider-Boy", secret_name="Pedro Parqueador")
|
||||
hero_3 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48)
|
||||
hero_4 = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32)
|
||||
hero_5 = Hero(name="Black Lion", secret_name="Trevor Challa", age=35)
|
||||
hero_6 = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36)
|
||||
hero_7 = Hero(name="Captain North America", secret_name="Esteban Rogelios", age=93)
|
||||
|
||||
with Session(engine) as session:
|
||||
session.add(hero_1)
|
||||
session.add(hero_2)
|
||||
session.add(hero_3)
|
||||
session.add(hero_4)
|
||||
session.add(hero_5)
|
||||
session.add(hero_6)
|
||||
session.add(hero_7)
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
def select_heroes():
|
||||
with Session(engine) as session:
|
||||
statement = select(Hero).where(Hero.age <= 35)
|
||||
results = session.exec(statement)
|
||||
for hero in results:
|
||||
print(hero)
|
||||
|
||||
|
||||
def main():
|
||||
create_db_and_tables()
|
||||
create_heroes()
|
||||
select_heroes()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -14,7 +14,7 @@ class HeroTeamLink(SQLModel, table=True):
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
heroes: List["Hero"] = Relationship(back_populates="teams", link_model=HeroTeamLink)
|
||||
@@ -22,9 +22,9 @@ class Team(SQLModel, table=True):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
teams: List[Team] = Relationship(back_populates="heroes", link_model=HeroTeamLink)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class HeroTeamLink(SQLModel, table=True):
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
heroes: List["Hero"] = Relationship(back_populates="teams", link_model=HeroTeamLink)
|
||||
@@ -22,9 +22,9 @@ class Team(SQLModel, table=True):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
teams: List[Team] = Relationship(back_populates="heroes", link_model=HeroTeamLink)
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class HeroTeamLink(SQLModel, table=True):
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
hero_links: List[HeroTeamLink] = Relationship(back_populates="team")
|
||||
@@ -26,9 +26,9 @@ class Team(SQLModel, table=True):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_links: List[HeroTeamLink] = Relationship(back_populates="hero")
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,9 +5,9 @@ from sqlmodel import Field, Session, SQLModel, create_engine
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
|
||||
@@ -5,7 +5,7 @@ from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, sele
|
||||
|
||||
class Team(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
headquarters: str
|
||||
|
||||
heroes: List["Hero"] = Relationship()
|
||||
@@ -13,9 +13,9 @@ class Team(SQLModel, table=True):
|
||||
|
||||
class Hero(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
name: str
|
||||
name: str = Field(index=True)
|
||||
secret_name: str
|
||||
age: Optional[int] = None
|
||||
age: Optional[int] = Field(default=None, index=True)
|
||||
|
||||
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
|
||||
team: Optional[Team] = Relationship()
|
||||
|
||||