From 909ad126285bf298e4555c986b8c2f611386b6eb Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 09:51:03 +0200 Subject: [PATCH 01/19] Add files like in sql db tutorial --- papi/sqlapp/__init__.py | 0 papi/sqlapp/crud.py | 0 papi/sqlapp/database.py | 0 papi/sqlapp/models.py | 0 papi/sqlapp/schemas.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 papi/sqlapp/__init__.py create mode 100644 papi/sqlapp/crud.py create mode 100644 papi/sqlapp/database.py create mode 100644 papi/sqlapp/models.py create mode 100644 papi/sqlapp/schemas.py diff --git a/papi/sqlapp/__init__.py b/papi/sqlapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/papi/sqlapp/crud.py b/papi/sqlapp/crud.py new file mode 100644 index 0000000..e69de29 diff --git a/papi/sqlapp/database.py b/papi/sqlapp/database.py new file mode 100644 index 0000000..e69de29 diff --git a/papi/sqlapp/models.py b/papi/sqlapp/models.py new file mode 100644 index 0000000..e69de29 diff --git a/papi/sqlapp/schemas.py b/papi/sqlapp/schemas.py new file mode 100644 index 0000000..e69de29 From 17f59cb554c46750002cb537a2cbf56ac02b1ee2 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 09:52:29 +0200 Subject: [PATCH 02/19] sample db file --- papi/sqlapp/database.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/papi/sqlapp/database.py b/papi/sqlapp/database.py index e69de29..45a8b9f 100644 --- a/papi/sqlapp/database.py +++ b/papi/sqlapp/database.py @@ -0,0 +1,13 @@ +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker + +SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" +# SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db" + +engine = create_engine( + SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} +) +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) + +Base = declarative_base() From 84cd8c5ef4a366755e359f97f9f9c37468279732 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 09:56:15 +0200 Subject: [PATCH 03/19] poetry add sqlalchemy and load modules ok --- papi/main.py | 1 + poetry.lock | 129 ++++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 3 files changed, 130 insertions(+), 1 deletion(-) diff --git a/papi/main.py b/papi/main.py index 02d51e0..4e17ee9 100644 --- a/papi/main.py +++ b/papi/main.py @@ -6,6 +6,7 @@ from fastapi import FastAPI, Request, Body from collections import defaultdict from . import utils +from papi.sqlapp.database import Base app = FastAPI() diff --git a/poetry.lock b/poetry.lock index 576086d..31f6b00 100644 --- a/poetry.lock +++ b/poetry.lock @@ -161,6 +161,17 @@ python-versions = "*" [package.dependencies] pies = ">=2.6.0" +[[package]] +name = "greenlet" +version = "1.1.1" +description = "Lightweight in-process concurrent programming" +category = "main" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*" + +[package.extras] +docs = ["sphinx"] + [[package]] name = "h11" version = "0.12.0" @@ -414,6 +425,38 @@ urllib3 = ">=1.21.1,<1.27" socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"] +[[package]] +name = "sqlalchemy" +version = "1.4.25" +description = "Database Abstraction Library" +category = "main" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" + +[package.dependencies] +greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"} + +[package.extras] +aiomysql = ["greenlet (!=0.4.17)", "aiomysql"] +aiosqlite = ["typing_extensions (!=3.10.0.1)", "greenlet (!=0.4.17)", "aiosqlite"] +asyncio = ["greenlet (!=0.4.17)"] +asyncmy = ["greenlet (!=0.4.17)", "asyncmy (>=0.2.0)"] +mariadb_connector = ["mariadb (>=1.0.1)"] +mssql = ["pyodbc"] +mssql_pymssql = ["pymssql"] +mssql_pyodbc = ["pyodbc"] +mypy = ["sqlalchemy2-stubs", "mypy (>=0.910)"] +mysql = ["mysqlclient (>=1.4.0,<2)", "mysqlclient (>=1.4.0)"] +mysql_connector = ["mysql-connector-python"] +oracle = ["cx_oracle (>=7,<8)", "cx_oracle (>=7)"] +postgresql = ["psycopg2 (>=2.7)"] +postgresql_asyncpg = ["greenlet (!=0.4.17)", "asyncpg"] +postgresql_pg8000 = ["pg8000 (>=1.16.6)"] +postgresql_psycopg2binary = ["psycopg2-binary"] +postgresql_psycopg2cffi = ["psycopg2cffi"] +pymysql = ["pymysql (<1)", "pymysql"] +sqlcipher = ["sqlcipher3-binary"] + [[package]] name = "starlette" version = "0.14.2" @@ -525,7 +568,7 @@ python-versions = ">=3.7" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "a93c7b671d96a1d37821f7543c9f21cf4dd11fa1160006e1cf1dbcd57afc0804" +content-hash = "76743b3324f5a77d33919708ffcf63515ea12024f618338503683ca1a1d8405b" [metadata.files] asgiref = [ @@ -630,6 +673,58 @@ frosted = [ {file = "frosted-1.4.1-py2.py3-none-any.whl", hash = "sha256:c6a30ad502ea373f6fe4cafbcd896ece66948406b04365d14a3eb764cc529b07"}, {file = "frosted-1.4.1.tar.gz", hash = "sha256:d1e5d2b43a064b33c289b9a986a7425fd9a36bed8f519ca430ac7a0915e32b51"}, ] +greenlet = [ + {file = "greenlet-1.1.1-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:476ba9435afaead4382fbab8f1882f75e3fb2285c35c9285abb3dd30237f9142"}, + {file = "greenlet-1.1.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:44556302c0ab376e37939fd0058e1f0db2e769580d340fb03b01678d1ff25f68"}, + {file = "greenlet-1.1.1-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:40abb7fec4f6294225d2b5464bb6d9552050ded14a7516588d6f010e7e366dcc"}, + {file = "greenlet-1.1.1-cp27-cp27m-win32.whl", hash = "sha256:a11b6199a0b9dc868990456a2667167d0ba096c5224f6258e452bfbe5a9742c5"}, + {file = "greenlet-1.1.1-cp27-cp27m-win_amd64.whl", hash = "sha256:e22a82d2b416d9227a500c6860cf13e74060cf10e7daf6695cbf4e6a94e0eee4"}, + {file = "greenlet-1.1.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bad269e442f1b7ffa3fa8820b3c3aa66f02a9f9455b5ba2db5a6f9eea96f56de"}, + {file = "greenlet-1.1.1-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:8ddb38fb6ad96c2ef7468ff73ba5c6876b63b664eebb2c919c224261ae5e8378"}, + {file = "greenlet-1.1.1-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:84782c80a433d87530ae3f4b9ed58d4a57317d9918dfcc6a59115fa2d8731f2c"}, + {file = "greenlet-1.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ac991947ca6533ada4ce7095f0e28fe25d5b2f3266ad5b983ed4201e61596acf"}, + {file = "greenlet-1.1.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5317701c7ce167205c0569c10abc4bd01c7f4cf93f642c39f2ce975fa9b78a3c"}, + {file = "greenlet-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4870b018ca685ff573edd56b93f00a122f279640732bb52ce3a62b73ee5c4a92"}, + {file = "greenlet-1.1.1-cp310-cp310-win_amd64.whl", hash = "sha256:990e0f5e64bcbc6bdbd03774ecb72496224d13b664aa03afd1f9b171a3269272"}, + {file = "greenlet-1.1.1-cp35-cp35m-macosx_10_14_x86_64.whl", hash = "sha256:a414f8e14aa7bacfe1578f17c11d977e637d25383b6210587c29210af995ef04"}, + {file = "greenlet-1.1.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:e02780da03f84a671bb4205c5968c120f18df081236d7b5462b380fd4f0b497b"}, + {file = "greenlet-1.1.1-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:dfcb5a4056e161307d103bc013478892cfd919f1262c2bb8703220adcb986362"}, + {file = "greenlet-1.1.1-cp35-cp35m-win32.whl", hash = "sha256:655ab836324a473d4cd8cf231a2d6f283ed71ed77037679da554e38e606a7117"}, + {file = "greenlet-1.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:6ce9d0784c3c79f3e5c5c9c9517bbb6c7e8aa12372a5ea95197b8a99402aa0e6"}, + {file = "greenlet-1.1.1-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:3fc6a447735749d651d8919da49aab03c434a300e9f0af1c886d560405840fd1"}, + {file = "greenlet-1.1.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:8039f5fe8030c43cd1732d9a234fdcbf4916fcc32e21745ca62e75023e4d4649"}, + {file = "greenlet-1.1.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:fddfb31aa2ac550b938d952bca8a87f1db0f8dc930ffa14ce05b5c08d27e7fd1"}, + {file = "greenlet-1.1.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b97a807437b81f90f85022a9dcfd527deea38368a3979ccb49d93c9198b2c722"}, + {file = "greenlet-1.1.1-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:cf31e894dabb077a35bbe6963285d4515a387ff657bd25b0530c7168e48f167f"}, + {file = "greenlet-1.1.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4eae94de9924bbb4d24960185363e614b1b62ff797c23dc3c8a7c75bbb8d187e"}, + {file = "greenlet-1.1.1-cp36-cp36m-win32.whl", hash = "sha256:c1862f9f1031b1dee3ff00f1027fcd098ffc82120f43041fe67804b464bbd8a7"}, + {file = "greenlet-1.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:9b02e6039eafd75e029d8c58b7b1f3e450ca563ef1fe21c7e3e40b9936c8d03e"}, + {file = "greenlet-1.1.1-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:84488516639c3c5e5c0e52f311fff94ebc45b56788c2a3bfe9cf8e75670f4de3"}, + {file = "greenlet-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:3f8fc59bc5d64fa41f58b0029794f474223693fd00016b29f4e176b3ee2cfd9f"}, + {file = "greenlet-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:3e594015a2349ec6dcceda9aca29da8dc89e85b56825b7d1f138a3f6bb79dd4c"}, + {file = "greenlet-1.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e41f72f225192d5d4df81dad2974a8943b0f2d664a2a5cfccdf5a01506f5523c"}, + {file = "greenlet-1.1.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:75ff270fd05125dce3303e9216ccddc541a9e072d4fc764a9276d44dee87242b"}, + {file = "greenlet-1.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5cde7ee190196cbdc078511f4df0be367af85636b84d8be32230f4871b960687"}, + {file = "greenlet-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:f253dad38605486a4590f9368ecbace95865fea0f2b66615d121ac91fd1a1563"}, + {file = "greenlet-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:a91ee268f059583176c2c8b012a9fce7e49ca6b333a12bbc2dd01fc1a9783885"}, + {file = "greenlet-1.1.1-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:34e6675167a238bede724ee60fe0550709e95adaff6a36bcc97006c365290384"}, + {file = "greenlet-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:bf3725d79b1ceb19e83fb1aed44095518c0fcff88fba06a76c0891cfd1f36837"}, + {file = "greenlet-1.1.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:5c3b735ccf8fc8048664ee415f8af5a3a018cc92010a0d7195395059b4b39b7d"}, + {file = "greenlet-1.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e2002a59453858c7f3404690ae80f10c924a39f45f6095f18a985a1234c37334"}, + {file = "greenlet-1.1.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:04e1849c88aa56584d4a0a6e36af5ec7cc37993fdc1fda72b56aa1394a92ded3"}, + {file = "greenlet-1.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c8d4ed48eed7414ccb2aaaecbc733ed2a84c299714eae3f0f48db085342d5629"}, + {file = "greenlet-1.1.1-cp38-cp38-win32.whl", hash = "sha256:2f89d74b4f423e756a018832cd7a0a571e0a31b9ca59323b77ce5f15a437629b"}, + {file = "greenlet-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:d15cb6f8706678dc47fb4e4f8b339937b04eda48a0af1cca95f180db552e7663"}, + {file = "greenlet-1.1.1-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:b050dbb96216db273b56f0e5960959c2b4cb679fe1e58a0c3906fa0a60c00662"}, + {file = "greenlet-1.1.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:6e0696525500bc8aa12eae654095d2260db4dc95d5c35af2b486eae1bf914ccd"}, + {file = "greenlet-1.1.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:07e6d88242e09b399682b39f8dfa1e7e6eca66b305de1ff74ed9eb1a7d8e539c"}, + {file = "greenlet-1.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:98b491976ed656be9445b79bc57ed21decf08a01aaaf5fdabf07c98c108111f6"}, + {file = "greenlet-1.1.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:05e72db813c28906cdc59bd0da7c325d9b82aa0b0543014059c34c8c4ad20e16"}, + {file = "greenlet-1.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:090126004c8ab9cd0787e2acf63d79e80ab41a18f57d6448225bbfcba475034f"}, + {file = "greenlet-1.1.1-cp39-cp39-win32.whl", hash = "sha256:1796f2c283faab2b71c67e9b9aefb3f201fdfbee5cb55001f5ffce9125f63a45"}, + {file = "greenlet-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:4adaf53ace289ced90797d92d767d37e7cdc29f13bd3830c3f0a561277a4ae83"}, + {file = "greenlet-1.1.1.tar.gz", hash = "sha256:c0f22774cd8294078bdf7392ac73cf00bfa1e5e0ed644bd064fdabc5f2a2f481"}, +] h11 = [ {file = "h11-0.12.0-py3-none-any.whl", hash = "sha256:36a3cb8c0a032f56e2da7084577878a035d3b61d104230d4bd49c0c6b555a9c6"}, {file = "h11-0.12.0.tar.gz", hash = "sha256:47222cb6067e4a307d535814917cd98fd0a57b6788ce715755fa2b6c28b56042"}, @@ -825,6 +920,38 @@ requests = [ {file = "requests-2.26.0-py2.py3-none-any.whl", hash = "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24"}, {file = "requests-2.26.0.tar.gz", hash = "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"}, ] +sqlalchemy = [ + {file = "SQLAlchemy-1.4.25-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:a36ea43919e51b0de0c0bc52bcfdad7683f6ea9fb81b340cdabb9df0e045e0f7"}, + {file = "SQLAlchemy-1.4.25-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:75cd5d48389a7635393ff5a9214b90695c06b3d74912109c3b00ce7392b69c6c"}, + {file = "SQLAlchemy-1.4.25-cp27-cp27m-win32.whl", hash = "sha256:16ef07e102d2d4f974ba9b0d4ac46345a411ad20ad988b3654d59ff08e553b1c"}, + {file = "SQLAlchemy-1.4.25-cp27-cp27m-win_amd64.whl", hash = "sha256:a79abdb404d9256afb8aeaa0d3a4bc7d3b6d8b66103d8b0f2f91febd3909976e"}, + {file = "SQLAlchemy-1.4.25-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:7ad59e2e16578b6c1a2873e4888134112365605b08a6067dd91e899e026efa1c"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:a505ecc0642f52e7c65afb02cc6181377d833b7df0994ecde15943b18d0fa89c"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a28fe28c359835f3be20c89efd517b35e8f97dbb2ca09c6cf0d9ac07f62d7ef6"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:41a916d815a3a23cb7fff8d11ad0c9b93369ac074e91e428075e088fe57d5358"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:842c49dd584aedd75c2ee05f6c950730c3ffcddd21c5824ed0f820808387e1e3"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-win32.whl", hash = "sha256:6b602e3351f59f3999e9fb8b87e5b95cb2faab6a6ecdb482382ac6fdfbee5266"}, + {file = "SQLAlchemy-1.4.25-cp36-cp36m-win_amd64.whl", hash = "sha256:6400b22e4e41cc27623a9a75630b7719579cd9a3a2027bcf16ad5aaa9a7806c0"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:dd4ed12a775f2cde4519f4267d3601990a97d8ecde5c944ab06bfd6e8e8ea177"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7b7778a205f956755e05721eebf9f11a6ac18b2409bff5db53ce5fe7ede79831"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:08d9396a2a38e672133266b31ed39b2b1f2b5ec712b5bff5e08033970563316a"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e93978993a2ad0af43f132be3ea8805f56b2f2cd223403ec28d3e7d5c6d39ed1"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-win32.whl", hash = "sha256:0566a6e90951590c0307c75f9176597c88ef4be2724958ca1d28e8ae05ec8822"}, + {file = "SQLAlchemy-1.4.25-cp37-cp37m-win_amd64.whl", hash = "sha256:0b08a53e40b34205acfeb5328b832f44437956d673a6c09fce55c66ab0e54916"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:33a1e86abad782e90976de36150d910748b58e02cd7d35680d441f9a76806c18"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2ed67aae8cde4d32aacbdba4f7f38183d14443b714498eada5e5a7a37769c0b7"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1ebd69365717becaa1b618220a3df97f7c08aa68e759491de516d1c3667bba54"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:26b0cd2d5c7ea96d3230cb20acac3d89de3b593339c1447b4d64bfcf4eac1110"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-win32.whl", hash = "sha256:c211e8ec81522ce87b0b39f0cf0712c998d4305a030459a0e115a2b3dc71598f"}, + {file = "SQLAlchemy-1.4.25-cp38-cp38-win_amd64.whl", hash = "sha256:9a1df8c93a0dd9cef0839917f0c6c49f46c75810cf8852be49884da4a7de3c59"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:1b38db2417b9f7005d6ceba7ce2a526bf10e3f6f635c0f163e6ed6a42b5b62b2"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e37621b37c73b034997b5116678862f38ee70e5a054821c7b19d0e55df270dec"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:91cd87d1de0111eaca11ccc3d31af441c753fa2bc22df72e5009cfb0a1af5b03"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90fe429285b171bcc252e21515703bdc2a4721008d1f13aa5b7150336f8a8493"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-win32.whl", hash = "sha256:6003771ea597346ab1e97f2f58405c6cacbf6a308af3d28a9201a643c0ac7bb3"}, + {file = "SQLAlchemy-1.4.25-cp39-cp39-win_amd64.whl", hash = "sha256:9ebe49c3960aa2219292ea2e5df6acdc425fc828f2f3d50b4cfae1692bcb5f02"}, + {file = "SQLAlchemy-1.4.25.tar.gz", hash = "sha256:1adf3d25e2e33afbcd48cfad8076f9378793be43e7fec3e4334306cac6bec138"}, +] starlette = [ {file = "starlette-0.14.2-py3-none-any.whl", hash = "sha256:3c8e48e52736b3161e34c9f0e8153b4f32ec5d8995a3ee1d59410d92f75162ed"}, {file = "starlette-0.14.2.tar.gz", hash = "sha256:7d49f4a27f8742262ef1470608c59ddbc66baf37c148e938c7038e6bc7a998aa"}, diff --git a/pyproject.toml b/pyproject.toml index 4aaedb2..23c9219 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ authors = ["Colin Goutte "] python = "^3.9" fastapi = "^0.68.1" uvicorn = {extras = ["standard"], version = "^0.15.0"} +SQLAlchemy = "^1.4.25" [tool.poetry.dev-dependencies] pytest = "^5.2" From 0f547f9ee6562a43dbe8cdaa773489677939b9f2 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 10:14:05 +0200 Subject: [PATCH 04/19] Dynamic same thread verification --- papi/sqlapp/database.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/papi/sqlapp/database.py b/papi/sqlapp/database.py index 45a8b9f..53d97b6 100644 --- a/papi/sqlapp/database.py +++ b/papi/sqlapp/database.py @@ -6,7 +6,8 @@ SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" # SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db" engine = create_engine( - SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} + SQLALCHEMY_DATABASE_URL, + connect_args={"check_same_thread": not ("sqlite" in SQLALCHEMY_DATABASE_URL)}, ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) From 4f508bb5bb2bc5f706ebb5092652a0b718f20d36 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 10:30:58 +0200 Subject: [PATCH 05/19] Start models implementation --- papi/sqlapp/database.py | 1 + papi/sqlapp/models.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/papi/sqlapp/database.py b/papi/sqlapp/database.py index 53d97b6..9decfa0 100644 --- a/papi/sqlapp/database.py +++ b/papi/sqlapp/database.py @@ -2,6 +2,7 @@ from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker + SQLALCHEMY_DATABASE_URL = "sqlite:///./sql_app.db" # SQLALCHEMY_DATABASE_URL = "postgresql://user:password@postgresserver/db" diff --git a/papi/sqlapp/models.py b/papi/sqlapp/models.py index e69de29..691e422 100644 --- a/papi/sqlapp/models.py +++ b/papi/sqlapp/models.py @@ -0,0 +1,19 @@ +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, JSON +from sqlalchemy.orm import relationship + +from .database import Base + + +class Sonde(Base): + __tablename__ = "sonde" + id = Column(Integer, primary_key=True, index=True) + nom = Column(String, index=True) + identifiant = Column(String, index=True, unique=True, nullable=False) + # mesures = relationship("Mesure") + + +class Mesure(Base): + __tablename__ == "mesure" + id = Column(Integer, primary_key=True, index=True) + # sonde_id = Column(Integer, Foreignkey("sonde.id") + content = Column(JSON, nullable=False) From 2437c802fe8a5c001047f5ddf31d1d39cc18d191 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 10:48:33 +0200 Subject: [PATCH 06/19] Add crud views --- papi/main.py | 3 ++- papi/sqlapp/crud.py | 29 +++++++++++++++++++++++++++++ papi/sqlapp/models.py | 8 ++++---- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/papi/main.py b/papi/main.py index 4e17ee9..0204f79 100644 --- a/papi/main.py +++ b/papi/main.py @@ -6,7 +6,8 @@ from fastapi import FastAPI, Request, Body from collections import defaultdict from . import utils -from papi.sqlapp.database import Base + +from papi.sqlapp.database import Base, SessionLocal, engine app = FastAPI() diff --git a/papi/sqlapp/crud.py b/papi/sqlapp/crud.py index e69de29..baebabb 100644 --- a/papi/sqlapp/crud.py +++ b/papi/sqlapp/crud.py @@ -0,0 +1,29 @@ +from sqlalchemy.orm import Session + +from . import models + + +def get_sonde(db: Session, identifiant: str): + return ( + db.query(models.Sonde).filter(models.Sonde.identifiant == identifiant).first() + ) + + +def create_sonde(db: Session, identifiant: str, nom: str): + db_sonde = models.Sonde(identifiant=identifiant, nom=nom) + db.add(db_sonde) + db.commit() + db.refresh(db_sonde) + return db_sonde + + +def create_mesure(db: Session, sonde_id: int, content: dict): + db_mesure = models.Mesure(sonde_id=sonde_id, content=content) + db.add(db_mesure) + db.commit() + db.refesh(db_mesure) + return db_mesure + + +def get_mesure(db: Session, sonde_id: int): + return db.query(models.Mesure).filter(models.Mesure.sonde_id == sonde_id).all() diff --git a/papi/sqlapp/models.py b/papi/sqlapp/models.py index 691e422..6bde411 100644 --- a/papi/sqlapp/models.py +++ b/papi/sqlapp/models.py @@ -6,14 +6,14 @@ from .database import Base class Sonde(Base): __tablename__ = "sonde" - id = Column(Integer, primary_key=True, index=True) + sonde_id = Column(Integer, primary_key=True, index=True) nom = Column(String, index=True) identifiant = Column(String, index=True, unique=True, nullable=False) - # mesures = relationship("Mesure") + mesures = relationship("Mesure") class Mesure(Base): __tablename__ == "mesure" - id = Column(Integer, primary_key=True, index=True) - # sonde_id = Column(Integer, Foreignkey("sonde.id") + mesure_id = Column(Integer, primary_key=True, index=True) + sonde_id = Column(Integer, Foreignkey("sonde.id")) content = Column(JSON, nullable=False) From a14ad8f5f7f1421e1768f1abbbd4c2d75a57827d Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 10:50:45 +0200 Subject: [PATCH 07/19] Creates the db --- papi/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/papi/main.py b/papi/main.py index 0204f79..ce92a63 100644 --- a/papi/main.py +++ b/papi/main.py @@ -15,6 +15,8 @@ app = FastAPI() mesures = defaultdict(list) notifications = defaultdict(list) +Base.metadata.create_all(bind=engine) + class Notifier: @staticmethod From b5710b3dfb112ea43e58d5a991989a6ee85fe1ec Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:04:44 +0200 Subject: [PATCH 08/19] Typos --- papi/main.py | 1 + papi/sqlapp/models.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/papi/main.py b/papi/main.py index ce92a63..fc67284 100644 --- a/papi/main.py +++ b/papi/main.py @@ -8,6 +8,7 @@ from collections import defaultdict from . import utils from papi.sqlapp.database import Base, SessionLocal, engine +from papi.sqlapp import crud app = FastAPI() diff --git a/papi/sqlapp/models.py b/papi/sqlapp/models.py index 6bde411..fd66b54 100644 --- a/papi/sqlapp/models.py +++ b/papi/sqlapp/models.py @@ -13,7 +13,7 @@ class Sonde(Base): class Mesure(Base): - __tablename__ == "mesure" + __tablename__ = "mesure" mesure_id = Column(Integer, primary_key=True, index=True) - sonde_id = Column(Integer, Foreignkey("sonde.id")) + sonde_id = Column(Integer, ForeignKey("sonde.sonde_id")) content = Column(JSON, nullable=False) From 6b4c8b69b8f75fbba9494eb154166179e27cead5 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:05:09 +0200 Subject: [PATCH 09/19] db like in tutorial --- papi/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/papi/main.py b/papi/main.py index fc67284..a1fc243 100644 --- a/papi/main.py +++ b/papi/main.py @@ -19,6 +19,14 @@ notifications = defaultdict(list) Base.metadata.create_all(bind=engine) +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() + + class Notifier: @staticmethod def __call__(idsonde, changes): From 97c7ab970ca58554923981374e5049168a227555 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:45:23 +0200 Subject: [PATCH 10/19] Add orm models for Probes --- papi/main.py | 26 +++++++++++++++----------- papi/sqlapp/schemas.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/papi/main.py b/papi/main.py index a1fc243..9c1360d 100644 --- a/papi/main.py +++ b/papi/main.py @@ -1,7 +1,8 @@ -from typing import Optional +from typing import Optional, List from pydantic import BaseModel -from fastapi import FastAPI, Request, Body +from fastapi import FastAPI, Request, Body, Depends +from sqlalchemy.orm import Session from collections import defaultdict @@ -9,6 +10,7 @@ from . import utils from papi.sqlapp.database import Base, SessionLocal, engine from papi.sqlapp import crud +from papi.sqlapp import schemas app = FastAPI() @@ -36,14 +38,9 @@ class Notifier: ) -class Sonde(BaseModel): - identifiant: str - nom: str - - Notifier = Notifier() -sondes = {"test": Sonde(identifiant="test", nom="Testlocal")} +sondes = {"test": schemas.SondeBase(identifiant="test", nom="Testlocal")} def default_sample(): @@ -56,9 +53,16 @@ def read_root(): return {"msg": "Hello World"} -@app.post("/sonde/") -def post_sonde(sonde: Sonde): - sondes[sonde.identifiant] = sonde +@app.post("/sonde/", response_model=List[schemas.SondeBase]) +def post_sonde(sonde: schemas.SondeBase, db: Session = Depends(get_db)): + db_sonde = crud.get_sonde(db, identifiant=sonde.identifiant) + if not db_sonde: + db_sonde = crud.create_sonde( + db, sonde.identifiant, sonde.nom or sonde.identifiant + ) + sondes[sonde.identifiant] = schemas.SondeBase.from_orm( + db_sonde + ) # Attention au typage ici return list(sondes.values()) diff --git a/papi/sqlapp/schemas.py b/papi/sqlapp/schemas.py index e69de29..e9ab104 100644 --- a/papi/sqlapp/schemas.py +++ b/papi/sqlapp/schemas.py @@ -0,0 +1,22 @@ +from typing import List, Optional + +from pydantic import BaseModel + + +class SondeBase(BaseModel): + identifiant: str + nom: str + + class Config: + orm_mode = True + + +class SondeCreate(SondeBase): + pass + + +class Sonde(SondeBase): + sonde_id: int + + class Config: + orm_mode = True From cb5af32b6ae0cdf1d97978ca80d0c6db90b6bc61 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:48:25 +0200 Subject: [PATCH 11/19] Add response model for sondelist --- papi/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/papi/main.py b/papi/main.py index 9c1360d..bd09c0b 100644 --- a/papi/main.py +++ b/papi/main.py @@ -66,7 +66,7 @@ def post_sonde(sonde: schemas.SondeBase, db: Session = Depends(get_db)): return list(sondes.values()) -@app.get("/sonde/") +@app.get("/sonde/", response_model=List[schemas.SondeBase]) def list_sonde(): return [x for x in sondes.values()] From e1a4449ad4302429e3587d511dd469838c238731 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:55:27 +0200 Subject: [PATCH 12/19] walrus --- papi/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/papi/main.py b/papi/main.py index bd09c0b..a6631d2 100644 --- a/papi/main.py +++ b/papi/main.py @@ -77,8 +77,11 @@ def list_notification(idsonde: str): @app.post("/sonde/{idsonde}/") -def post_sonde_data(idsonde: str, body: dict = Body(...)): - if idsonde not in sondes: +def post_sonde_data( + idsonde: str, body: dict = Body(...), db: Session = Depends(get_db) +): + + if not (sonde := crud.get_sonde(db, idsonde)): return mesures_ = mesures[idsonde] From 2447734471c9eab2aa12098265c58e964dbfe2f7 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 11:58:19 +0200 Subject: [PATCH 13/19] add failfat directive --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 7016c80..1cae41e 100644 --- a/Makefile +++ b/Makefile @@ -31,3 +31,7 @@ test: dtest: poetry run pytest -s --pdb --cov=. --cov-report=term-missing:skip-covered . +.ONESHELL: +qtest: + poetry run pytest -sxv --ff --lf . + From 7888ec9f4493d9b332cc368415eaf7311562e32d Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 12:37:24 +0200 Subject: [PATCH 14/19] wip --- papi/main.py | 17 +++++++++-------- papi/sqlapp/crud.py | 2 +- papi/sqlapp/schemas.py | 7 +++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/papi/main.py b/papi/main.py index a6631d2..857f580 100644 --- a/papi/main.py +++ b/papi/main.py @@ -80,18 +80,19 @@ def list_notification(idsonde: str): def post_sonde_data( idsonde: str, body: dict = Body(...), db: Session = Depends(get_db) ): - if not (sonde := crud.get_sonde(db, idsonde)): return - - mesures_ = mesures[idsonde] + mesures_ = [] + mesures_.extend(crud.get_mesure(db, sonde.identifiant)) if not mesures_: - mesures_.append(default_sample()) - mesures_.append(body) - + mesures_.append( + crud.create_mesure(db, sonde.sonde_id, content=default_sample()) + ) + mesures_.append(crud.create_mesure(db, sonde.sonde_id, content=body)) + mesures[idsonde] = mesures_ date = body["date"] - previous = utils.prepare(mesures_[-2]) - present = utils.prepare(mesures_[-1]) + previous = utils.prepare(mesures_[-2].content) + present = utils.prepare(mesures_[-1].content) all_channels = sorted(set((*previous["channels"], *present["channels"]))) diff = utils.compare(all_channels, previous, present) diff --git a/papi/sqlapp/crud.py b/papi/sqlapp/crud.py index baebabb..c683098 100644 --- a/papi/sqlapp/crud.py +++ b/papi/sqlapp/crud.py @@ -21,7 +21,7 @@ def create_mesure(db: Session, sonde_id: int, content: dict): db_mesure = models.Mesure(sonde_id=sonde_id, content=content) db.add(db_mesure) db.commit() - db.refesh(db_mesure) + db.refresh(db_mesure) return db_mesure diff --git a/papi/sqlapp/schemas.py b/papi/sqlapp/schemas.py index e9ab104..0be45bc 100644 --- a/papi/sqlapp/schemas.py +++ b/papi/sqlapp/schemas.py @@ -20,3 +20,10 @@ class Sonde(SondeBase): class Config: orm_mode = True + + +class Mesure(BaseModel): + content: dict + + class Config: + orm_mode = True From fb26b5ac2bd6bb31e62fb88a3d45a6c811d26cc0 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 13:32:41 +0200 Subject: [PATCH 15/19] Wip: un peu rapide le refacto --- Makefile | 9 ++++++--- papi/main.py | 6 +++--- papi/sqlapp/crud.py | 14 +++++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 1cae41e..5756e3f 100644 --- a/Makefile +++ b/Makefile @@ -22,16 +22,19 @@ kill_server: dev_serve: poetry run uvicorn papi.main:app --reload +cleandb: + rm sql_app.db || echo ls + .ONESHELL: -test: +test: cleandb poetry run pytest --cov=. --cov-report=term-missing:skip-covered . .ONESHELL: -dtest: +dtest: cleandb poetry run pytest -s --pdb --cov=. --cov-report=term-missing:skip-covered . .ONESHELL: -qtest: +qtest: cleandb poetry run pytest -sxv --ff --lf . diff --git a/papi/main.py b/papi/main.py index 857f580..e35b033 100644 --- a/papi/main.py +++ b/papi/main.py @@ -131,9 +131,9 @@ def historique(idsonde): print(len(mesures[idsonde])) for previous, present in zip(mesures[idsonde], mesures[idsonde][1:]): - date = present["date"] - previous = utils.prepare(previous) - present = utils.prepare(present) + date = present.content["date"] + previous = utils.prepare(previous.content) + present = utils.prepare(present.content) all_channels = sorted(set((*previous["channels"], *present["channels"]))) diff = utils.compare(all_channels, previous, present) diff --git a/papi/sqlapp/crud.py b/papi/sqlapp/crud.py index c683098..5018e20 100644 --- a/papi/sqlapp/crud.py +++ b/papi/sqlapp/crud.py @@ -4,9 +4,9 @@ from . import models def get_sonde(db: Session, identifiant: str): - return ( - db.query(models.Sonde).filter(models.Sonde.identifiant == identifiant).first() - ) + q = db.query(models.Sonde) + q = q.filter(models.Sonde.identifiant == identifiant) + return q.first() def create_sonde(db: Session, identifiant: str, nom: str): @@ -25,5 +25,9 @@ def create_mesure(db: Session, sonde_id: int, content: dict): return db_mesure -def get_mesure(db: Session, sonde_id: int): - return db.query(models.Mesure).filter(models.Mesure.sonde_id == sonde_id).all() +def get_mesure(db: Session, sonde_id: int, only_last=False): + q = db.query(models.Mesure).filter(models.Mesure.sonde_id == sonde_id) + if not only_last: + return q.all() + else: + return [q.all()[-1]] # order by id desc limit 1 From 9265cae4947a0c9dafecd0d034940f5349458303 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 13:34:34 +0200 Subject: [PATCH 16/19] Fix type --- papi/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/papi/main.py b/papi/main.py index e35b033..5974e89 100644 --- a/papi/main.py +++ b/papi/main.py @@ -119,6 +119,7 @@ def get_rapport(idsonde): except IndexError: return else: + last = last.content last = utils.prepare(last) for name, data in sorted( last["channels"].items(), key=lambda text: float(text[0].split("#")[0]) From 81cca85888222916e53feefe512b993ca6d4a9bc Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 13:43:34 +0200 Subject: [PATCH 17/19] Fix first run side effect tesT --- papi/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/papi/main.py b/papi/main.py index 5974e89..c6b1b63 100644 --- a/papi/main.py +++ b/papi/main.py @@ -90,6 +90,7 @@ def post_sonde_data( ) mesures_.append(crud.create_mesure(db, sonde.sonde_id, content=body)) mesures[idsonde] = mesures_ + date = body["date"] previous = utils.prepare(mesures_[-2].content) present = utils.prepare(mesures_[-1].content) @@ -106,7 +107,7 @@ def post_sonde_data( Notifier(idsonde, content) return { "count": len(mesures_) - if mesures_[0] != default_sample() + if "date" in mesures_[0].content.keys() else len(mesures_) - 1, "notify": content, } From 55a5173b6b13ef7e68ac6e268a8774c79e834b3f Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 14:33:16 +0200 Subject: [PATCH 18/19] -fix getting values --- papi/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/papi/main.py b/papi/main.py index c6b1b63..b08ac0a 100644 --- a/papi/main.py +++ b/papi/main.py @@ -129,10 +129,12 @@ def get_rapport(idsonde): @app.get("/sonde/{idsonde}/historique") -def historique(idsonde): - print(len(mesures[idsonde])) +def historique(idsonde, db: Session = Depends(get_db)): + if not (sonde := crud.get_sonde(db, idsonde)): + return + mesures = sonde.mesures - for previous, present in zip(mesures[idsonde], mesures[idsonde][1:]): + for previous, present in zip(mesures, mesures[1:]): date = present.content["date"] previous = utils.prepare(previous.content) present = utils.prepare(present.content) From 4d2f639f7f716aefe25b28f2dc4753e67b9a6289 Mon Sep 17 00:00:00 2001 From: Colin Goutte Date: Wed, 29 Sep 2021 14:33:29 +0200 Subject: [PATCH 19/19] Sqlalchemy homegnity --- papi/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/papi/main.py b/papi/main.py index b08ac0a..aa664e6 100644 --- a/papi/main.py +++ b/papi/main.py @@ -82,8 +82,7 @@ def post_sonde_data( ): if not (sonde := crud.get_sonde(db, idsonde)): return - mesures_ = [] - mesures_.extend(crud.get_mesure(db, sonde.identifiant)) + mesures_ = [x for x in sonde.mesures] if not mesures_: mesures_.append( crud.create_mesure(db, sonde.sonde_id, content=default_sample())