From 13c2b3841cf3e08185928f8c9580c2e6f6fcf9eb Mon Sep 17 00:00:00 2001 From: RJ Santana Date: Tue, 19 Oct 2021 16:50:46 -0600 Subject: [PATCH] removed asyncpg from dep (#14) * removed asyncpg from dep * Version bumped to 0.15.0 * updated the lock file Co-authored-by: ns-circle-ci --- README.md | 7 -- poetry.lock | 140 ++++++++++-------------------- pynocular/__init__.py | 2 +- pynocular/engines.py | 196 +++--------------------------------------- pyproject.toml | 5 +- 5 files changed, 57 insertions(+), 293 deletions(-) diff --git a/README.md b/README.md index 97727a0..d0a9fc6 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,6 @@ connection_string = f"postgresql://{db_user_name}:{db_user_password}@localhost:5 db_info = DBInfo(connection_string) ``` -Pynocular uses the asynchronous engine provided by aiopg to connect to your database. You can choose to use a -different engine by providing a different engine_type value to `DBInfo`. -```python -db_info = DBInfo(connection_string, engine_type=DatabaseAlias.asyncpg_engine) -``` -All other engine options are experimental and do not support all of the functionality Pynocular provides. - #### Object Management Once you define a `db_info` object, you are ready to decorate your Pydantic models and interact with your database! diff --git a/poetry.lock b/poetry.lock index 5cd75c1..ca40fde 100644 --- a/poetry.lock +++ b/poetry.lock @@ -19,7 +19,7 @@ contextvars = {version = "2.4", markers = "python_version < \"3.7\""} [[package]] name = "aiopg" -version = "1.3.1" +version = "1.3.2" description = "Postgres integration with asyncio." category = "main" optional = false @@ -53,34 +53,6 @@ category = "main" optional = false python-versions = ">=3.5.3" -[[package]] -name = "asyncpg" -version = "0.24.0" -description = "An asyncio PostgreSQL driver" -category = "main" -optional = false -python-versions = ">=3.6.0" - -[package.dependencies] -typing-extensions = {version = ">=3.7.4.3", markers = "python_version < \"3.8\""} - -[package.extras] -dev = ["Cython (>=0.29.24,<0.30.0)", "pytest (>=6.0)", "Sphinx (>=4.1.2,<4.2.0)", "sphinxcontrib-asyncio (>=0.3.0,<0.4.0)", "sphinx-rtd-theme (>=0.5.2,<0.6.0)", "pycodestyle (>=2.7.0,<2.8.0)", "flake8 (>=3.9.2,<3.10.0)", "uvloop (>=0.15.3)"] -docs = ["Sphinx (>=4.1.2,<4.2.0)", "sphinxcontrib-asyncio (>=0.3.0,<0.4.0)", "sphinx-rtd-theme (>=0.5.2,<0.6.0)"] -test = ["pycodestyle (>=2.7.0,<2.8.0)", "flake8 (>=3.9.2,<3.10.0)", "uvloop (>=0.15.3)"] - -[[package]] -name = "asyncpgsa" -version = "0.24.0" -description = "sqlalchemy support for asyncpg" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -asyncpg = "*" -sqlalchemy = "*" - [[package]] name = "atomicwrites" version = "1.4.0" @@ -103,14 +75,6 @@ docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] -[[package]] -name = "backoff" -version = "1.11.1" -description = "Function decoration for backoff and retry" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - [[package]] name = "backports.entry-points-selectable" version = "1.1.0" @@ -674,7 +638,7 @@ python-versions = ">=3.5" [[package]] name = "sqlalchemy" -version = "1.4.25" +version = "1.4.26" description = "Database Abstraction Library" category = "main" optional = false @@ -689,7 +653,7 @@ psycopg2-binary = {version = "*", optional = true, markers = "extra == \"postgre 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)"] +asyncmy = ["greenlet (!=0.4.17)", "asyncmy (>=0.2.3)"] mariadb_connector = ["mariadb (>=1.0.1)"] mssql = ["pyodbc"] mssql_pymssql = ["pymssql"] @@ -812,7 +776,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = "^3.6.5" -content-hash = "04c06724720822735db353ed800089ceb3d26691199e1ee8bf29d70f9f9367b3" +content-hash = "fb83413d7c2ff4d79caba96393787e7c1904432b482e87d4d075c9d0a15c2760" [metadata.files] aenum = [ @@ -825,8 +789,8 @@ aiocontextvars = [ {file = "aiocontextvars-0.2.2.tar.gz", hash = "sha256:f027372dc48641f683c559f247bd84962becaacdc9ba711d583c3871fb5652aa"}, ] aiopg = [ - {file = "aiopg-1.3.1-py3-none-any.whl", hash = "sha256:7a3fb1eb399ab0bb0335ddca66b51de31f6bb2251b5af2a45e7fec20040e5eac"}, - {file = "aiopg-1.3.1.tar.gz", hash = "sha256:837fb1cbc84fc95be78e4b1a1e3ff176eee836051b957304b10b18ee30f999b6"}, + {file = "aiopg-1.3.2-py3-none-any.whl", hash = "sha256:42f9e49bc7fe7b1f46cd9208c0ffc0bba4384a3eb11dda8eabe22c530048eb6d"}, + {file = "aiopg-1.3.2.tar.gz", hash = "sha256:864df77edb9897cea6318a0d2e61f9b08692f2f0a150b7051fc2bde0997b23fd"}, ] arrow = [ {file = "arrow-1.1.1-py3-none-any.whl", hash = "sha256:77a60a4db5766d900a2085ce9074c5c7b8e2c99afeaa98ad627637ff6f292510"}, @@ -836,25 +800,6 @@ async-timeout = [ {file = "async-timeout-3.0.1.tar.gz", hash = "sha256:0c3c816a028d47f659d6ff5c745cb2acf1f966da1fe5c19c77a70282b25f4c5f"}, {file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"}, ] -asyncpg = [ - {file = "asyncpg-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c4fc0205fe4ddd5aeb3dfdc0f7bafd43411181e1f5650189608e5971cceacff1"}, - {file = "asyncpg-0.24.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:a7095890c96ba36f9f668eb552bb020dddb44f8e73e932f8573efc613ee83843"}, - {file = "asyncpg-0.24.0-cp310-cp310-win_amd64.whl", hash = "sha256:8ff5073d4b654e34bd5eaadc01dc4d68b8a9609084d835acd364cd934190a08d"}, - {file = "asyncpg-0.24.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:e36c6806883786b19551bb70a4882561f31135dc8105a59662e0376cf5b2cbc5"}, - {file = "asyncpg-0.24.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:ddffcb85227bf39cd1bedd4603e0082b243cf3b14ced64dce506a15b05232b83"}, - {file = "asyncpg-0.24.0-cp37-cp37m-win_amd64.whl", hash = "sha256:41704c561d354bef01353835a7846e5606faabbeb846214dfcf666cf53319f18"}, - {file = "asyncpg-0.24.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:29ef6ae0a617fc13cc2ac5dc8e9b367bb83cba220614b437af9b67766f4b6b20"}, - {file = "asyncpg-0.24.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:eed43abc6ccf1dc02e0d0efc06ce46a411362f3358847c6b0ec9a43426f91ece"}, - {file = "asyncpg-0.24.0-cp38-cp38-win_amd64.whl", hash = "sha256:129d501f3d30616afd51eb8d3142ef51ba05374256bd5834cec3ef4956a9b317"}, - {file = "asyncpg-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:a458fc69051fbb67d995fdda46d75a012b5d6200f91e17d23d4751482640ed4c"}, - {file = "asyncpg-0.24.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:556b0e92e2b75dc028b3c4bc9bd5162ddf0053b856437cf1f04c97f9c6837d03"}, - {file = "asyncpg-0.24.0-cp39-cp39-win_amd64.whl", hash = "sha256:a738f4807c853623d3f93f0fea11f61be6b0e5ca16ea8aeb42c2c7ee742aa853"}, - {file = "asyncpg-0.24.0.tar.gz", hash = "sha256:dd2fa063c3344823487d9ddccb40802f02622ddf8bf8a6cc53885ee7a2c1c0c6"}, -] -asyncpgsa = [ - {file = "asyncpgsa-0.24.0-py3-none-any.whl", hash = "sha256:f5f52b9227577ae69a625f153c3075c937bf2edea37f9a53c002fa8797620427"}, - {file = "asyncpgsa-0.24.0.tar.gz", hash = "sha256:a6fdb83cd0d5716800489243e5a7691404c0cceaf008fcfe7939e7579e890f4b"}, -] atomicwrites = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, @@ -863,10 +808,6 @@ attrs = [ {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, ] -backoff = [ - {file = "backoff-1.11.1-py2.py3-none-any.whl", hash = "sha256:61928f8fa48d52e4faa81875eecf308eccfb1016b018bb6bd21e05b5d90a96c5"}, - {file = "backoff-1.11.1.tar.gz", hash = "sha256:ccb962a2378418c667b3c979b504fdeb7d9e0d29c0579e3b13b86467177728cb"}, -] "backports.entry-points-selectable" = [ {file = "backports.entry_points_selectable-1.1.0-py2.py3-none-any.whl", hash = "sha256:a6d9a871cde5e15b4c4a53e3d43ba890cc6861ec1332c9c2428c92f977192acc"}, {file = "backports.entry_points_selectable-1.1.0.tar.gz", hash = "sha256:988468260ec1c196dab6ae1149260e2f5472c9110334e5d51adcb77867361f6a"}, @@ -1133,6 +1074,11 @@ pre-commit = [ ] psycopg2-binary = [ {file = "psycopg2-binary-2.9.1.tar.gz", hash = "sha256:b0221ca5a9837e040ebf61f48899926b5783668b7807419e4adae8175a31f773"}, + {file = "psycopg2_binary-2.9.1-cp310-cp310-macosx_10_14_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", hash = "sha256:24b0b6688b9f31a911f2361fe818492650795c9e5d3a1bc647acbd7440142a4f"}, + {file = "psycopg2_binary-2.9.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:542875f62bc56e91c6eac05a0deadeae20e1730be4c6334d8f04c944fcd99759"}, + {file = "psycopg2_binary-2.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:661509f51531ec125e52357a489ea3806640d0ca37d9dada461ffc69ee1e7b6e"}, + {file = "psycopg2_binary-2.9.1-cp310-cp310-manylinux_2_24_aarch64.whl", hash = "sha256:d92272c7c16e105788efe2cfa5d680f07e34e0c29b03c1908f8636f55d5f915a"}, + {file = "psycopg2_binary-2.9.1-cp310-cp310-manylinux_2_24_ppc64le.whl", hash = "sha256:736b8797b58febabb85494142c627bd182b50d2a7ec65322983e71065ad3034c"}, {file = "psycopg2_binary-2.9.1-cp36-cp36m-macosx_10_14_x86_64.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl", hash = "sha256:c250a7ec489b652c892e4f0a5d122cc14c3780f9f643e1a326754aedf82d9a76"}, {file = "psycopg2_binary-2.9.1-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aef9aee84ec78af51107181d02fe8773b100b01c5dfde351184ad9223eab3698"}, {file = "psycopg2_binary-2.9.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:123c3fb684e9abfc47218d3784c7b4c47c8587951ea4dd5bc38b6636ac57f616"}, @@ -1297,36 +1243,40 @@ smmap = [ {file = "smmap-4.0.0.tar.gz", hash = "sha256:7e65386bd122d45405ddf795637b7f7d2b532e7e401d46bbe3fb49b9986d5182"}, ] 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"}, + {file = "SQLAlchemy-1.4.26-cp27-cp27m-macosx_10_14_x86_64.whl", hash = "sha256:c2f2114b0968a280f94deeeaa31cfbac9175e6ac7bd3058b3ce6e054ecd762b3"}, + {file = "SQLAlchemy-1.4.26-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:91efbda4e6d311812f23996242bad7665c1392209554f8a31ec6db757456db5c"}, + {file = "SQLAlchemy-1.4.26-cp27-cp27m-win32.whl", hash = "sha256:de996756d894a2d52c132742e3b6d64ecd37e0919ddadf4dc3981818777c7e67"}, + {file = "SQLAlchemy-1.4.26-cp27-cp27m-win_amd64.whl", hash = "sha256:463ef692259ff8189be42223e433542347ae17e33f91c1013e9c5c64e2798088"}, + {file = "SQLAlchemy-1.4.26-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:c757ba1279b85b3460e72e8b92239dae6f8b060a75fb24b3d9be984dd78cfa55"}, + {file = "SQLAlchemy-1.4.26-cp310-cp310-macosx_10_14_x86_64.whl", hash = "sha256:c24c01dcd03426a5fe5ee7af735906bec6084977b9027a3605d11d949a565c01"}, + {file = "SQLAlchemy-1.4.26-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c46f013ff31b80cbe36410281675e1fb4eaf3e25c284fd8a69981c73f6fa4cb4"}, + {file = "SQLAlchemy-1.4.26-cp310-cp310-win32.whl", hash = "sha256:7ef421c3887b39c6f352e5022a53ac18de8387de331130481cb956b2d029cad6"}, + {file = "SQLAlchemy-1.4.26-cp310-cp310-win_amd64.whl", hash = "sha256:908fad32c53b17aad12d722379150c3c5317c422437e44032256a77df1746292"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:1ef37c9ec2015ce2f0dc1084514e197f2f199d3dc3514190db7620b78e6004c8"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:090536fd23bf49077ee94ff97142bc5ee8bad24294c3d7c8d5284267c885dde7"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:e700d48056475d077f867e6a36e58546de71bdb6fdc3d34b879e3240827fefab"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:295b90efef1278f27fe27d94a45460ae3c17f5c5c2b32c163e29c359740a1599"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-win32.whl", hash = "sha256:cc6b21f19bc9d4cd77cbcba5f3b260436ce033f1053cea225b6efea2603d201e"}, + {file = "SQLAlchemy-1.4.26-cp36-cp36m-win_amd64.whl", hash = "sha256:ba84026e84379326bbf2f0c50792f2ae56ab9c01937df5597b6893810b8ca369"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:f1e97c5f36b94542f72917b62f3a2f92be914b2cf33b80fa69cede7529241d2a"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4c185c928e2638af9bae13acc3f70e0096eac76471a1101a10f96b80666b8270"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:bca660b76672e15d70a7dba5e703e1ce451a0257b6bd2028e62b0487885e8ae9"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ff8f91a7b1c4a1c7772caa9efe640f2768828897044748f2458b708f1026e2d4"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-win32.whl", hash = "sha256:a95bf9c725012dcd7ea3cac16bf647054e0d62b31d67467d228338e6a163e4ff"}, + {file = "SQLAlchemy-1.4.26-cp37-cp37m-win_amd64.whl", hash = "sha256:07ac4461a1116b317519ddf6f34bcb00b011b5c1370ebeaaf56595504ffc7e84"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:5039faa365e7522a8eb4736a54afd24a7e75dcc33b81ab2f0e6c456140f1ad64"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7e8ef103eaa72a857746fd57dda5b8b5961e8e82a528a3f8b7e2884d8506f0b7"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:31f4426cfad19b5a50d07153146b2bcb372a279975d5fa39f98883c0ef0f3313"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2feb028dc75e13ba93456a42ac042b255bf94dbd692bf80b47b22653bb25ccf8"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-win32.whl", hash = "sha256:2ce42ad1f59eb85c55c44fb505f8854081ee23748f76b62a7f569cfa9b6d0604"}, + {file = "SQLAlchemy-1.4.26-cp38-cp38-win_amd64.whl", hash = "sha256:dbf588ab09e522ac2cbd010919a592c6aae2f15ccc3cd9a96d01c42fbc13f63e"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-macosx_10_14_x86_64.whl", hash = "sha256:a6506c17b0b6016656783232d0bdd03fd333f1f654d51a14d93223f953903646"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4a882dedb9dfa6f33524953c3e3d72bcf518a5defd6d5863150a821928b19ad3"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1dee515578d04bc80c4f9a8c8cfe93f455db725059e885f1b1da174d91c4d077"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3c0c5f54560a92691d54b0768d67b4d3159e514b426cfcb1258af8c195577e8f"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-win32.whl", hash = "sha256:b86f762cee3709722ab4691981958cbec475ea43406a6916a7ec375db9cbd9e9"}, + {file = "SQLAlchemy-1.4.26-cp39-cp39-win_amd64.whl", hash = "sha256:5c6774b34782116ad9bdec61c2dbce9faaca4b166a0bc8e7b03c2b870b121d94"}, + {file = "SQLAlchemy-1.4.26.tar.gz", hash = "sha256:6bc7f9d7d90ef55e8c6db1308a8619cd8f40e24a34f759119b95e7284dca351a"}, ] text-unidecode = [ {file = "text-unidecode-1.3.tar.gz", hash = "sha256:bad6603bb14d279193107714b288be206cac565dfa49aa5b105294dd5c4aab93"}, diff --git a/pynocular/__init__.py b/pynocular/__init__.py index 56169e6..cac9f25 100644 --- a/pynocular/__init__.py +++ b/pynocular/__init__.py @@ -1,5 +1,5 @@ """Lightweight ORM that lets you query your database using Pydantic models and asyncio""" -__version__ = "0.14.0" +__version__ = "0.15.0" from pynocular.engines import DatabaseType, DBInfo diff --git a/pynocular/engines.py b/pynocular/engines.py index 8c93d12..f79a453 100644 --- a/pynocular/engines.py +++ b/pynocular/engines.py @@ -3,30 +3,20 @@ from enum import Enum from functools import wraps import logging -import ssl from typing import Any, Callable, Dict, NamedTuple, Optional, Tuple, Union -from urllib.parse import parse_qs from aiopg import Connection as AIOPGConnection from aiopg.sa import create_engine, Engine -from asyncpg.connection import Connection as AsyncPGConnection -from asyncpg.exceptions import ConnectionDoesNotExistError -from asyncpg.pool import Pool -from asyncpgsa import create_pool -import backoff -from sqlalchemy import create_engine as create_engine_sync -from sqlalchemy.engine import Engine as SyncEngine from pynocular.aiopg_transaction import ( ConditionalTransaction, transaction as Transaction, ) -from pynocular.config import DB_POOL_MAX_SIZE, DB_POOL_MIN_SIZE, POOL_RECYCLE +from pynocular.config import POOL_RECYCLE logger = logging.getLogger(__name__) _engines: Dict[Tuple[str, str], Engine] = {} -_pools: Dict[Tuple[str, str], Pool] = {} async def get_aiopg_engine( @@ -85,134 +75,10 @@ async def get_aiopg_engine( return engine -def get_psycopg_engine( - conn_str: str, force: bool = False, if_exists: bool = False -) -> Optional[SyncEngine]: - """Returns the psycopg SQLAlchemy connection engine for a given connection string. - - Similar to :py:func:`get_engine` except that a synchronous SQLAlchemy engine is - created instead. - - Args: - conn_str: The connection string for the engine - force: Force the creation of the engine regardless of the cache - if_exists: Only return the engine if it already exists - - Returns: - SQLAlchemy engine for the connection string - - """ - global _engines - logger.debug("Attempting to get sync DB engine") - cache_key = ("sync", conn_str) - engine = _engines.get(cache_key) - - if if_exists and engine is None: - return None - - if engine is None or force: - engine = create_engine_sync(conn_str, pool_recycle=POOL_RECYCLE) - _engines[cache_key] = engine - logger.debug(f"Sync DB engine created successfully: {engine}") - - logger.debug("Sync DB engine retrieved") - return engine - - -@backoff.on_exception( - backoff.expo, ConnectionDoesNotExistError, max_tries=8, jitter=backoff.random_jitter -) -async def get_asyncpgsa_pool( - conn_str: str, - force: bool = False, - application_name: str = None, - if_exists: bool = False, -) -> Optional[Pool]: - """Returns the asyncpgsa connection pool for a given connection string. - - This function lazily creates the connection pool if it doesn't already - exist. Callers of this function shouldn't close the pool. It will be - closed automatically when the process exits. - - This function exists to keep a single pool per database, which prevents us - from maxing out the number of connections the database server will give us. - - We include the hash of the event loop in the cache key because otherwise, if the - event loop closes, the cached pool will raise an exception when it's used. - - Args: - conn_str: The connection string for the engine - force: Force the creation of the pool regardless of the cache - application_name: Arbitrary string that shows up in queries to the - ``pg_stat_activity`` view for tracking the source of database connections. - if_exists: Only return the pool if it already exists - - Returns: - The aiopgsa pool for that connection - - """ - global _pools - logger.debug("Attempting to get/create the db pool") - loop_hash = str(hash(asyncio.get_event_loop())) - cache_key = (loop_hash, conn_str) - pool = _pools.get(cache_key) - - # Split the query params from the connection string - parsed_conn = conn_str.split("?") - conn_str = parsed_conn[0] - ssl_cert_path = None - - if len(parsed_conn) > 1: - query_params = parse_qs(parsed_conn[1]) - if "sslrootcert" in query_params: - ssl_cert_path = query_params["sslrootcert"][0] - - if if_exists and pool is None: - return None - - if pool is None or force or pool._closed: - options = {} - if application_name is not None: - options["server_settings"] = {"application_name": application_name} - if ssl_cert_path is not None: - ssl_context = ssl.create_default_context() - ssl_context.load_verify_locations(cafile=ssl_cert_path) - options["ssl"] = ssl_context # type: ignore - try: - pool = await create_pool( - conn_str, - min_size=DB_POOL_MIN_SIZE, - max_size=DB_POOL_MAX_SIZE, - max_inactive_connection_lifetime=POOL_RECYCLE, - **options, - ) - except Exception as e: - logger.error( - { - "description": "Failed to create asyncpg connection pool", - "application_name": application_name, - "min_size": DB_POOL_MIN_SIZE, - "max_size": DB_POOL_MAX_SIZE, - "force": force, - "if_exists": if_exists, - "error_msg": repr(e), - } - ) - raise e - - _pools[cache_key] = pool - logger.debug(f"Created new asyncpg pool: {pool}") - - logger.debug("Connection pool successfully retrieved") - return pool - - class DatabaseType(Enum): """Database type to differentiate engines and pools""" aiopg_engine = "aiopg_engine" - asyncpgsa_pool = "asyncpgsa_pool" - sqlalchemy_engine = "sqlalchemy_engine" class DBInfo(NamedTuple): @@ -227,14 +93,14 @@ class DBEngine: """Wrapper over database engine types""" @classmethod - async def _get_engine_or_pool( + async def _get_engine( cls, db_info: DBInfo, force: bool = False, application_name: str = None, if_exists: bool = False, - ) -> Optional[Union[Engine, SyncEngine, Pool]]: - """Get an aiopg engine or asyncpg pool depending on the database configuration. + ) -> Optional[Engine]: + """Get an async db engine depending on the database configuration. Args: db_info: Information for making the database connection @@ -259,24 +125,13 @@ async def _get_engine_or_pool( application_name=application_name, if_exists=if_exists, ) - elif db_info.engine_type == DatabaseType.asyncpgsa_pool: - return await get_asyncpgsa_pool( - db_info.connection_string, - force=force, - application_name=application_name, - if_exists=if_exists, - ) - elif db_info.engine_type == DatabaseType.sqlalchemy_engine: - return get_psycopg_engine( - db_info.connection_string, force=force, if_exists=if_exists - ) raise ValueError(f"Unsupported database type: {db_info.engine_type}") @classmethod async def get_engine( cls, db_info: DBInfo, force: bool = False, application_name: str = None - ) -> Union[Engine, SyncEngine]: + ) -> Union[Engine]: """Get a SQLAlchemy connection engine for a given database alias. See :py:func:`.get_engine` for more details. @@ -292,39 +147,12 @@ async def get_engine( database engine """ - return await cls._get_engine_or_pool( - db_info, force=force, application_name=application_name - ) - - @classmethod - async def get_pool( - cls, db_info: DBInfo, force: bool = False, application_name: str = None - ) -> Pool: - """Get a asyncpgsa connection pool for a given database alias. - - See :py:func:`.get_pool` for more details. - - Args: - db_info: database connection information - force: Force the creation of the pool regardless of the cache - application_name: Arbitrary string that shows up in queries to the - ``pg_stat_activity`` view for tracking the source of database - connections. - - Returns: - database connection pool - - """ - if db_info.engine_type != DatabaseType.asyncpgsa_pool: - raise ValueError(f"Cannot get a connection pool with {db_info.engine_type}") - return await cls._get_engine_or_pool( + return await cls._get_engine( db_info, force=force, application_name=application_name ) @classmethod - async def acquire( - cls, db_info: DBInfo - ) -> Union[AIOPGConnection, AsyncPGConnection]: + async def acquire(cls, db_info: DBInfo) -> Union[AIOPGConnection]: """Acquire a SQLAlchemy connection for a given database alias. This is a convenience function that first gets/creates the engine or pool then @@ -337,7 +165,7 @@ async def acquire( context manager that yields the connection """ - engine = await cls._get_engine_or_pool(db_info) + engine = await cls._get_engine(db_info) return engine.acquire() @classmethod @@ -361,7 +189,7 @@ async def transaction( raise ValueError( f"Transaction does not support database type {db_info.engine_type}" ) - engine = await cls._get_engine_or_pool(db_info) + engine = await cls._get_engine(db_info) return ConditionalTransaction(engine) if is_conditional else Transaction(engine) @classmethod @@ -416,14 +244,10 @@ async def close(cls, db_info: DBInfo) -> None: """ logger.info("Closing database engine") - pool_engine = await cls._get_engine_or_pool(db_info, if_exists=True) + pool_engine = await cls._get_engine(db_info, if_exists=True) if pool_engine is None: # The engine/pool doesn't exist so nothing to close pass - elif db_info.engine_type == DatabaseType.asyncpgsa_pool: - await pool_engine.close() - elif db_info.engine_type == DatabaseType.sqlalchemy_engine: - pool_engine.dispose() else: pool_engine.close() await pool_engine.wait_closed() diff --git a/pyproject.toml b/pyproject.toml index 6d93017..2eefe63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pynocular" -version = "0.14.0" +version = "0.15.0" description = "Lightweight ORM that lets you query your database using Pydantic models and asyncio" authors = [ "RJ Santana ", @@ -17,9 +17,6 @@ python = "^3.6.5" aenum = "^3.1.0" aiocontextvars = "^0.2.2" aiopg = {extras = ["sa"], version = "^1.3.1"} -asyncpg = "^0.24.0" -asyncpgsa = "^0.24.0" -backoff = "^1.11.1" pydantic = "^1.6" [tool.poetry.dev-dependencies]