🎨 Run pre-commit on all files and autoformat (#666)
This commit is contained in:
committed by
GitHub
parent
7f72c60ae4
commit
27a81b2112
@@ -159,7 +159,7 @@ As the `Hero` class model now has a field (column, attribute) `team_id`, we can
|
||||
|
||||
We haven't committed this hero to the database yet, but there are already a couple of things to pay **attention** to.
|
||||
|
||||
If the database already had some teams, we wouldn't even know **what is the ID** that is going to be automatically assigned to each team by the database, for example, we couldn't just guess `1` or `2`.
|
||||
If the database already had some teams, we wouldn't even know **what is the ID** that is going to be automatically assigned to each team by the database, for example, we couldn't just guess `1` or `2`.
|
||||
|
||||
But once the team is created and committed to the database, we can access the object's `id` field to get that ID.
|
||||
|
||||
@@ -171,8 +171,8 @@ That line alone would generate an output of:
|
||||
|
||||
```
|
||||
INFO Engine BEGIN (implicit)
|
||||
INFO Engine SELECT team.id AS team_id, team.name AS team_name, team.headquarters AS team_headquarters
|
||||
FROM team
|
||||
INFO Engine SELECT team.id AS team_id, team.name AS team_name, team.headquarters AS team_headquarters
|
||||
FROM team
|
||||
WHERE team.id = ?
|
||||
INFO Engine [generated in 0.00025s] (2,)
|
||||
```
|
||||
@@ -199,8 +199,8 @@ Let's now create two more heroes:
|
||||
When creating `hero_rusty_man`, we are accessing `team_preventers.id`, so that will also trigger a refresh of its data, generating an output of:
|
||||
|
||||
```
|
||||
INFO Engine SELECT team.id AS team_id, team.name AS team_name, team.headquarters AS team_headquarters
|
||||
FROM team
|
||||
INFO Engine SELECT team.id AS team_id, team.name AS team_name, team.headquarters AS team_headquarters
|
||||
FROM team
|
||||
WHERE team.id = ?
|
||||
INFO Engine [cached since 0.001795s ago] (1,)
|
||||
```
|
||||
@@ -256,18 +256,18 @@ $ python app.py
|
||||
INFO Engine BEGIN (implicit)
|
||||
|
||||
// Refresh the first hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
WHERE hero.id = ?
|
||||
INFO Engine [generated in 0.00021s] (1,)
|
||||
// Refresh the second hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
WHERE hero.id = ?
|
||||
INFO Engine [cached since 0.001575s ago] (2,)
|
||||
// Refresh the third hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
WHERE hero.id = ?
|
||||
INFO Engine [cached since 0.002518s ago] (3,)
|
||||
|
||||
|
||||
@@ -191,24 +191,24 @@ INFO Engine PRAGMA temp.table_info("hero")
|
||||
INFO Engine [raw sql] ()
|
||||
|
||||
// Create the tables
|
||||
INFO Engine
|
||||
INFO Engine
|
||||
CREATE TABLE team (
|
||||
id INTEGER,
|
||||
name VARCHAR NOT NULL,
|
||||
headquarters VARCHAR NOT NULL,
|
||||
id INTEGER,
|
||||
name VARCHAR NOT NULL,
|
||||
headquarters VARCHAR NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
|
||||
|
||||
INFO Engine [no key 0.00010s] ()
|
||||
INFO Engine
|
||||
INFO Engine
|
||||
CREATE TABLE hero (
|
||||
id INTEGER,
|
||||
name VARCHAR NOT NULL,
|
||||
secret_name VARCHAR NOT NULL,
|
||||
age INTEGER,
|
||||
team_id INTEGER,
|
||||
PRIMARY KEY (id),
|
||||
id INTEGER,
|
||||
name VARCHAR NOT NULL,
|
||||
secret_name VARCHAR NOT NULL,
|
||||
age INTEGER,
|
||||
team_id INTEGER,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY(team_id) REFERENCES team (id)
|
||||
)
|
||||
|
||||
@@ -229,9 +229,9 @@ So, the first SQL could also be written as:
|
||||
|
||||
```SQL
|
||||
CREATE TABLE team (
|
||||
id INTEGER,
|
||||
name TEXT NOT NULL,
|
||||
headquarters TEXT NOT NULL,
|
||||
id INTEGER,
|
||||
name TEXT NOT NULL,
|
||||
headquarters TEXT NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
```
|
||||
@@ -240,12 +240,12 @@ And the second table could be written as:
|
||||
|
||||
```SQL hl_lines="8"
|
||||
CREATE TABLE hero (
|
||||
id INTEGER,
|
||||
name TEXT NOT NULL,
|
||||
secret_name TEXT NOT NULL,
|
||||
age INTEGER,
|
||||
team_id INTEGER,
|
||||
PRIMARY KEY (id),
|
||||
id INTEGER,
|
||||
name TEXT NOT NULL,
|
||||
secret_name TEXT NOT NULL,
|
||||
age INTEGER,
|
||||
team_id INTEGER,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY(team_id) REFERENCES team (id)
|
||||
)
|
||||
```
|
||||
|
||||
@@ -203,8 +203,8 @@ $ python app.py
|
||||
// Previous output omitted 😉
|
||||
|
||||
// Get the heroes with their teams
|
||||
2021-08-09 08:55:50,682 INFO sqlalchemy.engine.Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
FROM hero, team
|
||||
2021-08-09 08:55:50,682 INFO sqlalchemy.engine.Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
FROM hero, team
|
||||
WHERE hero.team_id = team.id
|
||||
2021-08-09 08:55:50,682 INFO sqlalchemy.engine.Engine [no key 0.00015s] ()
|
||||
|
||||
@@ -323,7 +323,7 @@ $ python app.py
|
||||
// Previous output omitted 😉
|
||||
|
||||
// Select using a JOIN with automatic ON
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
FROM hero JOIN team ON team.id = hero.team_id
|
||||
INFO Engine [no key 0.00032s] ()
|
||||
|
||||
@@ -458,7 +458,7 @@ $ python app.py
|
||||
// Previous output omitted 😉
|
||||
|
||||
// SELECT using LEFT OUTER JOIN
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
FROM hero LEFT OUTER JOIN team ON team.id = hero.team_id
|
||||
|
||||
INFO Engine [no key 0.00051s] ()
|
||||
@@ -522,9 +522,9 @@ If we run that, it would output:
|
||||
$ python app.py
|
||||
|
||||
// Select only the hero data
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
// But still join with the team table
|
||||
FROM hero JOIN team ON team.id = hero.team_id
|
||||
FROM hero JOIN team ON team.id = hero.team_id
|
||||
// And filter with WHERE to get only the Preventers
|
||||
WHERE team.name = ?
|
||||
INFO Engine [no key 0.00066s] ('Preventers',)
|
||||
@@ -564,9 +564,9 @@ And if we run that, it will output:
|
||||
$ python app.py
|
||||
|
||||
// Select the hero and the team data
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id, team.id AS id_1, team.name AS name_1, team.headquarters
|
||||
// Join the hero with the team table
|
||||
FROM hero JOIN team ON team.id = hero.team_id
|
||||
FROM hero JOIN team ON team.id = hero.team_id
|
||||
// Filter with WHERE to get only Preventers
|
||||
WHERE team.name = ?
|
||||
INFO Engine [no key 0.00018s] ('Preventers',)
|
||||
|
||||
@@ -56,7 +56,7 @@ We can simply set the `team_id` to `None`, and now it doesn't have a connection
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/connect/delete/tutorial001.py[ln:31-32]!}
|
||||
|
||||
|
||||
# Previous code here omitted 👈
|
||||
|
||||
{!./docs_src/tutorial/connect/delete/tutorial001.py[ln:68-72]!}
|
||||
@@ -94,8 +94,8 @@ INFO Engine COMMIT
|
||||
// Automatically start a new transaction
|
||||
INFO Engine BEGIN (implicit)
|
||||
// Refresh the hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
WHERE hero.id = ?
|
||||
INFO Engine [cached since 0.1661s ago] (3,)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ Doing it is just like updating any other field:
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/tutorial/connect/update/tutorial001.py[ln:31-32]!}
|
||||
|
||||
|
||||
# Previous code here omitted 👈
|
||||
|
||||
{!./docs_src/tutorial/connect/update/tutorial001.py[ln:62-66]!}
|
||||
@@ -94,8 +94,8 @@ INFO Engine COMMIT
|
||||
// Automatically start a new transaction
|
||||
INFO Engine BEGIN (implicit)
|
||||
// Refresh the hero data
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
INFO Engine SELECT hero.id, hero.name, hero.secret_name, hero.age, hero.team_id
|
||||
FROM hero
|
||||
WHERE hero.id = ?
|
||||
INFO Engine [cached since 0.08837s ago] (3,)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user