Add source examples for Python 3.10 and 3.9 with updated syntax (#842)

Co-authored-by: Esteban Maya Cadavid <emayacadavid9@gmail.com>
This commit is contained in:
Sebastián Ramírez
2024-03-21 17:49:38 -05:00
committed by GitHub
parent 4c3f242ae2
commit 9141c8a920
39 changed files with 7456 additions and 25 deletions

View File

@@ -14,6 +14,20 @@ We will continue with the same code as before, but we'll modify it a little the
Again, we will create several heroes to have some data to select from:
//// tab | Python 3.10+
```Python hl_lines="4-10"
# Code above omitted 👆
{!./docs_src/tutorial/offset_and_limit/tutorial001_py310.py[ln:21-39]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="4-10"
# Code above omitted 👆
@@ -22,18 +36,46 @@ Again, we will create several heroes to have some data to select from:
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial001.py!}
```
////
///
## Review Select All
This is the code we had to select all the heroes in the `select()` examples:
//// tab | Python 3.10+
```Python hl_lines="3-8"
# Code above omitted 👆
{!./docs_src/tutorial/select/tutorial003_py310.py[ln:34-39]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="3-8"
# Code above omitted 👆
@@ -42,12 +84,26 @@ This is the code we had to select all the heroes in the `select()` examples:
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/select/tutorial003_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/select/tutorial003.py!}
```
////
///
But this would get us **all** the heroes at the same time, in a database that could have thousands, that could be problematic.
@@ -56,6 +112,20 @@ But this would get us **all** the heroes at the same time, in a database that co
We currently have 7 heroes in the database. But we could as well have thousands, so let's limit the results to get only the first 3:
//// tab | Python 3.10+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/offset_and_limit/tutorial001_py310.py[ln:42-47]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="5"
# Code above omitted 👆
@@ -64,12 +134,26 @@ We currently have 7 heroes in the database. But we could as well have thousands,
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial001_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial001.py!}
```
////
///
The special **select** object we get from `select()` also has a method `.limit()` that we can use to limit the results to a certain number.
@@ -133,6 +217,20 @@ How do we get the next 3?
We can use `.offset()`:
//// tab | Python 3.10+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/offset_and_limit/tutorial002_py310.py[ln:42-47]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="5"
# Code above omitted 👆
@@ -141,12 +239,26 @@ We can use `.offset()`:
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial002_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial002.py!}
```
////
///
The way this works is that the special **select** object we get from `select()` has methods like `.where()`, `.offset()` and `.limit()`.
@@ -186,6 +298,20 @@ INFO Engine [no key 0.00020s] (3, 3)
Then to get the next batch of 3 rows we would offset all the ones we already saw, the first 6:
//// tab | Python 3.10+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/offset_and_limit/tutorial003_py310.py[ln:42-47]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="5"
# Code above omitted 👆
@@ -194,12 +320,26 @@ Then to get the next batch of 3 rows we would offset all the ones we already saw
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial003_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial003.py!}
```
////
///
The database right now has **only 7 rows**, so this query can only get 1 row.
@@ -255,6 +395,20 @@ If you try that in **DB Browser for SQLite**, you will get the same result:
Of course, you can also combine `.limit()` and `.offset()` with `.where()` and other methods you will learn about later:
//// tab | Python 3.10+
```Python hl_lines="5"
# Code above omitted 👆
{!./docs_src/tutorial/offset_and_limit/tutorial004_py310.py[ln:42-47]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="5"
# Code above omitted 👆
@@ -263,12 +417,26 @@ Of course, you can also combine `.limit()` and `.offset()` with `.where()` and o
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial004_py310.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/offset_and_limit/tutorial004.py!}
```
////
///
## Run the Program with Limit, Offset, and Where on the Command Line