| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d55af68 commit ee44f3b
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -307,8 +307,11 @@ | |||
| 307 | 307 | ||
| 308 | 308 | 33. Print the `hero_1`. | |
| 309 | 309 | ||
| 310 | - !!! info | ||
| 311 | - Even if the `hero_1` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 310 | + /// info | ||
| 311 | + | ||
| 312 | + Even if the `hero_1` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 313 | + | ||
| 314 | + /// | ||
| 312 | 315 | ||
| 313 | 316 | Because the `hero_1` is fresh it has all it's data available. | |
| 314 | 317 | ||
@@ -320,8 +323,11 @@ | |||
| 320 | 323 | ||
| 321 | 324 | 34. Print the `hero_2`. | |
| 322 | 325 | ||
| 323 | - !!! info | ||
| 324 | - Even if the `hero_2` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 326 | + /// info | ||
| 327 | + | ||
| 328 | + Even if the `hero_2` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 329 | + | ||
| 330 | + /// | ||
| 325 | 331 | ||
| 326 | 332 | Because the `hero_2` is fresh it has all it's data available. | |
| 327 | 333 | ||
@@ -333,8 +339,11 @@ | |||
| 333 | 339 | ||
| 334 | 340 | 35. Print the `hero_3`. | |
| 335 | 341 | ||
| 336 | - !!! info | ||
| 337 | - Even if the `hero_3` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 342 | + /// info | ||
| 343 | + | ||
| 344 | + Even if the `hero_3` wasn't fresh, this would **not** trigger a `refresh` making the **session** use the **engine** to fetch data from the database because it is not accessing an attribute. | ||
| 345 | + | ||
| 346 | + /// | ||
| 338 | 347 | ||
| 339 | 348 | Because the `hero_3` is fresh it has all it's data available. | |
| 340 | 349 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,10 +14,13 @@ | |||
| 14 | 14 | ||
| 15 | 15 | 3. Get one hero object, expecting exactly one. | |
| 16 | 16 | ||
| 17 | - !!! tip | ||
| 18 | - This ensures there's no more than one, and that there's exactly one, not `None`. | ||
| 17 | + /// tip | ||
| 19 | 18 | ||
| 20 | - This would never return `None`, instead it would raise an exception. | ||
| 19 | + This ensures there's no more than one, and that there's exactly one, not `None`. | ||
| 20 | + | ||
| 21 | + This would never return `None`, instead it would raise an exception. | ||
| 22 | + | ||
| 23 | + /// | ||
| 21 | 24 | ||
| 22 | 25 | 4. Print the hero object. | |
| 23 | 26 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,5 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | We tell it that with the `poolclass=StaticPool` parameter. | |
| 24 | 24 | ||
| 25 | - !!! info | ||
| 26 | - You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 25 | + /// info | ||
| 26 | + | ||
| 27 | + You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 28 | + | ||
| 29 | + /// | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,5 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | We tell it that with the `poolclass=StaticPool` parameter. | |
| 24 | 24 | ||
| 25 | - !!! info | ||
| 26 | - You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 25 | + /// info | ||
| 26 | + | ||
| 27 | + You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 28 | + | ||
| 29 | + /// | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,5 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | We tell it that with the `poolclass=StaticPool` parameter. | |
| 24 | 24 | ||
| 25 | - !!! info | ||
| 26 | - You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 25 | + /// info | ||
| 26 | + | ||
| 27 | + You can read more details in the <a href="https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#using-a-memory-database-in-multiple-threads" class="external-link" target="_blank">SQLAlchemy documentation about Using a Memory Database in Multiple Threads</a> | ||
| 28 | + | ||
| 29 | + /// | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,10 +16,13 @@ | |||
| 16 | 16 | ||
| 17 | 17 | 7. Create a new **session** to query data. | |
| 18 | 18 | ||
| 19 | - !!! tip | ||
| 20 | - Notice that this is a new **session** independent from the one in the other function above. | ||
| 19 | + /// tip | ||
| 21 | 20 | ||
| 22 | - But it still uses the same **engine**. We still have one engine for the whole application. | ||
| 21 | + Notice that this is a new **session** independent from the one in the other function above. | ||
| 22 | + | ||
| 23 | + But it still uses the same **engine**. We still have one engine for the whole application. | ||
| 24 | + | ||
| 25 | + /// | ||
| 23 | 26 | ||
| 24 | 27 | 8. Use the `select()` function to create a statement selecting all the `Hero` objects. | |
| 25 | 28 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,10 +13,13 @@ | |||
| 13 | 13 | ||
| 14 | 14 | 3. Get one hero object, expecting exactly one. | |
| 15 | 15 | ||
| 16 | - !!! tip | ||
| 17 | - This ensures there's no more than one, and that there's exactly one, not `None`. | ||
| 16 | + /// tip | ||
| 18 | 17 | ||
| 19 | - This would never return `None`, instead it would raise an exception. | ||
| 18 | + This ensures there's no more than one, and that there's exactly one, not `None`. | ||
| 19 | + | ||
| 20 | + This would never return `None`, instead it would raise an exception. | ||
| 21 | + | ||
| 22 | + /// | ||
| 20 | 23 | ||
| 21 | 24 | 4. Print the hero object. | |
| 22 | 25 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,12 +35,15 @@ | |||
| 35 | 35 | INFO Engine [no key 0.00020s] ('Captain North America',) | |
| 36 | 36 | ``` | |
| 37 | 37 | ||
| 38 | - !!! tip | ||
| 39 | - See the `BEGIN` at the top? | ||
| 38 | + /// tip | ||
| 40 | 39 | ||
| 41 | - This is SQLAlchemy automatically starting a transaction for us. | ||
| 40 | + See the `BEGIN` at the top? | ||
| 42 | 41 | ||
| 43 | - This way, we could revert the last changes (if there were some) if we wanted to, even if the SQL to create them was already sent to the database. | ||
| 42 | + This is SQLAlchemy automatically starting a transaction for us. | ||
| 43 | + | ||
| 44 | + This way, we could revert the last changes (if there were some) if we wanted to, even if the SQL to create them was already sent to the database. | ||
| 45 | + | ||
| 46 | + /// | ||
| 44 | 47 | ||
| 45 | 48 | 7. Get one hero object for this new query. | |
| 46 | 49 | ||
@@ -98,10 +101,13 @@ | |||
| 98 | 101 | INFO Engine COMMIT | |
| 99 | 102 | ``` | |
| 100 | 103 | ||
| 101 | - !!! tip | ||
| 102 | - See how SQLAlchemy (that powers SQLModel) optimizes the SQL to do as much work as possible in a single batch. | ||
| 104 | + /// tip | ||
| 105 | + | ||
| 106 | + See how SQLAlchemy (that powers SQLModel) optimizes the SQL to do as much work as possible in a single batch. | ||
| 107 | + | ||
| 108 | + Here it updates both heroes in a single SQL query. | ||
| 103 | 109 | ||
| 104 | - Here it updates both heroes in a single SQL query. | ||
| 110 | + /// | ||
| 105 | 111 | ||
| 106 | 112 | 16. Refresh the first hero. | |
| 107 | 113 | ||
@@ -115,8 +121,11 @@ | |||
| 115 | 121 | INFO Engine [generated in 0.00023s] (2,) | |
| 116 | 122 | ``` | |
| 117 | 123 | ||
| 118 | - !!! tip | ||
| 119 | - Because we just committed a SQL transaction with `COMMIT`, SQLAlchemy will automatically start a new transaction with `BEGIN`. | ||
| 124 | + /// tip | ||
| 125 | + | ||
| 126 | + Because we just committed a SQL transaction with `COMMIT`, SQLAlchemy will automatically start a new transaction with `BEGIN`. | ||
| 127 | + | ||
| 128 | + /// | ||
| 120 | 129 | ||
| 121 | 130 | 17. Refresh the second hero. | |
| 122 | 131 | ||
@@ -129,8 +138,11 @@ | |||
| 129 | 138 | INFO Engine [cached since 0.001709s ago] (7,) | |
| 130 | 139 | ``` | |
| 131 | 140 | ||
| 132 | - !!! tip | ||
| 133 | - SQLAlchemy is still using the previous transaction, so it doesn't have to create a new one. | ||
| 141 | + /// tip | ||
| 142 | + | ||
| 143 | + SQLAlchemy is still using the previous transaction, so it doesn't have to create a new one. | ||
| 144 | + | ||
| 145 | + /// | ||
| 134 | 146 | ||
| 135 | 147 | 18. Print the first hero, now updated. | |
| 136 | 148 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments