diff options
| author | Simeon Simeonov | 2023-09-17 01:22:00 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2023-09-17 01:22:00 +0200 |
| commit | 24d5938dfb98cc5c27eaec51b1da06b2f4a66932 (patch) | |
| tree | 46aee2ddca96cb25a22803a8e91d0aa3426cb5dc | |
| parent | 6dcd1727eb9d5dbfcb8f6e9599ada10d33063bac (diff) | |
Update notebooks/python/python_oo.ipynb and notebooks/sqlalchemy/sqlalchemy.ipynb
| -rw-r--r-- | notebooks/python/python_3_8_to_3_11.ipynb | 2 | ||||
| -rw-r--r-- | notebooks/python/python_intro.ipynb | 260 | ||||
| -rw-r--r-- | notebooks/python/python_oo.ipynb | 18 | ||||
| -rw-r--r-- | notebooks/sqlalchemy/sqlalchemy.ipynb | 700 |
4 files changed, 503 insertions, 477 deletions
diff --git a/notebooks/python/python_3_8_to_3_11.ipynb b/notebooks/python/python_3_8_to_3_11.ipynb index 1b0467c..e2a08e9 100644 --- a/notebooks/python/python_3_8_to_3_11.ipynb +++ b/notebooks/python/python_3_8_to_3_11.ipynb | |||
| @@ -834,7 +834,7 @@ | |||
| 834 | "name": "python", | 834 | "name": "python", |
| 835 | "nbconvert_exporter": "python", | 835 | "nbconvert_exporter": "python", |
| 836 | "pygments_lexer": "ipython3", | 836 | "pygments_lexer": "ipython3", |
| 837 | "version": "3.10.8" | 837 | "version": "3.11.4" |
| 838 | } | 838 | } |
| 839 | }, | 839 | }, |
| 840 | "nbformat": 4, | 840 | "nbformat": 4, |
diff --git a/notebooks/python/python_intro.ipynb b/notebooks/python/python_intro.ipynb index 0168839..171b83c 100644 --- a/notebooks/python/python_intro.ipynb +++ b/notebooks/python/python_intro.ipynb | |||
| @@ -62,7 +62,7 @@ | |||
| 62 | }, | 62 | }, |
| 63 | { | 63 | { |
| 64 | "cell_type": "code", | 64 | "cell_type": "code", |
| 65 | "execution_count": 50, | 65 | "execution_count": 12, |
| 66 | "id": "54c9e132-30b0-41bf-97e9-0e8b94f3d202", | 66 | "id": "54c9e132-30b0-41bf-97e9-0e8b94f3d202", |
| 67 | "metadata": {}, | 67 | "metadata": {}, |
| 68 | "outputs": [], | 68 | "outputs": [], |
| @@ -109,7 +109,7 @@ | |||
| 109 | }, | 109 | }, |
| 110 | { | 110 | { |
| 111 | "cell_type": "code", | 111 | "cell_type": "code", |
| 112 | "execution_count": 51, | 112 | "execution_count": 13, |
| 113 | "id": "bd6134d9-cc0e-4b45-b6b3-50210f6395e2", | 113 | "id": "bd6134d9-cc0e-4b45-b6b3-50210f6395e2", |
| 114 | "metadata": {}, | 114 | "metadata": {}, |
| 115 | "outputs": [], | 115 | "outputs": [], |
| @@ -140,7 +140,7 @@ | |||
| 140 | }, | 140 | }, |
| 141 | { | 141 | { |
| 142 | "cell_type": "code", | 142 | "cell_type": "code", |
| 143 | "execution_count": 52, | 143 | "execution_count": 14, |
| 144 | "id": "cd2b7f98-ea16-49e2-9d19-f37266bd4f3a", | 144 | "id": "cd2b7f98-ea16-49e2-9d19-f37266bd4f3a", |
| 145 | "metadata": {}, | 145 | "metadata": {}, |
| 146 | "outputs": [ | 146 | "outputs": [ |
| @@ -148,23 +148,7 @@ | |||
| 148 | "name": "stdout", | 148 | "name": "stdout", |
| 149 | "output_type": "stream", | 149 | "output_type": "stream", |
| 150 | "text": [ | 150 | "text": [ |
| 151 | "'can be written like this'\n" | 151 | "'can be written like this'\n", |
| 152 | ] | ||
| 153 | }, | ||
| 154 | { | ||
| 155 | "data": { | ||
| 156 | "text/plain": [ | ||
| 157 | "'foo bar'" | ||
| 158 | ] | ||
| 159 | }, | ||
| 160 | "execution_count": 52, | ||
| 161 | "metadata": {}, | ||
| 162 | "output_type": "execute_result" | ||
| 163 | }, | ||
| 164 | { | ||
| 165 | "name": "stdout", | ||
| 166 | "output_type": "stream", | ||
| 167 | "text": [ | ||
| 168 | "works just fine\n", | 152 | "works just fine\n", |
| 169 | "works\n", | 153 | "works\n", |
| 170 | "just\n", | 154 | "just\n", |
| @@ -174,110 +158,10 @@ | |||
| 174 | { | 158 | { |
| 175 | "data": { | 159 | "data": { |
| 176 | "text/plain": [ | 160 | "text/plain": [ |
| 177 | "'S'" | ||
| 178 | ] | ||
| 179 | }, | ||
| 180 | "execution_count": 52, | ||
| 181 | "metadata": {}, | ||
| 182 | "output_type": "execute_result" | ||
| 183 | }, | ||
| 184 | { | ||
| 185 | "data": { | ||
| 186 | "text/plain": [ | ||
| 187 | "'t'" | ||
| 188 | ] | ||
| 189 | }, | ||
| 190 | "execution_count": 52, | ||
| 191 | "metadata": {}, | ||
| 192 | "output_type": "execute_result" | ||
| 193 | }, | ||
| 194 | { | ||
| 195 | "data": { | ||
| 196 | "text/plain": [ | ||
| 197 | "'tatnett'" | ||
| 198 | ] | ||
| 199 | }, | ||
| 200 | "execution_count": 52, | ||
| 201 | "metadata": {}, | ||
| 202 | "output_type": "execute_result" | ||
| 203 | }, | ||
| 204 | { | ||
| 205 | "data": { | ||
| 206 | "text/plain": [ | ||
| 207 | "'tatnet'" | ||
| 208 | ] | ||
| 209 | }, | ||
| 210 | "execution_count": 52, | ||
| 211 | "metadata": {}, | ||
| 212 | "output_type": "execute_result" | ||
| 213 | }, | ||
| 214 | { | ||
| 215 | "data": { | ||
| 216 | "text/plain": [ | ||
| 217 | "'ett'" | ||
| 218 | ] | ||
| 219 | }, | ||
| 220 | "execution_count": 52, | ||
| 221 | "metadata": {}, | ||
| 222 | "output_type": "execute_result" | ||
| 223 | }, | ||
| 224 | { | ||
| 225 | "data": { | ||
| 226 | "text/plain": [ | ||
| 227 | "'tte'" | ||
| 228 | ] | ||
| 229 | }, | ||
| 230 | "execution_count": 52, | ||
| 231 | "metadata": {}, | ||
| 232 | "output_type": "execute_result" | ||
| 233 | }, | ||
| 234 | { | ||
| 235 | "data": { | ||
| 236 | "text/plain": [ | ||
| 237 | "True" | ||
| 238 | ] | ||
| 239 | }, | ||
| 240 | "execution_count": 52, | ||
| 241 | "metadata": {}, | ||
| 242 | "output_type": "execute_result" | ||
| 243 | }, | ||
| 244 | { | ||
| 245 | "data": { | ||
| 246 | "text/plain": [ | ||
| 247 | "False" | ||
| 248 | ] | ||
| 249 | }, | ||
| 250 | "execution_count": 52, | ||
| 251 | "metadata": {}, | ||
| 252 | "output_type": "execute_result" | ||
| 253 | }, | ||
| 254 | { | ||
| 255 | "data": { | ||
| 256 | "text/plain": [ | ||
| 257 | "True" | ||
| 258 | ] | ||
| 259 | }, | ||
| 260 | "execution_count": 52, | ||
| 261 | "metadata": {}, | ||
| 262 | "output_type": "execute_result" | ||
| 263 | }, | ||
| 264 | { | ||
| 265 | "data": { | ||
| 266 | "text/plain": [ | ||
| 267 | "b'B\\xc3\\x98!'" | ||
| 268 | ] | ||
| 269 | }, | ||
| 270 | "execution_count": 52, | ||
| 271 | "metadata": {}, | ||
| 272 | "output_type": "execute_result" | ||
| 273 | }, | ||
| 274 | { | ||
| 275 | "data": { | ||
| 276 | "text/plain": [ | ||
| 277 | "'BØ!'" | 161 | "'BØ!'" |
| 278 | ] | 162 | ] |
| 279 | }, | 163 | }, |
| 280 | "execution_count": 52, | 164 | "execution_count": 14, |
| 281 | "metadata": {}, | 165 | "metadata": {}, |
| 282 | "output_type": "execute_result" | 166 | "output_type": "execute_result" |
| 283 | } | 167 | } |
| @@ -520,87 +404,17 @@ | |||
| 520 | }, | 404 | }, |
| 521 | { | 405 | { |
| 522 | "cell_type": "code", | 406 | "cell_type": "code", |
| 523 | "execution_count": 53, | 407 | "execution_count": 15, |
| 524 | "id": "f4a4ea99-4038-4b61-9b8d-9ce623e6a663", | 408 | "id": "f4a4ea99-4038-4b61-9b8d-9ce623e6a663", |
| 525 | "metadata": {}, | 409 | "metadata": {}, |
| 526 | "outputs": [ | 410 | "outputs": [ |
| 527 | { | 411 | { |
| 528 | "data": { | 412 | "data": { |
| 529 | "text/plain": [ | 413 | "text/plain": [ |
| 530 | "35082617072" | 414 | "-42990858669078524" |
| 531 | ] | ||
| 532 | }, | ||
| 533 | "execution_count": 53, | ||
| 534 | "metadata": {}, | ||
| 535 | "output_type": "execute_result" | ||
| 536 | }, | ||
| 537 | { | ||
| 538 | "data": { | ||
| 539 | "text/plain": [ | ||
| 540 | "35082617104" | ||
| 541 | ] | 415 | ] |
| 542 | }, | 416 | }, |
| 543 | "execution_count": 53, | 417 | "execution_count": 15, |
| 544 | "metadata": {}, | ||
| 545 | "output_type": "execute_result" | ||
| 546 | }, | ||
| 547 | { | ||
| 548 | "data": { | ||
| 549 | "text/plain": [ | ||
| 550 | "'H'" | ||
| 551 | ] | ||
| 552 | }, | ||
| 553 | "execution_count": 53, | ||
| 554 | "metadata": {}, | ||
| 555 | "output_type": "execute_result" | ||
| 556 | }, | ||
| 557 | { | ||
| 558 | "data": { | ||
| 559 | "text/plain": [ | ||
| 560 | "-6333845781340707986" | ||
| 561 | ] | ||
| 562 | }, | ||
| 563 | "execution_count": 53, | ||
| 564 | "metadata": {}, | ||
| 565 | "output_type": "execute_result" | ||
| 566 | }, | ||
| 567 | { | ||
| 568 | "data": { | ||
| 569 | "text/plain": [ | ||
| 570 | "36350585520" | ||
| 571 | ] | ||
| 572 | }, | ||
| 573 | "execution_count": 53, | ||
| 574 | "metadata": {}, | ||
| 575 | "output_type": "execute_result" | ||
| 576 | }, | ||
| 577 | { | ||
| 578 | "data": { | ||
| 579 | "text/plain": [ | ||
| 580 | "36350587520" | ||
| 581 | ] | ||
| 582 | }, | ||
| 583 | "execution_count": 53, | ||
| 584 | "metadata": {}, | ||
| 585 | "output_type": "execute_result" | ||
| 586 | }, | ||
| 587 | { | ||
| 588 | "data": { | ||
| 589 | "text/plain": [ | ||
| 590 | "8927089887582119463" | ||
| 591 | ] | ||
| 592 | }, | ||
| 593 | "execution_count": 53, | ||
| 594 | "metadata": {}, | ||
| 595 | "output_type": "execute_result" | ||
| 596 | }, | ||
| 597 | { | ||
| 598 | "data": { | ||
| 599 | "text/plain": [ | ||
| 600 | "8927089887582119463" | ||
| 601 | ] | ||
| 602 | }, | ||
| 603 | "execution_count": 53, | ||
| 604 | "metadata": {}, | 418 | "metadata": {}, |
| 605 | "output_type": "execute_result" | 419 | "output_type": "execute_result" |
| 606 | } | 420 | } |
| @@ -703,41 +517,15 @@ | |||
| 703 | }, | 517 | }, |
| 704 | { | 518 | { |
| 705 | "cell_type": "code", | 519 | "cell_type": "code", |
| 706 | "execution_count": 54, | 520 | "execution_count": 16, |
| 707 | "id": "bf95f44a-1257-440f-b35f-a8536c8c4363", | 521 | "id": "bf95f44a-1257-440f-b35f-a8536c8c4363", |
| 708 | "metadata": {}, | 522 | "metadata": {}, |
| 709 | "outputs": [ | 523 | "outputs": [ |
| 710 | { | 524 | { |
| 711 | "data": { | ||
| 712 | "text/plain": [ | ||
| 713 | "7" | ||
| 714 | ] | ||
| 715 | }, | ||
| 716 | "execution_count": 54, | ||
| 717 | "metadata": {}, | ||
| 718 | "output_type": "execute_result" | ||
| 719 | }, | ||
| 720 | { | ||
| 721 | "name": "stdout", | ||
| 722 | "output_type": "stream", | ||
| 723 | "text": [ | ||
| 724 | "9\n" | ||
| 725 | ] | ||
| 726 | }, | ||
| 727 | { | ||
| 728 | "data": { | ||
| 729 | "text/plain": [ | ||
| 730 | "[9, -2]" | ||
| 731 | ] | ||
| 732 | }, | ||
| 733 | "execution_count": 54, | ||
| 734 | "metadata": {}, | ||
| 735 | "output_type": "execute_result" | ||
| 736 | }, | ||
| 737 | { | ||
| 738 | "name": "stdout", | 525 | "name": "stdout", |
| 739 | "output_type": "stream", | 526 | "output_type": "stream", |
| 740 | "text": [ | 527 | "text": [ |
| 528 | "9\n", | ||
| 741 | "[9, 5]\n" | 529 | "[9, 5]\n" |
| 742 | ] | 530 | ] |
| 743 | } | 531 | } |
| @@ -785,7 +573,7 @@ | |||
| 785 | }, | 573 | }, |
| 786 | { | 574 | { |
| 787 | "cell_type": "code", | 575 | "cell_type": "code", |
| 788 | "execution_count": 55, | 576 | "execution_count": 17, |
| 789 | "id": "ecd03ee2-3523-40bd-afd1-4263a777bae0", | 577 | "id": "ecd03ee2-3523-40bd-afd1-4263a777bae0", |
| 790 | "metadata": {}, | 578 | "metadata": {}, |
| 791 | "outputs": [], | 579 | "outputs": [], |
| @@ -837,7 +625,7 @@ | |||
| 837 | }, | 625 | }, |
| 838 | { | 626 | { |
| 839 | "cell_type": "code", | 627 | "cell_type": "code", |
| 840 | "execution_count": 56, | 628 | "execution_count": 18, |
| 841 | "id": "c67ca162-e8eb-4b4d-8c3c-246b000c5c13", | 629 | "id": "c67ca162-e8eb-4b4d-8c3c-246b000c5c13", |
| 842 | "metadata": {}, | 630 | "metadata": {}, |
| 843 | "outputs": [ | 631 | "outputs": [ |
| @@ -955,7 +743,7 @@ | |||
| 955 | }, | 743 | }, |
| 956 | { | 744 | { |
| 957 | "cell_type": "code", | 745 | "cell_type": "code", |
| 958 | "execution_count": 57, | 746 | "execution_count": 19, |
| 959 | "id": "edf9cfa7-d76c-428b-a39f-8c0697789031", | 747 | "id": "edf9cfa7-d76c-428b-a39f-8c0697789031", |
| 960 | "metadata": {}, | 748 | "metadata": {}, |
| 961 | "outputs": [], | 749 | "outputs": [], |
| @@ -1005,7 +793,7 @@ | |||
| 1005 | }, | 793 | }, |
| 1006 | { | 794 | { |
| 1007 | "cell_type": "code", | 795 | "cell_type": "code", |
| 1008 | "execution_count": 58, | 796 | "execution_count": 20, |
| 1009 | "id": "ea583c17-c938-495a-9586-2027c66328a2", | 797 | "id": "ea583c17-c938-495a-9586-2027c66328a2", |
| 1010 | "metadata": {}, | 798 | "metadata": {}, |
| 1011 | "outputs": [ | 799 | "outputs": [ |
| @@ -1064,7 +852,7 @@ | |||
| 1064 | }, | 852 | }, |
| 1065 | { | 853 | { |
| 1066 | "cell_type": "code", | 854 | "cell_type": "code", |
| 1067 | "execution_count": 59, | 855 | "execution_count": 21, |
| 1068 | "id": "49d7f6e1-1f54-4b96-8203-5eae95f47ebe", | 856 | "id": "49d7f6e1-1f54-4b96-8203-5eae95f47ebe", |
| 1069 | "metadata": {}, | 857 | "metadata": {}, |
| 1070 | "outputs": [ | 858 | "outputs": [ |
| @@ -1167,10 +955,22 @@ | |||
| 1167 | }, | 955 | }, |
| 1168 | { | 956 | { |
| 1169 | "cell_type": "code", | 957 | "cell_type": "code", |
| 1170 | "execution_count": 60, | 958 | "execution_count": 22, |
| 1171 | "id": "4346260d-76af-437e-9c10-1c1d0c478695", | 959 | "id": "4346260d-76af-437e-9c10-1c1d0c478695", |
| 1172 | "metadata": {}, | 960 | "metadata": {}, |
| 1173 | "outputs": [], | 961 | "outputs": [ |
| 962 | { | ||
| 963 | "ename": "NameError", | ||
| 964 | "evalue": "name 'is_admin' is not defined", | ||
| 965 | "output_type": "error", | ||
| 966 | "traceback": [ | ||
| 967 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
| 968 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | ||
| 969 | "Cell \u001b[0;32mIn[22], line 25\u001b[0m\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m decorated\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m api_access_decorator\n\u001b[1;32m 24\u001b[0m \u001b[38;5;129m@requires_access\u001b[39m(access_secret\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mb28cfeaa65b73cf\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m---> 25\u001b[0m \u001b[38;5;129m@is_admin\u001b[39m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msensitive_function\u001b[39m(data, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 27\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"very sensitive function\"\"\"\u001b[39;00m\n\u001b[1;32m 28\u001b[0m db\u001b[38;5;241m.\u001b[39msave(data)\n", | ||
| 970 | "\u001b[0;31mNameError\u001b[0m: name 'is_admin' is not defined" | ||
| 971 | ] | ||
| 972 | } | ||
| 973 | ], | ||
| 1174 | "source": [ | 974 | "source": [ |
| 1175 | "# Decorators (cont ...) - a complete example\n", | 975 | "# Decorators (cont ...) - a complete example\n", |
| 1176 | "\n", | 976 | "\n", |
| @@ -1253,7 +1053,7 @@ | |||
| 1253 | "name": "python", | 1053 | "name": "python", |
| 1254 | "nbconvert_exporter": "python", | 1054 | "nbconvert_exporter": "python", |
| 1255 | "pygments_lexer": "ipython3", | 1055 | "pygments_lexer": "ipython3", |
| 1256 | "version": "3.11.1" | 1056 | "version": "3.11.5" |
| 1257 | } | 1057 | } |
| 1258 | }, | 1058 | }, |
| 1259 | "nbformat": 4, | 1059 | "nbformat": 4, |
diff --git a/notebooks/python/python_oo.ipynb b/notebooks/python/python_oo.ipynb index 1c655d0..0ab369b 100644 --- a/notebooks/python/python_oo.ipynb +++ b/notebooks/python/python_oo.ipynb | |||
| @@ -226,17 +226,17 @@ | |||
| 226 | "name": "stdout", | 226 | "name": "stdout", |
| 227 | "output_type": "stream", | 227 | "output_type": "stream", |
| 228 | "text": [ | 228 | "text": [ |
| 229 | "car1.get_obj_info_str() = \"I am <__main__.Car object at 0x7fc7add96f10> with id 140495591927568 from <class '__main__.Car'> with id 94628241379728\"\n", | 229 | "car1.get_obj_info_str() = \"I am <__main__.Car object at 0x7f70e643d590> with id 140122876269968 from <class '__main__.Car'> with id 93964809433504\"\n", |
| 230 | "car2.get_obj_info_str() = \"I am <__main__.Car object at 0x7fc7aef459d0> with id 140495610468816 from <class '__main__.Car'> with id 94628241379728\"\n", | 230 | "car2.get_obj_info_str() = \"I am <__main__.Car object at 0x7f70e63ddf10> with id 140122875879184 from <class '__main__.Car'> with id 93964809433504\"\n", |
| 231 | "car1.model = 'BMW', car1.reg_nr = 'EC76183', car1.extras = ['GPSnav', 'Sound system'], id(car1.cls_extras) = 140495591909184, id(car1.get_obj_info_str) = 140495591927808\n", | 231 | "car1.model = 'BMW', car1.reg_nr = 'EC76183', car1.extras = ['GPSnav', 'Sound system'], id(car1.cls_extras) = 140122875882432, id(car1.get_obj_info_str) = 140122875878080\n", |
| 232 | "car2.model = 'Scoda', car2.reg_nr = 'BD77655', car2.extras = ['GPSnav'], id(car2.cls_extras) = 140495591909184, id(car2.get_obj_info_str) = 140495591927936\n", | 232 | "car2.model = 'Scoda', car2.reg_nr = 'BD77655', car2.extras = ['GPSnav'], id(car2.cls_extras) = 140122875882432, id(car2.get_obj_info_str) = 140122875880192\n", |
| 233 | "id(Car.cls_extras) = 140495591909184, id(Car.get_obj_info_str) = 140495591682944\n", | 233 | "id(Car.cls_extras) = 140122875882432, id(Car.get_obj_info_str) = 140122875964416\n", |
| 234 | "car1.cls_extras = ['GPSnav', 'Sound system'], id(car1.cls_extras) = 140495591909184\n", | 234 | "car1.cls_extras = ['GPSnav', 'Sound system'], id(car1.cls_extras) = 140122875882432\n", |
| 235 | "car2.cls_extras = ['GPSnav', 'Sound system'], id(car2.cls_extras) = 140495591909184\n", | 235 | "car2.cls_extras = ['GPSnav', 'Sound system'], id(car2.cls_extras) = 140122875882432\n", |
| 236 | "True\n", | 236 | "True\n", |
| 237 | "hasattr(car1, 'import_tax_paid') = True\n", | 237 | "hasattr(car1, 'import_tax_paid') = True\n", |
| 238 | "hasattr(car2, 'import_tax_paid') = False\n", | 238 | "hasattr(car2, 'import_tax_paid') = False\n", |
| 239 | "id(car1.__class__) = 94628241379728, id(car2.__class__) = 94628241379728, id(Car) = 94628241379728\n" | 239 | "id(car1.__class__) = 93964809433504, id(car2.__class__) = 93964809433504, id(Car) = 93964809433504\n" |
| 240 | ] | 240 | ] |
| 241 | } | 241 | } |
| 242 | ], | 242 | ], |
| @@ -1418,7 +1418,7 @@ | |||
| 1418 | "name": "python", | 1418 | "name": "python", |
| 1419 | "nbconvert_exporter": "python", | 1419 | "nbconvert_exporter": "python", |
| 1420 | "pygments_lexer": "ipython3", | 1420 | "pygments_lexer": "ipython3", |
| 1421 | "version": "3.11.1" | 1421 | "version": "3.11.3" |
| 1422 | } | 1422 | } |
| 1423 | }, | 1423 | }, |
| 1424 | "nbformat": 4, | 1424 | "nbformat": 4, |
diff --git a/notebooks/sqlalchemy/sqlalchemy.ipynb b/notebooks/sqlalchemy/sqlalchemy.ipynb index 92b2d56..58a7eb9 100644 --- a/notebooks/sqlalchemy/sqlalchemy.ipynb +++ b/notebooks/sqlalchemy/sqlalchemy.ipynb | |||
| @@ -19,7 +19,9 @@ | |||
| 19 | "\n", | 19 | "\n", |
| 20 | "- Design & overview\n", | 20 | "- Design & overview\n", |
| 21 | "\n", | 21 | "\n", |
| 22 | "- A small practical example\n" | 22 | "- A small practical example\n", |
| 23 | "\n", | ||
| 24 | "- General principles and best practices" | ||
| 23 | ] | 25 | ] |
| 24 | }, | 26 | }, |
| 25 | { | 27 | { |
| @@ -90,7 +92,7 @@ | |||
| 90 | }, | 92 | }, |
| 91 | { | 93 | { |
| 92 | "cell_type": "code", | 94 | "cell_type": "code", |
| 93 | "execution_count": 11, | 95 | "execution_count": 50, |
| 94 | "id": "d1ea9f51-e3de-45a8-8302-b4a89b5d1689", | 96 | "id": "d1ea9f51-e3de-45a8-8302-b4a89b5d1689", |
| 95 | "metadata": { | 97 | "metadata": { |
| 96 | "slideshow": { | 98 | "slideshow": { |
| @@ -114,7 +116,7 @@ | |||
| 114 | }, | 116 | }, |
| 115 | { | 117 | { |
| 116 | "cell_type": "code", | 118 | "cell_type": "code", |
| 117 | "execution_count": 12, | 119 | "execution_count": 51, |
| 118 | "id": "3b4a777d-7d38-4149-8ab2-c876e2533766", | 120 | "id": "3b4a777d-7d38-4149-8ab2-c876e2533766", |
| 119 | "metadata": { | 121 | "metadata": { |
| 120 | "slideshow": { | 122 | "slideshow": { |
| @@ -126,20 +128,20 @@ | |||
| 126 | "name": "stdout", | 128 | "name": "stdout", |
| 127 | "output_type": "stream", | 129 | "output_type": "stream", |
| 128 | "text": [ | 130 | "text": [ |
| 129 | "2022-09-21 09:05:41,263 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | 131 | "2023-09-08 09:45:43,380 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 130 | "2022-09-21 09:05:41,264 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_types\")\n", | 132 | "2023-09-08 09:45:43,380 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_types\")\n", |
| 131 | "2022-09-21 09:05:41,265 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 133 | "2023-09-08 09:45:43,380 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 132 | "2022-09-21 09:05:41,267 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"production_types\")\n", | 134 | "2023-09-08 09:45:43,380 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"production_types\")\n", |
| 133 | "2022-09-21 09:05:41,267 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 135 | "2023-09-08 09:45:43,380 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 134 | "2022-09-21 09:05:41,269 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"bidding_areas\")\n", | 136 | "2023-09-08 09:45:43,381 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"bidding_areas\")\n", |
| 135 | "2022-09-21 09:05:41,269 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 137 | "2023-09-08 09:45:43,381 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 136 | "2022-09-21 09:05:41,270 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"bidding_areas\")\n", | 138 | "2023-09-08 09:45:43,381 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"bidding_areas\")\n", |
| 137 | "2022-09-21 09:05:41,271 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 139 | "2023-09-08 09:45:43,381 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 138 | "2022-09-21 09:05:41,272 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", | 140 | "2023-09-08 09:45:43,381 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", |
| 139 | "2022-09-21 09:05:41,272 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 141 | "2023-09-08 09:45:43,382 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 140 | "2022-09-21 09:05:41,274 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"production_plans\")\n", | 142 | "2023-09-08 09:45:43,382 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info(\"production_plans\")\n", |
| 141 | "2022-09-21 09:05:41,274 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 143 | "2023-09-08 09:45:43,382 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 142 | "2022-09-21 09:05:41,275 INFO sqlalchemy.engine.Engine \n", | 144 | "2023-09-08 09:45:43,382 INFO sqlalchemy.engine.Engine \n", |
| 143 | "CREATE TABLE production_types (\n", | 145 | "CREATE TABLE production_types (\n", |
| 144 | "\tproduction_type_id INTEGER NOT NULL, \n", | 146 | "\tproduction_type_id INTEGER NOT NULL, \n", |
| 145 | "\tcode VARCHAR(3) NOT NULL, \n", | 147 | "\tcode VARCHAR(3) NOT NULL, \n", |
| @@ -149,8 +151,8 @@ | |||
| 149 | ")\n", | 151 | ")\n", |
| 150 | "\n", | 152 | "\n", |
| 151 | "\n", | 153 | "\n", |
| 152 | "2022-09-21 09:05:41,276 INFO sqlalchemy.engine.Engine [no key 0.00063s] ()\n", | 154 | "2023-09-08 09:45:43,382 INFO sqlalchemy.engine.Engine [no key 0.00011s] ()\n", |
| 153 | "2022-09-21 09:05:41,278 INFO sqlalchemy.engine.Engine \n", | 155 | "2023-09-08 09:45:43,383 INFO sqlalchemy.engine.Engine \n", |
| 154 | "CREATE TABLE bidding_areas (\n", | 156 | "CREATE TABLE bidding_areas (\n", |
| 155 | "\tbidding_area_id INTEGER NOT NULL, \n", | 157 | "\tbidding_area_id INTEGER NOT NULL, \n", |
| 156 | "\tcode VARCHAR(3) NOT NULL, \n", | 158 | "\tcode VARCHAR(3) NOT NULL, \n", |
| @@ -160,8 +162,8 @@ | |||
| 160 | ")\n", | 162 | ")\n", |
| 161 | "\n", | 163 | "\n", |
| 162 | "\n", | 164 | "\n", |
| 163 | "2022-09-21 09:05:41,278 INFO sqlalchemy.engine.Engine [no key 0.00059s] ()\n", | 165 | "2023-09-08 09:45:43,383 INFO sqlalchemy.engine.Engine [no key 0.00011s] ()\n", |
| 164 | "2022-09-21 09:05:41,280 INFO sqlalchemy.engine.Engine \n", | 166 | "2023-09-08 09:45:43,383 INFO sqlalchemy.engine.Engine \n", |
| 165 | "CREATE TABLE production_plans (\n", | 167 | "CREATE TABLE production_plans (\n", |
| 166 | "\trecord_created_time DATETIME NOT NULL, \n", | 168 | "\trecord_created_time DATETIME NOT NULL, \n", |
| 167 | "\tstart_time DATETIME NOT NULL, \n", | 169 | "\tstart_time DATETIME NOT NULL, \n", |
| @@ -174,25 +176,25 @@ | |||
| 174 | ")\n", | 176 | ")\n", |
| 175 | "\n", | 177 | "\n", |
| 176 | "\n", | 178 | "\n", |
| 177 | "2022-09-21 09:05:41,280 INFO sqlalchemy.engine.Engine [no key 0.00050s] ()\n", | 179 | "2023-09-08 09:45:43,383 INFO sqlalchemy.engine.Engine [no key 0.00011s] ()\n", |
| 178 | "2022-09-21 09:05:41,281 INFO sqlalchemy.engine.Engine COMMIT\n" | 180 | "2023-09-08 09:45:43,383 INFO sqlalchemy.engine.Engine COMMIT\n" |
| 179 | ] | 181 | ] |
| 180 | } | 182 | } |
| 181 | ], | 183 | ], |
| 182 | "source": [ | 184 | "source": [ |
| 183 | "from sqlalchemy import Column, Table\n", | ||
| 184 | "from sqlalchemy import DateTime, ForeignKey, Integer, Numeric, String\n", | 185 | "from sqlalchemy import DateTime, ForeignKey, Integer, Numeric, String\n", |
| 185 | "from sqlalchemy.orm import declarative_base, relationship\n", | 186 | "from sqlalchemy.orm import DeclarativeBase, mapped_column, relationship\n", |
| 186 | "\n", | 187 | "\n", |
| 187 | "Base = declarative_base()\n", | 188 | "class Base(DeclarativeBase):\n", |
| 189 | " pass\n", | ||
| 188 | "\n", | 190 | "\n", |
| 189 | "\n", | 191 | "\n", |
| 190 | "class ProductionType(Base):\n", | 192 | "class ProductionType(Base):\n", |
| 191 | " __tablename__ = \"production_types\"\n", | 193 | " __tablename__ = \"production_types\"\n", |
| 192 | "\n", | 194 | "\n", |
| 193 | " production_type_id = Column(Integer, primary_key=True)\n", | 195 | " production_type_id = mapped_column(Integer, primary_key=True)\n", |
| 194 | " code = Column(String(3), nullable=False, unique=True)\n", | 196 | " code = mapped_column(String(3), nullable=False, unique=True)\n", |
| 195 | " description = Column(String)\n", | 197 | " description = mapped_column(String)\n", |
| 196 | "\n", | 198 | "\n", |
| 197 | " production_plans = relationship(\n", | 199 | " production_plans = relationship(\n", |
| 198 | " \"ProductionPlan\", back_populates=\"production_type\", lazy=\"dynamic\"\n", | 200 | " \"ProductionPlan\", back_populates=\"production_type\", lazy=\"dynamic\"\n", |
| @@ -215,9 +217,9 @@ | |||
| 215 | "class BiddingArea(Base):\n", | 217 | "class BiddingArea(Base):\n", |
| 216 | " __tablename__ = \"bidding_areas\"\n", | 218 | " __tablename__ = \"bidding_areas\"\n", |
| 217 | "\n", | 219 | "\n", |
| 218 | " bidding_area_id = Column(Integer, primary_key=True)\n", | 220 | " bidding_area_id = mapped_column(Integer, primary_key=True)\n", |
| 219 | " code = Column(String(3), nullable=False, unique=True)\n", | 221 | " code = mapped_column(String(3), nullable=False, unique=True)\n", |
| 220 | " name = Column(String(32))\n", | 222 | " name = mapped_column(String(32))\n", |
| 221 | "\n", | 223 | "\n", |
| 222 | " production_plans = relationship(\n", | 224 | " production_plans = relationship(\n", |
| 223 | " \"ProductionPlan\", back_populates=\"bidding_area\", lazy=\"dynamic\"\n", | 225 | " \"ProductionPlan\", back_populates=\"bidding_area\", lazy=\"dynamic\"\n", |
| @@ -240,11 +242,11 @@ | |||
| 240 | "class ProductionPlan(Base):\n", | 242 | "class ProductionPlan(Base):\n", |
| 241 | " __tablename__ = \"production_plans\"\n", | 243 | " __tablename__ = \"production_plans\"\n", |
| 242 | "\n", | 244 | "\n", |
| 243 | " record_created_time = Column(DateTime(timezone=False), primary_key=True)\n", | 245 | " record_created_time = mapped_column(DateTime(timezone=False), primary_key=True)\n", |
| 244 | " start_time = Column(DateTime(timezone=False), primary_key=True)\n", | 246 | " start_time = mapped_column(DateTime(timezone=False), primary_key=True)\n", |
| 245 | " bidding_area_id = Column(Integer, ForeignKey(\"bidding_areas.bidding_area_id\"), primary_key=True)\n", | 247 | " bidding_area_id = mapped_column(Integer, ForeignKey(\"bidding_areas.bidding_area_id\"), primary_key=True)\n", |
| 246 | " production_type_id = Column(Integer, ForeignKey(\"production_types.production_type_id\"), primary_key=True)\n", | 248 | " production_type_id = mapped_column(Integer, ForeignKey(\"production_types.production_type_id\"), primary_key=True)\n", |
| 247 | " value = Column(Numeric, nullable=False)\n", | 249 | " value = mapped_column(Numeric, nullable=False)\n", |
| 248 | "\n", | 250 | "\n", |
| 249 | " # defining relationships.\n", | 251 | " # defining relationships.\n", |
| 250 | " # the defined attributes will reference 'ProductionType' and 'BiddingArea' objects\n", | 252 | " # the defined attributes will reference 'ProductionType' and 'BiddingArea' objects\n", |
| @@ -293,7 +295,7 @@ | |||
| 293 | }, | 295 | }, |
| 294 | { | 296 | { |
| 295 | "cell_type": "code", | 297 | "cell_type": "code", |
| 296 | "execution_count": 13, | 298 | "execution_count": 52, |
| 297 | "id": "70b0c5fa-35ae-44b5-b57b-2fa21b4f7da5", | 299 | "id": "70b0c5fa-35ae-44b5-b57b-2fa21b4f7da5", |
| 298 | "metadata": {}, | 300 | "metadata": {}, |
| 299 | "outputs": [ | 301 | "outputs": [ |
| @@ -301,76 +303,90 @@ | |||
| 301 | "name": "stdout", | 303 | "name": "stdout", |
| 302 | "output_type": "stream", | 304 | "output_type": "stream", |
| 303 | "text": [ | 305 | "text": [ |
| 304 | "2022-09-21 09:05:41,292 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_types\")\n", | 306 | "2023-09-08 09:45:43,387 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 305 | "2022-09-21 09:05:41,293 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 307 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_types\")\n", |
| 306 | "2022-09-21 09:05:41,294 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 308 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 307 | "2022-09-21 09:05:41,295 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 309 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 308 | "2022-09-21 09:05:41,296 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_types\")\n", | 310 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", |
| 309 | "2022-09-21 09:05:41,297 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 311 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_types\")\n", |
| 310 | "2022-09-21 09:05:41,298 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"production_types\")\n", | 312 | "2023-09-08 09:45:43,388 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 311 | "2022-09-21 09:05:41,298 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 313 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"production_types\")\n", |
| 312 | "2022-09-21 09:05:41,299 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 314 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 313 | "2022-09-21 09:05:41,300 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 315 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 314 | "2022-09-21 09:05:41,301 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | 316 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", |
| 315 | "2022-09-21 09:05:41,302 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 317 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", |
| 316 | "2022-09-21 09:05:41,303 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | 318 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 317 | "2022-09-21 09:05:41,303 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 319 | "2023-09-08 09:45:43,389 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_types\")\n", |
| 318 | "2022-09-21 09:05:41,304 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_types_1\")\n", | 320 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 319 | "2022-09-21 09:05:41,305 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 321 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", |
| 320 | "2022-09-21 09:05:41,306 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 322 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 321 | "2022-09-21 09:05:41,307 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 323 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_types_1\")\n", |
| 322 | "2022-09-21 09:05:41,309 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"bidding_areas\")\n", | 324 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 323 | "2022-09-21 09:05:41,310 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 325 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 324 | "2022-09-21 09:05:41,311 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 326 | "2023-09-08 09:45:43,390 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", |
| 325 | "2022-09-21 09:05:41,311 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 327 | "2023-09-08 09:45:43,391 INFO sqlalchemy.engine.Engine ROLLBACK\n", |
| 326 | "2022-09-21 09:05:41,313 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"bidding_areas\")\n", | 328 | "2023-09-08 09:45:43,391 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 327 | "2022-09-21 09:05:41,313 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 329 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"bidding_areas\")\n", |
| 328 | "2022-09-21 09:05:41,314 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"bidding_areas\")\n", | 330 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 329 | "2022-09-21 09:05:41,315 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 331 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 330 | "2022-09-21 09:05:41,316 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 332 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 331 | "2022-09-21 09:05:41,316 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 333 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"bidding_areas\")\n", |
| 332 | "2022-09-21 09:05:41,318 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | 334 | "2023-09-08 09:45:43,392 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 333 | "2022-09-21 09:05:41,318 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 335 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"bidding_areas\")\n", |
| 334 | "2022-09-21 09:05:41,319 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | 336 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 335 | "2022-09-21 09:05:41,320 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 337 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 336 | "2022-09-21 09:05:41,321 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_bidding_areas_1\")\n", | 338 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 337 | "2022-09-21 09:05:41,322 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 339 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", |
| 338 | "2022-09-21 09:05:41,323 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 340 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 339 | "2022-09-21 09:05:41,323 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 341 | "2023-09-08 09:45:43,393 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"bidding_areas\")\n", |
| 340 | "2022-09-21 09:05:41,326 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_plans\")\n", | 342 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 341 | "2022-09-21 09:05:41,327 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 343 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", |
| 342 | "2022-09-21 09:05:41,328 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 344 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 343 | "2022-09-21 09:05:41,329 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | 345 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_bidding_areas_1\")\n", |
| 344 | "2022-09-21 09:05:41,330 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_plans\")\n", | 346 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 345 | "2022-09-21 09:05:41,331 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 347 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 346 | "2022-09-21 09:05:41,331 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 348 | "2023-09-08 09:45:43,394 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 347 | "2022-09-21 09:05:41,332 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | 349 | "2023-09-08 09:45:43,395 INFO sqlalchemy.engine.Engine ROLLBACK\n", |
| 348 | "2022-09-21 09:05:41,334 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | 350 | "2023-09-08 09:45:43,395 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 349 | "2022-09-21 09:05:41,334 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 351 | "2023-09-08 09:45:43,395 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_plans\")\n", |
| 350 | "2022-09-21 09:05:41,336 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | 352 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 351 | "2022-09-21 09:05:41,336 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 353 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 352 | "2022-09-21 09:05:41,337 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_plans_1\")\n", | 354 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", |
| 353 | "2022-09-21 09:05:41,338 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 355 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_plans\")\n", |
| 354 | "2022-09-21 09:05:41,339 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 356 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 355 | "2022-09-21 09:05:41,340 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n" | 357 | "2023-09-08 09:45:43,396 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 358 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | ||
| 359 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | ||
| 360 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 361 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", | ||
| 362 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 363 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | ||
| 364 | "2023-09-08 09:45:43,397 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 365 | "2023-09-08 09:45:43,398 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_plans_1\")\n", | ||
| 366 | "2023-09-08 09:45:43,398 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 367 | "2023-09-08 09:45:43,398 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 368 | "2023-09-08 09:45:43,398 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | ||
| 369 | "2023-09-08 09:45:43,399 INFO sqlalchemy.engine.Engine ROLLBACK\n" | ||
| 356 | ] | 370 | ] |
| 357 | } | 371 | } |
| 358 | ], | 372 | ], |
| 359 | "source": [ | 373 | "source": [ |
| 360 | "## N.B. This example does NOT represent SQLAlchemy - best practice\n", | 374 | "## N.B. This example does NOT represent SQLAlchemy - best practice\n", |
| 361 | "from sqlalchemy.ext.declarative import declarative_base\n", | 375 | "from sqlalchemy import Table, Column\n", |
| 376 | "from sqlalchemy.orm import DeclarativeBase, mapped_column, Mapped\n", | ||
| 377 | "\n", | ||
| 362 | "\n", | 378 | "\n", |
| 363 | "Base = declarative_base()\n", | 379 | "class Base(DeclarativeBase):\n", |
| 364 | "Base.metadata.bind = engine\n", | 380 | " pass\n", |
| 365 | "\n", | 381 | "\n", |
| 366 | "\n", | 382 | "\n", |
| 367 | "class ProductionType(Base):\n", | 383 | "class ProductionType(Base):\n", |
| 368 | " __tablename__ = \"production_types\"\n", | 384 | " __tablename__ = \"production_types\"\n", |
| 369 | " __table_args__ = {\"autoload\": True}\n", | 385 | " __table_args__ = {\"autoload_with\": engine}\n", |
| 370 | "\n", | 386 | " # __table__ = Table(\"production_types\", Base.metadata, Column(\"description\", String(32)), autoload_with=engine)\n", |
| 371 | " # override the existing 'description'...\n", | ||
| 372 | " description = Column(String(64))\n", | ||
| 373 | "\n", | 387 | "\n", |
| 388 | " # redefining the 'description' column\n", | ||
| 389 | " description = mapped_column(String(32))\n", | ||
| 374 | " production_plans = relationship(\n", | 390 | " production_plans = relationship(\n", |
| 375 | " \"ProductionPlan\", back_populates=\"production_type\", lazy=\"dynamic\"\n", | 391 | " \"ProductionPlan\", back_populates=\"production_type\", lazy=\"dynamic\"\n", |
| 376 | " )\n", | 392 | " )\n", |
| @@ -391,7 +407,8 @@ | |||
| 391 | "\n", | 407 | "\n", |
| 392 | "class BiddingArea(Base):\n", | 408 | "class BiddingArea(Base):\n", |
| 393 | " __tablename__ = \"bidding_areas\"\n", | 409 | " __tablename__ = \"bidding_areas\"\n", |
| 394 | " __table_args__ = {\"autoload\": True}\n", | 410 | " __table_args__ = {\"autoload_with\": engine}\n", |
| 411 | " # __table__ = Table(\"bidding_areas\", Base.metadata, autoload_with=engine)\n", | ||
| 395 | "\n", | 412 | "\n", |
| 396 | " production_plans = relationship(\n", | 413 | " production_plans = relationship(\n", |
| 397 | " \"ProductionPlan\", back_populates=\"bidding_area\", lazy=\"dynamic\"\n", | 414 | " \"ProductionPlan\", back_populates=\"bidding_area\", lazy=\"dynamic\"\n", |
| @@ -412,8 +429,10 @@ | |||
| 412 | "\n", | 429 | "\n", |
| 413 | "\n", | 430 | "\n", |
| 414 | "class ProductionPlan(Base):\n", | 431 | "class ProductionPlan(Base):\n", |
| 415 | " __tablename__ = \"production_plans\"\n", | 432 | " # __tablename__ = \"production_plans\"\n", |
| 416 | " __table_args__ = {\"autoload\": True}\n", | 433 | " # __table_args__ = {\"autoload_with\": engine}\n", |
| 434 | " # declarative mapping with imperative Table definition (A.K.A. Hybrid declarative)\n", | ||
| 435 | " __table__ = Table(\"production_plans\", Base.metadata, autoload_with=engine)\n", | ||
| 417 | "\n", | 436 | "\n", |
| 418 | " production_type = relationship(ProductionType, back_populates=\"production_plans\")\n", | 437 | " production_type = relationship(ProductionType, back_populates=\"production_plans\")\n", |
| 419 | " bidding_area = relationship(BiddingArea, back_populates=\"production_plans\")\n", | 438 | " bidding_area = relationship(BiddingArea, back_populates=\"production_plans\")\n", |
| @@ -443,7 +462,7 @@ | |||
| 443 | }, | 462 | }, |
| 444 | { | 463 | { |
| 445 | "cell_type": "code", | 464 | "cell_type": "code", |
| 446 | "execution_count": 14, | 465 | "execution_count": 53, |
| 447 | "id": "1f18d9c1-bd39-4195-b868-114c3296eac2", | 466 | "id": "1f18d9c1-bd39-4195-b868-114c3296eac2", |
| 448 | "metadata": { | 467 | "metadata": { |
| 449 | "slideshow": { | 468 | "slideshow": { |
| @@ -455,42 +474,42 @@ | |||
| 455 | "name": "stdout", | 474 | "name": "stdout", |
| 456 | "output_type": "stream", | 475 | "output_type": "stream", |
| 457 | "text": [ | 476 | "text": [ |
| 458 | "2022-09-21 09:05:41,358 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | 477 | "2023-09-08 09:45:43,405 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 459 | "2022-09-21 09:05:41,360 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?)\n", | 478 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?) RETURNING bidding_area_id\n", |
| 460 | "2022-09-21 09:05:41,360 INFO sqlalchemy.engine.Engine [generated in 0.00079s] ('NO1', 'Elspot NO1')\n", | 479 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine [generated in 0.00005s (insertmanyvalues) 1/5 (ordered; batch not supported)] ('NO1', 'Elspot NO1')\n", |
| 461 | "2022-09-21 09:05:41,361 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?)\n", | 480 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?) RETURNING bidding_area_id\n", |
| 462 | "2022-09-21 09:05:41,362 INFO sqlalchemy.engine.Engine [cached since 0.002301s ago] ('NO2', 'Elspot NO2')\n", | 481 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine [insertmanyvalues 2/5 (ordered; batch not supported)] ('NO2', 'Elspot NO2')\n", |
| 463 | "2022-09-21 09:05:41,364 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?)\n", | 482 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?) RETURNING bidding_area_id\n", |
| 464 | "2022-09-21 09:05:41,364 INFO sqlalchemy.engine.Engine [cached since 0.004883s ago] ('NO3', 'Elspot NO3')\n", | 483 | "2023-09-08 09:45:43,406 INFO sqlalchemy.engine.Engine [insertmanyvalues 3/5 (ordered; batch not supported)] ('NO3', 'Elspot NO3')\n", |
| 465 | "2022-09-21 09:05:41,366 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?)\n", | 484 | "2023-09-08 09:45:43,407 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?) RETURNING bidding_area_id\n", |
| 466 | "2022-09-21 09:05:41,366 INFO sqlalchemy.engine.Engine [cached since 0.006756s ago] ('NO4', 'Elspot NO4')\n", | 485 | "2023-09-08 09:45:43,407 INFO sqlalchemy.engine.Engine [insertmanyvalues 4/5 (ordered; batch not supported)] ('NO4', 'Elspot NO4')\n", |
| 467 | "2022-09-21 09:05:41,367 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?)\n", | 486 | "2023-09-08 09:45:43,407 INFO sqlalchemy.engine.Engine INSERT INTO bidding_areas (code, name) VALUES (?, ?) RETURNING bidding_area_id\n", |
| 468 | "2022-09-21 09:05:41,368 INFO sqlalchemy.engine.Engine [cached since 0.008241s ago] ('NO5', 'Elspot NO5')\n", | 487 | "2023-09-08 09:45:43,407 INFO sqlalchemy.engine.Engine [insertmanyvalues 5/5 (ordered; batch not supported)] ('NO5', 'Elspot NO5')\n", |
| 469 | "2022-09-21 09:05:41,370 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 488 | "2023-09-08 09:45:43,407 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 470 | "2022-09-21 09:05:41,370 INFO sqlalchemy.engine.Engine [generated in 0.00058s] ('B19', 'Wind Onshore')\n", | 489 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine [generated in 0.00004s (insertmanyvalues) 1/7 (ordered; batch not supported)] ('B19', 'Wind Onshore')\n", |
| 471 | "2022-09-21 09:05:41,371 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 490 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 472 | "2022-09-21 09:05:41,372 INFO sqlalchemy.engine.Engine [cached since 0.00176s ago] ('B10', 'Hydro-electric pure pumped storage head installation')\n", | 491 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine [insertmanyvalues 2/7 (ordered; batch not supported)] ('B10', 'Hydro-electric pure pumped storage head installation')\n", |
| 473 | "2022-09-21 09:05:41,373 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 492 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 474 | "2022-09-21 09:05:41,374 INFO sqlalchemy.engine.Engine [cached since 0.003672s ago] ('B11', 'Hydro Run-of-river head installation')\n", | 493 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine [insertmanyvalues 3/7 (ordered; batch not supported)] ('B11', 'Hydro Run-of-river head installation')\n", |
| 475 | "2022-09-21 09:05:41,375 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 494 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 476 | "2022-09-21 09:05:41,375 INFO sqlalchemy.engine.Engine [cached since 0.00531s ago] ('B12', 'Hydro-electric storage head installation')\n", | 495 | "2023-09-08 09:45:43,408 INFO sqlalchemy.engine.Engine [insertmanyvalues 4/7 (ordered; batch not supported)] ('B12', 'Hydro-electric storage head installation')\n", |
| 477 | "2022-09-21 09:05:41,376 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 496 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 478 | "2022-09-21 09:05:41,377 INFO sqlalchemy.engine.Engine [cached since 0.00679s ago] ('A04', 'Generation')\n", | 497 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine [insertmanyvalues 5/7 (ordered; batch not supported)] ('A04', 'Generation')\n", |
| 479 | "2022-09-21 09:05:41,377 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 498 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 480 | "2022-09-21 09:05:41,378 INFO sqlalchemy.engine.Engine [cached since 0.008175s ago] ('B37', 'Thermal unspecified')\n", | 499 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine [insertmanyvalues 6/7 (ordered; batch not supported)] ('B37', 'Thermal unspecified')\n", |
| 481 | "2022-09-21 09:05:41,379 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?)\n", | 500 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine INSERT INTO production_types (code, description) VALUES (?, ?) RETURNING production_type_id\n", |
| 482 | "2022-09-21 09:05:41,380 INFO sqlalchemy.engine.Engine [cached since 0.01012s ago] ('B30', 'Wind unspecified')\n", | 501 | "2023-09-08 09:45:43,409 INFO sqlalchemy.engine.Engine [insertmanyvalues 7/7 (ordered; batch not supported)] ('B30', 'Wind unspecified')\n", |
| 483 | "2022-09-21 09:05:41,382 INFO sqlalchemy.engine.Engine INSERT INTO production_plans (record_created_time, start_time, bidding_area_id, production_type_id, value) VALUES (?, ?, ?, ?, ?)\n", | 502 | "2023-09-08 09:45:43,410 INFO sqlalchemy.engine.Engine INSERT INTO production_plans (record_created_time, start_time, bidding_area_id, production_type_id, value) VALUES (?, ?, ?, ?, ?)\n", |
| 484 | "2022-09-21 09:05:41,383 INFO sqlalchemy.engine.Engine [generated in 0.00075s] (('2022-09-21 09:05:41.357984', '2022-11-02 01:00:00.000000', 1, 6, 80.5), ('2022-09-21 09:05:41.358126', '2022-11-02 02:00:00.000000', 1, 6, 90.5))\n", | 503 | "2023-09-08 09:45:43,410 INFO sqlalchemy.engine.Engine [generated in 0.00024s] [('2023-09-08 09:45:43.404962', '2022-11-02 01:00:00.000000', 1, 6, 80.5), ('2023-09-08 09:45:43.405033', '2022-11-02 02:00:00.000000', 1, 6, 90.5)]\n", |
| 485 | "2022-09-21 09:05:41,384 INFO sqlalchemy.engine.Engine COMMIT\n", | 504 | "2023-09-08 09:45:43,410 INFO sqlalchemy.engine.Engine COMMIT\n", |
| 486 | "2022-09-21 09:05:41,385 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | 505 | "2023-09-08 09:45:43,411 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 487 | "2022-09-21 09:05:41,387 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id \n", | 506 | "2023-09-08 09:45:43,411 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id \n", |
| 488 | "FROM production_plans \n", | 507 | "FROM production_plans \n", |
| 489 | "WHERE production_plans.record_created_time = ? AND production_plans.start_time = ? AND production_plans.bidding_area_id = ? AND production_plans.production_type_id = ?\n", | 508 | "WHERE production_plans.record_created_time = ? AND production_plans.start_time = ? AND production_plans.bidding_area_id = ? AND production_plans.production_type_id = ?\n", |
| 490 | "2022-09-21 09:05:41,388 INFO sqlalchemy.engine.Engine [generated in 0.00093s] ('2022-09-21 09:05:41.358126', '2022-11-02 02:00:00.000000', 1, 6)\n", | 509 | "2023-09-08 09:45:43,412 INFO sqlalchemy.engine.Engine [generated in 0.00017s] ('2023-09-08 09:45:43.405033', '2022-11-02 02:00:00.000000', 1, 6)\n", |
| 491 | "2022-09-21 09:05:41,390 INFO sqlalchemy.engine.Engine UPDATE production_plans SET value=? WHERE production_plans.record_created_time = ? AND production_plans.start_time = ? AND production_plans.bidding_area_id = ? AND production_plans.production_type_id = ?\n", | 510 | "2023-09-08 09:45:43,412 INFO sqlalchemy.engine.Engine UPDATE production_plans SET value=? WHERE production_plans.record_created_time = ? AND production_plans.start_time = ? AND production_plans.bidding_area_id = ? AND production_plans.production_type_id = ?\n", |
| 492 | "2022-09-21 09:05:41,391 INFO sqlalchemy.engine.Engine [generated in 0.00054s] (70.5, '2022-09-21 09:05:41.358126', '2022-11-02 02:00:00.000000', 1, 6)\n", | 511 | "2023-09-08 09:45:43,412 INFO sqlalchemy.engine.Engine [generated in 0.00016s] (70.5, '2023-09-08 09:45:43.405033', '2022-11-02 02:00:00.000000', 1, 6)\n", |
| 493 | "2022-09-21 09:05:41,392 INFO sqlalchemy.engine.Engine COMMIT\n" | 512 | "2023-09-08 09:45:43,413 INFO sqlalchemy.engine.Engine COMMIT\n" |
| 494 | ] | 513 | ] |
| 495 | } | 514 | } |
| 496 | ], | 515 | ], |
| @@ -499,10 +518,10 @@ | |||
| 499 | "import datetime\n", | 518 | "import datetime\n", |
| 500 | "import decimal\n", | 519 | "import decimal\n", |
| 501 | "\n", | 520 | "\n", |
| 502 | "from sqlalchemy.orm import sessionmaker\n", | 521 | "from sqlalchemy.orm import Session\n", |
| 503 | "\n", | 522 | "\n", |
| 504 | "Session = sessionmaker(bind=engine) # bound session\n", | 523 | "session = Session(engine)\n", |
| 505 | "session = Session()\n", | 524 | "# with Session(engine) as session:\n", |
| 506 | "\n", | 525 | "\n", |
| 507 | "bidding_area1 = BiddingArea(\"NO1\", \"Elspot NO1\")\n", | 526 | "bidding_area1 = BiddingArea(\"NO1\", \"Elspot NO1\")\n", |
| 508 | "session.add(bidding_area1),\n", | 527 | "session.add(bidding_area1),\n", |
| @@ -556,14 +575,14 @@ | |||
| 556 | "\n", | 575 | "\n", |
| 557 | "production_plan2.value = decimal.Decimal(\"70.5\")\n", | 576 | "production_plan2.value = decimal.Decimal(\"70.5\")\n", |
| 558 | "production_plan2 in session\n", | 577 | "production_plan2 in session\n", |
| 559 | "# Out: True\n", | 578 | " # Out: True\n", |
| 560 | "\n", | 579 | "\n", |
| 561 | "session.commit()\n" | 580 | "session.commit()\n" |
| 562 | ] | 581 | ] |
| 563 | }, | 582 | }, |
| 564 | { | 583 | { |
| 565 | "cell_type": "code", | 584 | "cell_type": "code", |
| 566 | "execution_count": 15, | 585 | "execution_count": 54, |
| 567 | "id": "875195c5-ae99-4aa8-9aca-89d6e9c27ae2", | 586 | "id": "875195c5-ae99-4aa8-9aca-89d6e9c27ae2", |
| 568 | "metadata": {}, | 587 | "metadata": {}, |
| 569 | "outputs": [ | 588 | "outputs": [ |
| @@ -571,139 +590,145 @@ | |||
| 571 | "name": "stdout", | 590 | "name": "stdout", |
| 572 | "output_type": "stream", | 591 | "output_type": "stream", |
| 573 | "text": [ | 592 | "text": [ |
| 574 | "2022-09-21 09:05:41,400 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | 593 | "2023-09-08 09:45:43,415 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 575 | "2022-09-21 09:05:41,402 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 594 | "2023-09-08 09:45:43,416 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 576 | "FROM production_plans ORDER BY production_plans.start_time\n", | 595 | "FROM production_plans ORDER BY production_plans.start_time\n", |
| 577 | "2022-09-21 09:05:41,403 INFO sqlalchemy.engine.Engine [generated in 0.00078s] ()\n", | 596 | "2023-09-08 09:45:43,416 INFO sqlalchemy.engine.Engine [generated in 0.00015s] ()\n", |
| 578 | "2022-09-21 09:05:41,406 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 597 | "2023-09-08 09:45:43,417 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 579 | "FROM production_plans \n", | 598 | "FROM production_plans \n", |
| 580 | "WHERE production_plans.start_time > ?\n", | 599 | "WHERE production_plans.start_time > ?\n", |
| 581 | "2022-09-21 09:05:41,406 INFO sqlalchemy.engine.Engine [generated in 0.00070s] ('2022-09-01 00:00:00.000000',)\n", | 600 | "2023-09-08 09:45:43,417 INFO sqlalchemy.engine.Engine [generated in 0.00016s] ('2022-09-01 00:00:00.000000',)\n", |
| 582 | "2022-09-21 09:05:41,409 INFO sqlalchemy.engine.Engine SELECT count(*) AS count_1 \n", | 601 | "2023-09-08 09:45:43,418 INFO sqlalchemy.engine.Engine SELECT count(*) AS count_1 \n", |
| 583 | "FROM (SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 602 | "FROM (SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 584 | "FROM production_plans \n", | 603 | "FROM production_plans \n", |
| 585 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time) AS anon_1\n", | 604 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time) AS anon_1\n", |
| 586 | "2022-09-21 09:05:41,410 INFO sqlalchemy.engine.Engine [generated in 0.00059s] (80,)\n", | 605 | "2023-09-08 09:45:43,418 INFO sqlalchemy.engine.Engine [generated in 0.00016s] (80,)\n", |
| 587 | "2022-09-21 09:05:41,412 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 606 | "2023-09-08 09:45:43,419 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 588 | "FROM production_plans \n", | 607 | "FROM production_plans \n", |
| 589 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | 608 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", |
| 590 | " LIMIT ? OFFSET ?\n", | 609 | " LIMIT ? OFFSET ?\n", |
| 591 | "2022-09-21 09:05:41,412 INFO sqlalchemy.engine.Engine [generated in 0.00056s] (80, 1, 0)\n", | 610 | "2023-09-08 09:45:43,419 INFO sqlalchemy.engine.Engine [generated in 0.00015s] (80, 1, 0)\n", |
| 592 | "2022-09-21 09:05:41,414 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 611 | "2023-09-08 09:45:43,420 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 593 | "FROM production_plans \n", | 612 | "FROM production_plans \n", |
| 594 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | 613 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", |
| 595 | "2022-09-21 09:05:41,415 INFO sqlalchemy.engine.Engine [generated in 0.00066s] (80,)\n", | 614 | "2023-09-08 09:45:43,420 INFO sqlalchemy.engine.Engine [generated in 0.00014s] (80,)\n", |
| 596 | "2022-09-21 09:05:41,417 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", | 615 | "2023-09-08 09:45:43,420 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", |
| 597 | "2022-09-21 09:05:41,418 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 616 | "2023-09-08 09:45:43,420 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", |
| 598 | "2022-09-21 09:05:41,419 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_plans\")\n", | 617 | "2023-09-08 09:45:43,420 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 599 | "2022-09-21 09:05:41,420 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 618 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite~_%' ESCAPE '~' ORDER BY name\n", |
| 600 | "2022-09-21 09:05:41,421 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 619 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 601 | "2022-09-21 09:05:41,422 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | 620 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine SELECT name FROM sqlite_temp_master WHERE type='table' AND name NOT LIKE 'sqlite~_%' ESCAPE '~' ORDER BY name\n", |
| 602 | "2022-09-21 09:05:41,423 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_plans\")\n", | 621 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 603 | "2022-09-21 09:05:41,424 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 622 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_plans\")\n", |
| 604 | "2022-09-21 09:05:41,425 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 623 | "2023-09-08 09:45:43,421 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 605 | "2022-09-21 09:05:41,425 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | 624 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 606 | "2022-09-21 09:05:41,427 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"bidding_areas\")\n", | 625 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", |
| 607 | "2022-09-21 09:05:41,427 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 626 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_plans\")\n", |
| 608 | "2022-09-21 09:05:41,428 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 627 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 609 | "2022-09-21 09:05:41,429 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 628 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 610 | "2022-09-21 09:05:41,430 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"bidding_areas\")\n", | 629 | "2023-09-08 09:45:43,422 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", |
| 611 | "2022-09-21 09:05:41,430 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 630 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", |
| 612 | "2022-09-21 09:05:41,432 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"bidding_areas\")\n", | 631 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 613 | "2022-09-21 09:05:41,432 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 632 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", |
| 614 | "2022-09-21 09:05:41,434 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 633 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 615 | "2022-09-21 09:05:41,434 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 634 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", |
| 616 | "2022-09-21 09:05:41,436 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | 635 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 617 | "2022-09-21 09:05:41,436 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 636 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_plans_1\")\n", |
| 618 | "2022-09-21 09:05:41,437 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | 637 | "2023-09-08 09:45:43,423 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 619 | "2022-09-21 09:05:41,438 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 638 | "2023-09-08 09:45:43,424 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 620 | "2022-09-21 09:05:41,439 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_bidding_areas_1\")\n", | 639 | "2023-09-08 09:45:43,424 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", |
| 621 | "2022-09-21 09:05:41,440 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 640 | "2023-09-08 09:45:43,424 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"bidding_areas\")\n", |
| 622 | "2022-09-21 09:05:41,441 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 641 | "2023-09-08 09:45:43,424 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 623 | "2022-09-21 09:05:41,441 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | 642 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 624 | "2022-09-21 09:05:41,443 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_types\")\n", | 643 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 625 | "2022-09-21 09:05:41,443 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 644 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"bidding_areas\")\n", |
| 626 | "2022-09-21 09:05:41,445 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 645 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 627 | "2022-09-21 09:05:41,445 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 646 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"bidding_areas\")\n", |
| 628 | "2022-09-21 09:05:41,446 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_types\")\n", | 647 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 629 | "2022-09-21 09:05:41,447 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 648 | "2023-09-08 09:45:43,425 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 630 | "2022-09-21 09:05:41,448 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"production_types\")\n", | 649 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 631 | "2022-09-21 09:05:41,448 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 650 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", |
| 632 | "2022-09-21 09:05:41,450 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 651 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 633 | "2022-09-21 09:05:41,450 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 652 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"bidding_areas\")\n", |
| 634 | "2022-09-21 09:05:41,452 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | 653 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 635 | "2022-09-21 09:05:41,452 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 654 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", |
| 636 | "2022-09-21 09:05:41,453 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | 655 | "2023-09-08 09:45:43,426 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 637 | "2022-09-21 09:05:41,454 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 656 | "2023-09-08 09:45:43,427 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_bidding_areas_1\")\n", |
| 638 | "2022-09-21 09:05:41,455 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_types_1\")\n", | 657 | "2023-09-08 09:45:43,427 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 639 | "2022-09-21 09:05:41,456 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 658 | "2023-09-08 09:45:43,427 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 640 | "2022-09-21 09:05:41,457 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 659 | "2023-09-08 09:45:43,427 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", |
| 641 | "2022-09-21 09:05:41,458 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | 660 | "2023-09-08 09:45:43,427 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_types\")\n", |
| 642 | "2022-09-21 09:05:41,459 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | 661 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 643 | "2022-09-21 09:05:41,459 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 662 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 644 | "2022-09-21 09:05:41,461 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | 663 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", |
| 645 | "2022-09-21 09:05:41,461 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 664 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_types\")\n", |
| 646 | "2022-09-21 09:05:41,462 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_plans_1\")\n", | 665 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 647 | "2022-09-21 09:05:41,462 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | 666 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"production_types\")\n", |
| 648 | "2022-09-21 09:05:41,464 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type = 'table'\n", | 667 | "2023-09-08 09:45:43,428 INFO sqlalchemy.engine.Engine [raw sql] ()\n", |
| 649 | "2022-09-21 09:05:41,464 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | 668 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", |
| 650 | "2022-09-21 09:05:41,466 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | 669 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", |
| 670 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | ||
| 671 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 672 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_types\")\n", | ||
| 673 | "2023-09-08 09:45:43,429 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 674 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | ||
| 675 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 676 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_types_1\")\n", | ||
| 677 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 678 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 679 | "2023-09-08 09:45:43,430 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | ||
| 680 | "2023-09-08 09:45:43,431 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 651 | "FROM production_plans\n", | 681 | "FROM production_plans\n", |
| 652 | "2022-09-21 09:05:41,467 INFO sqlalchemy.engine.Engine [generated in 0.00114s] ()\n", | 682 | "2023-09-08 09:45:43,431 INFO sqlalchemy.engine.Engine [generated in 0.00014s] ()\n", |
| 653 | "2022-09-21 09:05:41,471 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | 683 | "2023-09-08 09:45:43,432 INFO sqlalchemy.engine.Engine COMMIT\n", |
| 684 | "2023-09-08 09:45:43,432 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | ||
| 685 | "2023-09-08 09:45:43,433 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 654 | "FROM production_plans \n", | 686 | "FROM production_plans \n", |
| 655 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | 687 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", |
| 656 | "2022-09-21 09:05:41,472 INFO sqlalchemy.engine.Engine [generated in 0.00061s] (80,)\n", | 688 | "2023-09-08 09:45:43,433 INFO sqlalchemy.engine.Engine [generated in 0.00026s] (80,)\n", |
| 657 | "2022-09-21 09:05:41,475 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 689 | "2023-09-08 09:45:43,433 INFO sqlalchemy.engine.Engine ROLLBACK\n", |
| 690 | "2023-09-08 09:45:43,434 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | ||
| 658 | "FROM production_plans, production_types \n", | 691 | "FROM production_plans, production_types \n", |
| 659 | "WHERE production_plans.production_type_id = production_types.production_type_id AND production_types.code = ?\n", | 692 | "WHERE production_plans.production_type_id = production_types.production_type_id AND production_types.code = ?\n", |
| 660 | "2022-09-21 09:05:41,476 INFO sqlalchemy.engine.Engine [generated in 0.00097s] ('B37',)\n", | 693 | "2023-09-08 09:45:43,434 INFO sqlalchemy.engine.Engine [generated in 0.00021s] ('B37',)\n", |
| 661 | "2022-09-21 09:05:41,478 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 694 | "2023-09-08 09:45:43,435 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 662 | "FROM production_plans JOIN production_types ON production_types.production_type_id = production_plans.production_type_id \n", | 695 | "FROM production_plans JOIN production_types ON production_types.production_type_id = production_plans.production_type_id \n", |
| 663 | "WHERE production_types.code = ?\n", | 696 | "WHERE production_types.code = ?\n", |
| 664 | "2022-09-21 09:05:41,478 INFO sqlalchemy.engine.Engine [generated in 0.00060s] ('B37',)\n", | 697 | "2023-09-08 09:45:43,435 INFO sqlalchemy.engine.Engine [generated in 0.00015s] ('B37',)\n", |
| 665 | "2022-09-21 09:05:41,481 INFO sqlalchemy.engine.Engine SELECT production_types.production_type_id AS production_types_production_type_id, production_types.code AS production_types_code, production_types.description AS production_types_description \n", | 698 | "2023-09-08 09:45:43,436 INFO sqlalchemy.engine.Engine SELECT production_types.production_type_id AS production_types_production_type_id, production_types.code AS production_types_code, production_types.description AS production_types_description \n", |
| 666 | "FROM production_types \n", | 699 | "FROM production_types \n", |
| 667 | "WHERE production_types.production_type_id = ?\n", | 700 | "WHERE production_types.production_type_id = ?\n", |
| 668 | "2022-09-21 09:05:41,482 INFO sqlalchemy.engine.Engine [generated in 0.00098s] (6,)\n", | 701 | "2023-09-08 09:45:43,436 INFO sqlalchemy.engine.Engine [generated in 0.00015s] (6,)\n", |
| 669 | "2022-09-21 09:05:41,483 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", | 702 | "2023-09-08 09:45:43,436 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time AS production_plans_record_created_time, production_plans.start_time AS production_plans_start_time, production_plans.bidding_area_id AS production_plans_bidding_area_id, production_plans.production_type_id AS production_plans_production_type_id, production_plans.value AS production_plans_value \n", |
| 670 | "FROM production_plans \n", | 703 | "FROM production_plans \n", |
| 671 | "WHERE ? = production_plans.production_type_id\n", | 704 | "WHERE ? = production_plans.production_type_id\n", |
| 672 | "2022-09-21 09:05:41,484 INFO sqlalchemy.engine.Engine [generated in 0.00342s] (6,)\n", | 705 | "2023-09-08 09:45:43,436 INFO sqlalchemy.engine.Engine [generated in 0.00093s] (6,)\n", |
| 673 | "2022-09-21 09:05:41,486 INFO sqlalchemy.engine.Engine SELECT pp.* FROM production_plans pp, production_types pt WHERE pp.production_type_id = pt.production_type_id AND pt.code=?\n", | 706 | "2023-09-08 09:45:43,437 INFO sqlalchemy.engine.Engine SELECT pp.* FROM production_plans pp, production_types pt WHERE pp.production_type_id = pt.production_type_id AND pt.code=?\n", |
| 674 | "2022-09-21 09:05:41,486 INFO sqlalchemy.engine.Engine [generated in 0.00058s] ('B37',)\n", | 707 | "2023-09-08 09:45:43,437 INFO sqlalchemy.engine.Engine [generated in 0.00015s] ('B37',)\n", |
| 675 | "2022-09-21 09:05:41,492 INFO sqlalchemy.engine.Engine SELECT bidding_areas.bidding_area_id AS bidding_areas_bidding_area_id, bidding_areas.code AS bidding_areas_code, bidding_areas.name AS bidding_areas_name \n", | 708 | "2023-09-08 09:45:43,439 INFO sqlalchemy.engine.Engine SELECT bidding_areas.bidding_area_id AS bidding_areas_bidding_area_id, bidding_areas.code AS bidding_areas_code, bidding_areas.name AS bidding_areas_name \n", |
| 676 | "FROM bidding_areas \n", | 709 | "FROM bidding_areas \n", |
| 677 | "WHERE bidding_areas.bidding_area_id = ?\n", | 710 | "WHERE bidding_areas.bidding_area_id = ?\n", |
| 678 | "2022-09-21 09:05:41,492 INFO sqlalchemy.engine.Engine [generated in 0.00065s] (1,)\n" | 711 | "2023-09-08 09:45:43,439 INFO sqlalchemy.engine.Engine [generated in 0.00016s] (1,)\n" |
| 679 | ] | ||
| 680 | }, | ||
| 681 | { | ||
| 682 | "name": "stderr", | ||
| 683 | "output_type": "stream", | ||
| 684 | "text": [ | ||
| 685 | "/tmp/ipykernel_611/3660144138.py:7: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.\n", | ||
| 686 | " session.query(ProductionPlan).order_by(ProductionPlan.start_time).all() # returns an object-list\n" | ||
| 687 | ] | 712 | ] |
| 688 | }, | 713 | }, |
| 689 | { | 714 | { |
| 690 | "data": { | 715 | "data": { |
| 691 | "text/plain": [ | 716 | "text/plain": [ |
| 692 | "[<ProductionPlan(record_created_time=datetime.datetime(2022, 9, 21, 9, 5, 41, 357984), start_time=datetime.datetime(2022, 11, 2, 1, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('80.5000000000'))>,\n", | 717 | "[<ProductionPlan(record_created_time=datetime.datetime(2023, 9, 8, 9, 45, 43, 404962), start_time=datetime.datetime(2022, 11, 2, 1, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('80.5000000000'))>,\n", |
| 693 | " <ProductionPlan(record_created_time=datetime.datetime(2022, 9, 21, 9, 5, 41, 358126), start_time=datetime.datetime(2022, 11, 2, 2, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('70.5000000000'))>]" | 718 | " <ProductionPlan(record_created_time=datetime.datetime(2023, 9, 8, 9, 45, 43, 405033), start_time=datetime.datetime(2022, 11, 2, 2, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('70.5000000000'))>]" |
| 694 | ] | 719 | ] |
| 695 | }, | 720 | }, |
| 696 | "execution_count": 15, | 721 | "execution_count": 54, |
| 697 | "metadata": {}, | 722 | "metadata": {}, |
| 698 | "output_type": "execute_result" | 723 | "output_type": "execute_result" |
| 699 | } | 724 | } |
| 700 | ], | 725 | ], |
| 701 | "source": [ | 726 | "source": [ |
| 727 | "# Old SQLAlchemy 1.x API - still working in SQLAlchemy 2\n", | ||
| 702 | "import pandas as pd\n", | 728 | "import pandas as pd\n", |
| 703 | "\n", | 729 | "\n", |
| 704 | "from sqlalchemy import text\n", | 730 | "from sqlalchemy import text\n", |
| 705 | "\n", | 731 | "\n", |
| 706 | "\n", | ||
| 707 | "session.query(ProductionPlan).order_by(ProductionPlan.start_time) # returns a Query instance\n", | 732 | "session.query(ProductionPlan).order_by(ProductionPlan.start_time) # returns a Query instance\n", |
| 708 | "session.query(ProductionPlan).order_by(ProductionPlan.start_time).all() # returns an object-list\n", | 733 | "session.query(ProductionPlan).order_by(ProductionPlan.start_time).all() # returns an object-list\n", |
| 709 | "\n", | 734 | "\n", |
| @@ -738,13 +763,214 @@ | |||
| 738 | ] | 763 | ] |
| 739 | }, | 764 | }, |
| 740 | { | 765 | { |
| 766 | "cell_type": "code", | ||
| 767 | "execution_count": 55, | ||
| 768 | "id": "c2f70746-485d-4d1d-ae6e-27e3cf70b99c", | ||
| 769 | "metadata": {}, | ||
| 770 | "outputs": [ | ||
| 771 | { | ||
| 772 | "name": "stdout", | ||
| 773 | "output_type": "stream", | ||
| 774 | "text": [ | ||
| 775 | "2023-09-08 09:45:43,443 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 776 | "FROM production_plans ORDER BY production_plans.start_time\n", | ||
| 777 | "2023-09-08 09:45:43,443 INFO sqlalchemy.engine.Engine [generated in 0.00041s] ()\n", | ||
| 778 | "2023-09-08 09:45:43,443 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 779 | "FROM production_plans ORDER BY production_plans.start_time\n", | ||
| 780 | "2023-09-08 09:45:43,443 INFO sqlalchemy.engine.Engine [cached since 0.0009604s ago] ()\n", | ||
| 781 | "2023-09-08 09:45:43,444 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 782 | "FROM production_plans \n", | ||
| 783 | "WHERE production_plans.start_time > ?\n", | ||
| 784 | "2023-09-08 09:45:43,444 INFO sqlalchemy.engine.Engine [generated in 0.00015s] ('2022-09-01 00:00:00.000000',)\n", | ||
| 785 | "2023-09-08 09:45:43,445 INFO sqlalchemy.engine.Engine SELECT count(*) AS count_1 \n", | ||
| 786 | "FROM (SELECT production_plans.record_created_time AS record_created_time, production_plans.start_time AS start_time, production_plans.bidding_area_id AS bidding_area_id, production_plans.production_type_id AS production_type_id, production_plans.value AS value \n", | ||
| 787 | "FROM production_plans \n", | ||
| 788 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time) AS anon_1\n", | ||
| 789 | "2023-09-08 09:45:43,445 INFO sqlalchemy.engine.Engine [generated in 0.00020s] (80,)\n", | ||
| 790 | "2023-09-08 09:45:43,446 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 791 | "FROM production_plans \n", | ||
| 792 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | ||
| 793 | "2023-09-08 09:45:43,446 INFO sqlalchemy.engine.Engine [generated in 0.00024s] (80,)\n", | ||
| 794 | "2023-09-08 09:45:43,446 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 795 | "FROM production_plans \n", | ||
| 796 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | ||
| 797 | "2023-09-08 09:45:43,446 INFO sqlalchemy.engine.Engine [cached since 0.0007238s ago] (80,)\n", | ||
| 798 | "2023-09-08 09:45:43,447 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | ||
| 799 | "2023-09-08 09:45:43,447 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", | ||
| 800 | "2023-09-08 09:45:43,447 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 801 | "2023-09-08 09:45:43,447 INFO sqlalchemy.engine.Engine SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite~_%' ESCAPE '~' ORDER BY name\n", | ||
| 802 | "2023-09-08 09:45:43,448 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 803 | "2023-09-08 09:45:43,448 INFO sqlalchemy.engine.Engine SELECT name FROM sqlite_temp_master WHERE type='table' AND name NOT LIKE 'sqlite~_%' ESCAPE '~' ORDER BY name\n", | ||
| 804 | "2023-09-08 09:45:43,448 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 805 | "2023-09-08 09:45:43,448 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_plans\")\n", | ||
| 806 | "2023-09-08 09:45:43,448 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 807 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 808 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | ||
| 809 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_plans\")\n", | ||
| 810 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 811 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 812 | "2023-09-08 09:45:43,449 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | ||
| 813 | "2023-09-08 09:45:43,450 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | ||
| 814 | "2023-09-08 09:45:43,450 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 815 | "2023-09-08 09:45:43,450 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_plans\")\n", | ||
| 816 | "2023-09-08 09:45:43,450 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 817 | "2023-09-08 09:45:43,450 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_plans\")\n", | ||
| 818 | "2023-09-08 09:45:43,451 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 819 | "2023-09-08 09:45:43,451 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_plans_1\")\n", | ||
| 820 | "2023-09-08 09:45:43,451 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 821 | "2023-09-08 09:45:43,451 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 822 | "2023-09-08 09:45:43,451 INFO sqlalchemy.engine.Engine [raw sql] ('production_plans',)\n", | ||
| 823 | "2023-09-08 09:45:43,452 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"bidding_areas\")\n", | ||
| 824 | "2023-09-08 09:45:43,452 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 825 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 826 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | ||
| 827 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"bidding_areas\")\n", | ||
| 828 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 829 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"bidding_areas\")\n", | ||
| 830 | "2023-09-08 09:45:43,453 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 831 | "2023-09-08 09:45:43,454 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 832 | "2023-09-08 09:45:43,454 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | ||
| 833 | "2023-09-08 09:45:43,454 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | ||
| 834 | "2023-09-08 09:45:43,454 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 835 | "2023-09-08 09:45:43,454 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"bidding_areas\")\n", | ||
| 836 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 837 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"bidding_areas\")\n", | ||
| 838 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 839 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_bidding_areas_1\")\n", | ||
| 840 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 841 | "2023-09-08 09:45:43,455 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 842 | "2023-09-08 09:45:43,456 INFO sqlalchemy.engine.Engine [raw sql] ('bidding_areas',)\n", | ||
| 843 | "2023-09-08 09:45:43,456 INFO sqlalchemy.engine.Engine PRAGMA main.table_xinfo(\"production_types\")\n", | ||
| 844 | "2023-09-08 09:45:43,456 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 845 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 846 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | ||
| 847 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine PRAGMA main.foreign_key_list(\"production_types\")\n", | ||
| 848 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 849 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine PRAGMA temp.foreign_key_list(\"production_types\")\n", | ||
| 850 | "2023-09-08 09:45:43,457 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 851 | "2023-09-08 09:45:43,458 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 852 | "2023-09-08 09:45:43,458 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | ||
| 853 | "2023-09-08 09:45:43,458 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | ||
| 854 | "2023-09-08 09:45:43,458 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 855 | "2023-09-08 09:45:43,458 INFO sqlalchemy.engine.Engine PRAGMA main.table_info(\"production_types\")\n", | ||
| 856 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 857 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine PRAGMA main.index_list(\"production_types\")\n", | ||
| 858 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 859 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine PRAGMA main.index_info(\"sqlite_autoindex_production_types_1\")\n", | ||
| 860 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine [raw sql] ()\n", | ||
| 861 | "2023-09-08 09:45:43,459 INFO sqlalchemy.engine.Engine SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE name = ? AND type in ('table', 'view')\n", | ||
| 862 | "2023-09-08 09:45:43,460 INFO sqlalchemy.engine.Engine [raw sql] ('production_types',)\n", | ||
| 863 | "2023-09-08 09:45:43,460 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 864 | "FROM production_plans\n", | ||
| 865 | "2023-09-08 09:45:43,461 INFO sqlalchemy.engine.Engine [generated in 0.00023s] ()\n", | ||
| 866 | "2023-09-08 09:45:43,462 INFO sqlalchemy.engine.Engine COMMIT\n", | ||
| 867 | "2023-09-08 09:45:43,462 INFO sqlalchemy.engine.Engine BEGIN (implicit)\n", | ||
| 868 | "2023-09-08 09:45:43,462 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 869 | "FROM production_plans \n", | ||
| 870 | "WHERE production_plans.value > ? ORDER BY production_plans.start_time\n", | ||
| 871 | "2023-09-08 09:45:43,462 INFO sqlalchemy.engine.Engine [cached since 0.01647s ago] (80,)\n", | ||
| 872 | "2023-09-08 09:45:43,463 INFO sqlalchemy.engine.Engine ROLLBACK\n", | ||
| 873 | "2023-09-08 09:45:43,463 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 874 | "FROM production_plans, production_types \n", | ||
| 875 | "WHERE production_plans.production_type_id = production_types.production_type_id AND production_types.code = ?\n", | ||
| 876 | "2023-09-08 09:45:43,463 INFO sqlalchemy.engine.Engine [generated in 0.00021s] ('B37',)\n", | ||
| 877 | "2023-09-08 09:45:43,464 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 878 | "FROM production_plans JOIN production_types ON production_types.production_type_id = production_plans.production_type_id \n", | ||
| 879 | "WHERE production_types.code = ?\n", | ||
| 880 | "2023-09-08 09:45:43,464 INFO sqlalchemy.engine.Engine [generated in 0.00020s] ('B37',)\n", | ||
| 881 | "2023-09-08 09:45:43,465 INFO sqlalchemy.engine.Engine SELECT production_plans.record_created_time, production_plans.start_time, production_plans.bidding_area_id, production_plans.production_type_id, production_plans.value \n", | ||
| 882 | "FROM production_plans \n", | ||
| 883 | "WHERE ? = production_plans.production_type_id\n", | ||
| 884 | "2023-09-08 09:45:43,465 INFO sqlalchemy.engine.Engine [generated in 0.00026s] (6,)\n" | ||
| 885 | ] | ||
| 886 | }, | ||
| 887 | { | ||
| 888 | "data": { | ||
| 889 | "text/plain": [ | ||
| 890 | "[<ProductionPlan(record_created_time=datetime.datetime(2023, 9, 8, 9, 45, 43, 404962), start_time=datetime.datetime(2022, 11, 2, 1, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('80.5000000000'))>,\n", | ||
| 891 | " <ProductionPlan(record_created_time=datetime.datetime(2023, 9, 8, 9, 45, 43, 405033), start_time=datetime.datetime(2022, 11, 2, 2, 0), production_type=<ProductionType(production_type_id=6, code='B37', description='Thermal unspecified')>, bidding_area=<BiddingArea(bidding_area_id=1, code='NO1', name='Elspot NO1')>, value=Decimal('70.5000000000'))>]" | ||
| 892 | ] | ||
| 893 | }, | ||
| 894 | "execution_count": 55, | ||
| 895 | "metadata": {}, | ||
| 896 | "output_type": "execute_result" | ||
| 897 | } | ||
| 898 | ], | ||
| 899 | "source": [ | ||
| 900 | "# New SQLAlchemy 2 - API\n", | ||
| 901 | "\n", | ||
| 902 | "from sqlalchemy import func, select\n", | ||
| 903 | "\n", | ||
| 904 | "# Returns a sqlalchemy.sql.expression.Select instance (statement)\n", | ||
| 905 | "# No actual SELECT statement(s) have been sent to the DB-server\n", | ||
| 906 | "stmt = select(ProductionPlan).order_by(ProductionPlan.start_time)\n", | ||
| 907 | "\n", | ||
| 908 | "# sends the actual SELECT statement to the DB-server\n", | ||
| 909 | "result = session.scalars(stmt) # returns a sqlalchemy.engine.ScalarResult\n", | ||
| 910 | "result.all() # returns a list of objects (if any) and then \"closes\" the result\n", | ||
| 911 | "result.first() # N.B. will return None or raise an exeption since the Result has been \"closed\"\n", | ||
| 912 | "\n", | ||
| 913 | "session.scalars(select(ProductionPlan).order_by(ProductionPlan.start_time)).all()\n", | ||
| 914 | "\n", | ||
| 915 | "# return all production plans where start_time after 2022-09-01 00:00\n", | ||
| 916 | "session.scalars(\n", | ||
| 917 | " select(\n", | ||
| 918 | " ProductionPlan\n", | ||
| 919 | " ).where(\n", | ||
| 920 | " ProductionPlan.start_time > datetime.datetime(2022, 9, 1, 0, 0)\n", | ||
| 921 | " )\n", | ||
| 922 | ").all()\n", | ||
| 923 | "\n", | ||
| 924 | "# return production plans with value > 80\n", | ||
| 925 | "stmt = select(ProductionPlan).where(ProductionPlan.value > 80).order_by(ProductionPlan.start_time)\n", | ||
| 926 | "session.execute(select(func.count()).select_from(stmt.subquery())).scalar_one() # 1\n", | ||
| 927 | "# N.B. Result (or ScalarResult) can be invoked only once\n", | ||
| 928 | "production_plan = session.scalars(stmt).first() # returns the first object (element)\n", | ||
| 929 | "production_plan = session.scalars(stmt).one() # raises NoResultFound exception or MultipleResultsFound in case elements != 1\n", | ||
| 930 | "\n", | ||
| 931 | "# generate Pandas DataFrame from a query or entire table\n", | ||
| 932 | "df = pd.read_sql_table(\"production_plans\", con=session.get_bind()) # or con=engine\n", | ||
| 933 | "df = pd.read_sql_query(stmt, engine)\n", | ||
| 934 | "\n", | ||
| 935 | "# return production plans with production type 'B37'\n", | ||
| 936 | "session.scalars(\n", | ||
| 937 | " select(ProductionPlan).where(\n", | ||
| 938 | " ProductionPlan.production_type_id == ProductionType.production_type_id,\n", | ||
| 939 | " ProductionType.code == \"B37\"\n", | ||
| 940 | " )\n", | ||
| 941 | ").all()\n", | ||
| 942 | "session.scalars(\n", | ||
| 943 | " select(ProductionPlan).join(ProductionPlan.production_type).where(ProductionType.code == \"B37\")\n", | ||
| 944 | ").all()\n", | ||
| 945 | "session.scalars(\n", | ||
| 946 | " select(ProductionPlan).where(ProductionPlan.production_type == production_type_B37)\n", | ||
| 947 | ").all()\n", | ||
| 948 | "##session.query(\n", | ||
| 949 | "## ProductionPlan\n", | ||
| 950 | "##).from_statement(\n", | ||
| 951 | "## text(\n", | ||
| 952 | "## \"SELECT pp.* FROM production_plans pp, production_types pt \"\n", | ||
| 953 | "## \"WHERE pp.production_type_id = pt.production_type_id AND pt.code=:code\"\n", | ||
| 954 | "## )\n", | ||
| 955 | "##).params(code=\"B37\").all()" | ||
| 956 | ] | ||
| 957 | }, | ||
| 958 | { | ||
| 741 | "cell_type": "markdown", | 959 | "cell_type": "markdown", |
| 742 | "id": "86336aaa-540c-466d-b5c1-f3fc179bd1e3", | 960 | "id": "d5b79cc1-bec7-4837-89a0-9fdbcbfd7fc0", |
| 743 | "metadata": {}, | 961 | "metadata": {}, |
| 744 | "source": [ | 962 | "source": [ |
| 745 | "# TODO\n", | 963 | "# Some basic tips when using ORM models\n", |
| 746 | "\n", | 964 | "\n", |
| 747 | "- delete\n" | 965 | " - **Business logic is implemented in the respective models.** Objects are responsible for their own actions.\n", |
| 966 | " - All object-orientation rules (SOLID etc.) should apply\n", | ||
| 967 | " - When is comes to overall design. in general always consider using composition (**has a** relationships) before considering inheritance (**is a** relationships)\n", | ||
| 968 | " - Try to make the DBMS do the job. If not possible, try to make SQLAlchemy do it and only if that is not possible try to do it yourself\n", | ||
| 969 | " - Analyze use cases and come up with a 'lazyness' strategy\n", | ||
| 970 | " - Do not create relationships you don't need in your mapped classes\n", | ||
| 971 | " - Session strategy should be based on a real world DB session use-case -> usually a new transaction is started, a series of jobs / queries are performed, the session is commited and finally closed. Context manager(s) may be a good idea.\n", | ||
| 972 | " - Sharing a session object (if possible) instead of spawning several session objects and using them in parallel may guard you from unwanted locks, connection / cursor leaks and bugs in general.\n", | ||
| 973 | " - An idea that can not be implemented using SQLAlchemy, may not always be a good idea :)" | ||
| 748 | ] | 974 | ] |
| 749 | } | 975 | } |
| 750 | ], | 976 | ], |
| @@ -765,7 +991,7 @@ | |||
| 765 | "name": "python", | 991 | "name": "python", |
| 766 | "nbconvert_exporter": "python", | 992 | "nbconvert_exporter": "python", |
| 767 | "pygments_lexer": "ipython3", | 993 | "pygments_lexer": "ipython3", |
| 768 | "version": "3.10.8" | 994 | "version": "3.11.5" |
| 769 | } | 995 | } |
| 770 | }, | 996 | }, |
| 771 | "nbformat": 4, | 997 | "nbformat": 4, |
