sqlalchemy-firebird-async 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. sqlalchemy_firebird_async-0.1.0/.gitignore +149 -0
  2. sqlalchemy_firebird_async-0.1.0/LICENSE +21 -0
  3. sqlalchemy_firebird_async-0.1.0/PKG-INFO +136 -0
  4. sqlalchemy_firebird_async-0.1.0/README.md +107 -0
  5. sqlalchemy_firebird_async-0.1.0/check_query.py +22 -0
  6. sqlalchemy_firebird_async-0.1.0/check_simple.py +12 -0
  7. sqlalchemy_firebird_async-0.1.0/pyproject.toml +42 -0
  8. sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/__init__.py +0 -0
  9. sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/fdb.py +115 -0
  10. sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/firebirdsql.py +184 -0
  11. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/PKG-INFO +50 -0
  12. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/README.md +26 -0
  13. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/pyproject.toml +39 -0
  14. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/__init__.py +0 -0
  15. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/fdb.py +115 -0
  16. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/src/sqlalchemy_firebird_async/firebirdsql.py +154 -0
  17. sqlalchemy_firebird_async-0.1.0/temp_check/sqlalchemy_firebird_async-0.1.0/uv.lock +204 -0
  18. sqlalchemy_firebird_async-0.1.0/temp_check/test_install/check.py +29 -0
  19. sqlalchemy_firebird_async-0.1.0/temp_check/test_install/db/sql_models.py +140 -0
  20. sqlalchemy_firebird_async-0.1.0/temp_check/test_install/main.py +175 -0
  21. sqlalchemy_firebird_async-0.1.0/tests/conftest.py +68 -0
  22. sqlalchemy_firebird_async-0.1.0/tests/test_basic.py +39 -0
  23. sqlalchemy_firebird_async-0.1.0/tests/test_load.py +79 -0
  24. sqlalchemy_firebird_async-0.1.0/uv.lock +468 -0
@@ -0,0 +1,149 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .node_repl_history
51
+ .pytest_cache/
52
+ pytestdebug.log
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the Python version
87
+ # is managed by the end user and local to the developer.
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or even
94
+ # fail to install, on other platforms.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ #poetry.lock
100
+
101
+ # pdm
102
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
103
+ #pdm.lock
104
+
105
+ # PEP 582; used by e.g. github.com/fannheyward/coc-pyright
106
+ __pypackages__/
107
+
108
+ # Celery stuff
109
+ celerybeat-schedule
110
+ celerybeat.pid
111
+
112
+ # SageMath parsed files
113
+ *.sage.py
114
+
115
+ # Environments
116
+ .env
117
+ .venv
118
+ env/
119
+ venv/
120
+ ENV/
121
+ env.bak/
122
+ venv.bak/
123
+
124
+ # Spyder project settings
125
+ .spyderproject
126
+ .spyproject
127
+
128
+ # Rope project settings
129
+ .ropeproject
130
+
131
+ # mkdocs documentation
132
+ /site
133
+
134
+ # mypy
135
+ .mypy_cache/
136
+ .dmypy.json
137
+ dmypy.json
138
+
139
+ # Pyre type checker
140
+ .pyre/
141
+
142
+ # pytype static type analyzer
143
+ .pytype/
144
+
145
+ # Cython debug symbols
146
+ cython_debug/
147
+
148
+ # PyCharm
149
+ .idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: sqlalchemy-firebird-async
3
+ Version: 0.1.0
4
+ Summary: Asyncio support for Firebird in SQLAlchemy
5
+ Project-URL: Homepage, https://github.com/attid/sqlalchemy-firebird-async
6
+ Author-email: Igor Tolstov <attid0@gmail.com>
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Framework :: AsyncIO
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Database
14
+ Requires-Dist: greenlet!=0.4.17
15
+ Requires-Dist: sqlalchemy-firebird>=2.0.0
16
+ Requires-Dist: sqlalchemy>=2.0.0
17
+ Provides-Extra: all
18
+ Requires-Dist: fdb>=2.0; extra == 'all'
19
+ Requires-Dist: firebirdsql>=1.0; extra == 'all'
20
+ Provides-Extra: fdb
21
+ Requires-Dist: fdb>=2.0; extra == 'fdb'
22
+ Provides-Extra: firebirdsql
23
+ Requires-Dist: firebirdsql>=1.0; extra == 'firebirdsql'
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'test'
26
+ Requires-Dist: pytest>=7.0; extra == 'test'
27
+ Requires-Dist: testcontainers>=3.7.0; extra == 'test'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # sqlalchemy-firebird-async
31
+
32
+ ![Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-firebird-async)
33
+ ![License](https://img.shields.io/pypi/l/sqlalchemy-firebird-async)
34
+ ![Status](https://img.shields.io/pypi/status/sqlalchemy-firebird-async)
35
+
36
+ **Asynchronous Firebird dialect for SQLAlchemy.**
37
+
38
+ This library provides proper `asyncio` support for Firebird databases in SQLAlchemy 2.0+, allowing you to write fully asynchronous code using modern Python patterns.
39
+
40
+ It supports two underlying drivers:
41
+ 1. **`fdb`** (Recommended) - Runs the official C-based driver in a thread pool. Fast and stable.
42
+ 2. **`firebirdsql`** - Pure Python asyncio driver. Currently experimental due to upstream issues.
43
+
44
+ ## 📦 Installation
45
+
46
+ Install using pip:
47
+
48
+ ```bash
49
+ # Recommended: Install with the FDB driver (Threaded, Fast)
50
+ pip install "sqlalchemy-firebird-async[fdb]"
51
+
52
+ # Install with pure python driver (Experimental)
53
+ pip install "sqlalchemy-firebird-async[firebirdsql]"
54
+ # Note: For correct async behavior with firebirdsql, you might need a patched version:
55
+ # pip install git+https://github.com/attid/pyfirebirdsql.git
56
+ ```
57
+
58
+ ## 🚀 Quick Start
59
+
60
+ ### 1. Using FDB Driver (Recommended)
61
+
62
+ This dialect runs the official `fdb` driver in a thread pool (`run_in_executor`). While not "truly" async at the socket level, it provides the best performance and stability currently available for Firebird in Python.
63
+
64
+ **URL Scheme:** `firebird+fdb_async://`
65
+
66
+ ```python
67
+ import asyncio
68
+ from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
69
+ from sqlalchemy import text
70
+
71
+ async def main():
72
+ # Format: firebird+fdb_async://user:password@host:port/path/to/db
73
+ # Note: For Linux, ensure the path is absolute (e.g. //firebird/data/...)
74
+ dsn = "firebird+fdb_async://sysdba:masterkey@localhost:3050//firebird/data/employee.fdb"
75
+
76
+ engine = create_async_engine(dsn, echo=True)
77
+
78
+ async with engine.begin() as conn:
79
+ result = await conn.execute(text("SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') FROM rdb$database"))
80
+ version = result.scalar()
81
+ print(f"Firebird Version: {version}")
82
+
83
+ # Using AsyncSession
84
+ async_session = async_sessionmaker(engine, expire_on_commit=False)
85
+ async with async_session() as session:
86
+ result = await session.execute(text("SELECT count(*) FROM rdb$relations"))
87
+ print(f"Total tables: {result.scalar()}")
88
+
89
+ await engine.dispose()
90
+
91
+ if __name__ == "__main__":
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ ### 2. Using Native Async Driver (firebirdsql)
96
+
97
+ **Warning:** The upstream `firebirdsql` driver currently has issues with `asyncio` compatibility (bugs causing crashes or incorrect behavior).
98
+ A patched fork is available at [attid/pyfirebirdsql](https://github.com/attid/pyfirebirdsql.git), which fixes the async logic but currently exhibits significantly lower performance (approx. 4x slower than fdb).
99
+
100
+ **URL Scheme:** `firebird+firebirdsql_async://`
101
+
102
+ ```python
103
+ engine = create_async_engine(
104
+ "firebird+firebirdsql_async://sysdba:masterkey@localhost:3050//firebird/data/employee.fdb"
105
+ )
106
+ ```
107
+
108
+ ## 📊 Performance Comparison
109
+
110
+ We compared both drivers executing 5000 queries in 8 concurrent tasks (4 raw SQL + 4 ORM).
111
+
112
+ | Metric | **fdb (Threaded)** 🏆 | **firebirdsql (Patched)** | Difference |
113
+ | :--- | :--- | :--- | :--- |
114
+ | **Total Time** | **4.53s** | 116.20s | ~25x slower |
115
+ | **Avg Query Time (ORM)** | **2.54s** | 114.43s | ~45x slower |
116
+ | **Avg Query Time (Raw)** | **4.44s** | 116.14s | ~26x slower |
117
+ | **Parallel Ratio** | 6.16x | 7.94x | - |
118
+
119
+ *Benchmark details: 8 concurrent workers, 5000 rows each, total 40k rows.*
120
+
121
+ As seen above, `fdb` in a thread pool is significantly faster for high-load scenarios.
122
+
123
+ ## 🔌 Connection String Guide
124
+
125
+ | Driver | Protocol | URL Scheme |
126
+ | :--- | :--- | :--- |
127
+ | **fdb** (Recommended) | TCP/IP | `firebird+fdb_async://user:pass@host:port/db_path` |
128
+ | **firebirdsql** | TCP/IP | `firebird+firebirdsql_async://user:pass@host:port/db_path` |
129
+
130
+ ## 🤝 Contributing
131
+
132
+ Contributions are welcome! Please feel free to submit a Pull Request.
133
+
134
+ ## 📄 License
135
+
136
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,107 @@
1
+ # sqlalchemy-firebird-async
2
+
3
+ ![Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-firebird-async)
4
+ ![License](https://img.shields.io/pypi/l/sqlalchemy-firebird-async)
5
+ ![Status](https://img.shields.io/pypi/status/sqlalchemy-firebird-async)
6
+
7
+ **Asynchronous Firebird dialect for SQLAlchemy.**
8
+
9
+ This library provides proper `asyncio` support for Firebird databases in SQLAlchemy 2.0+, allowing you to write fully asynchronous code using modern Python patterns.
10
+
11
+ It supports two underlying drivers:
12
+ 1. **`fdb`** (Recommended) - Runs the official C-based driver in a thread pool. Fast and stable.
13
+ 2. **`firebirdsql`** - Pure Python asyncio driver. Currently experimental due to upstream issues.
14
+
15
+ ## 📦 Installation
16
+
17
+ Install using pip:
18
+
19
+ ```bash
20
+ # Recommended: Install with the FDB driver (Threaded, Fast)
21
+ pip install "sqlalchemy-firebird-async[fdb]"
22
+
23
+ # Install with pure python driver (Experimental)
24
+ pip install "sqlalchemy-firebird-async[firebirdsql]"
25
+ # Note: For correct async behavior with firebirdsql, you might need a patched version:
26
+ # pip install git+https://github.com/attid/pyfirebirdsql.git
27
+ ```
28
+
29
+ ## 🚀 Quick Start
30
+
31
+ ### 1. Using FDB Driver (Recommended)
32
+
33
+ This dialect runs the official `fdb` driver in a thread pool (`run_in_executor`). While not "truly" async at the socket level, it provides the best performance and stability currently available for Firebird in Python.
34
+
35
+ **URL Scheme:** `firebird+fdb_async://`
36
+
37
+ ```python
38
+ import asyncio
39
+ from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
40
+ from sqlalchemy import text
41
+
42
+ async def main():
43
+ # Format: firebird+fdb_async://user:password@host:port/path/to/db
44
+ # Note: For Linux, ensure the path is absolute (e.g. //firebird/data/...)
45
+ dsn = "firebird+fdb_async://sysdba:masterkey@localhost:3050//firebird/data/employee.fdb"
46
+
47
+ engine = create_async_engine(dsn, echo=True)
48
+
49
+ async with engine.begin() as conn:
50
+ result = await conn.execute(text("SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') FROM rdb$database"))
51
+ version = result.scalar()
52
+ print(f"Firebird Version: {version}")
53
+
54
+ # Using AsyncSession
55
+ async_session = async_sessionmaker(engine, expire_on_commit=False)
56
+ async with async_session() as session:
57
+ result = await session.execute(text("SELECT count(*) FROM rdb$relations"))
58
+ print(f"Total tables: {result.scalar()}")
59
+
60
+ await engine.dispose()
61
+
62
+ if __name__ == "__main__":
63
+ asyncio.run(main())
64
+ ```
65
+
66
+ ### 2. Using Native Async Driver (firebirdsql)
67
+
68
+ **Warning:** The upstream `firebirdsql` driver currently has issues with `asyncio` compatibility (bugs causing crashes or incorrect behavior).
69
+ A patched fork is available at [attid/pyfirebirdsql](https://github.com/attid/pyfirebirdsql.git), which fixes the async logic but currently exhibits significantly lower performance (approx. 4x slower than fdb).
70
+
71
+ **URL Scheme:** `firebird+firebirdsql_async://`
72
+
73
+ ```python
74
+ engine = create_async_engine(
75
+ "firebird+firebirdsql_async://sysdba:masterkey@localhost:3050//firebird/data/employee.fdb"
76
+ )
77
+ ```
78
+
79
+ ## 📊 Performance Comparison
80
+
81
+ We compared both drivers executing 5000 queries in 8 concurrent tasks (4 raw SQL + 4 ORM).
82
+
83
+ | Metric | **fdb (Threaded)** 🏆 | **firebirdsql (Patched)** | Difference |
84
+ | :--- | :--- | :--- | :--- |
85
+ | **Total Time** | **4.53s** | 116.20s | ~25x slower |
86
+ | **Avg Query Time (ORM)** | **2.54s** | 114.43s | ~45x slower |
87
+ | **Avg Query Time (Raw)** | **4.44s** | 116.14s | ~26x slower |
88
+ | **Parallel Ratio** | 6.16x | 7.94x | - |
89
+
90
+ *Benchmark details: 8 concurrent workers, 5000 rows each, total 40k rows.*
91
+
92
+ As seen above, `fdb` in a thread pool is significantly faster for high-load scenarios.
93
+
94
+ ## 🔌 Connection String Guide
95
+
96
+ | Driver | Protocol | URL Scheme |
97
+ | :--- | :--- | :--- |
98
+ | **fdb** (Recommended) | TCP/IP | `firebird+fdb_async://user:pass@host:port/db_path` |
99
+ | **firebirdsql** | TCP/IP | `firebird+firebirdsql_async://user:pass@host:port/db_path` |
100
+
101
+ ## 🤝 Contributing
102
+
103
+ Contributions are welcome! Please feel free to submit a Pull Request.
104
+
105
+ ## 📄 License
106
+
107
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,22 @@
1
+ import asyncio
2
+ from sqlalchemy.ext.asyncio import create_async_engine
3
+ from sqlalchemy import text
4
+
5
+ async def main():
6
+ # URL из нашего conftest
7
+ url = "firebird+firebirdsql_async://testuser:testpass@localhost:32785//var/lib/firebird/data/test.fdb?charset=UTF8"
8
+ engine = create_async_engine(url)
9
+
10
+ try:
11
+ async with engine.connect() as conn:
12
+ print("🔌 Connected")
13
+ # Просто select 1
14
+ res = await conn.execute(text("SELECT 1 FROM rdb$database"))
15
+ print(f"📊 Result: {res.scalar()}")
16
+ except Exception as e:
17
+ print(f"❌ Error: {e}")
18
+ finally:
19
+ await engine.dispose()
20
+
21
+ if __name__ == "__main__":
22
+ asyncio.run(main())
@@ -0,0 +1,12 @@
1
+ import asyncio
2
+ from sqlalchemy.ext.asyncio import create_async_engine
3
+
4
+ async def main():
5
+ # Просто создание движка и проверка диалекта
6
+ engine = create_async_engine("firebird+firebirdsql_async://user:pass@localhost/db")
7
+ print(f"✅ Engine created: {engine}")
8
+ print(f"✅ Dialect: {engine.dialect.name}")
9
+ await engine.dispose()
10
+
11
+ if __name__ == "__main__":
12
+ asyncio.run(main())
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "sqlalchemy-firebird-async"
7
+ version = "0.1.0"
8
+ description = "Asyncio support for Firebird in SQLAlchemy"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Igor Tolstov", email = "attid0@gmail.com" },
12
+ ]
13
+ license = { text = "MIT" }
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Framework :: AsyncIO",
19
+ "Topic :: Database",
20
+ ]
21
+ dependencies = [
22
+ "sqlalchemy>=2.0.0",
23
+ "sqlalchemy-firebird>=2.0.0",
24
+ "greenlet!=0.4.17",
25
+ ]
26
+
27
+ [project.optional-dependencies]
28
+ fdb = ["fdb>=2.0"]
29
+ firebirdsql = ["firebirdsql>=1.0"]
30
+ all = ["fdb>=2.0", "firebirdsql>=1.0"]
31
+ test = [
32
+ "pytest>=7.0",
33
+ "pytest-asyncio>=0.21",
34
+ "testcontainers>=3.7.0",
35
+ ]
36
+
37
+ [project.entry-points."sqlalchemy.dialects"]
38
+ "firebird.fdb_async" = "sqlalchemy_firebird_async.fdb:AsyncFDBDialect"
39
+ "firebird.firebirdsql_async" = "sqlalchemy_firebird_async.firebirdsql:AsyncFirebirdSQLDialect"
40
+
41
+ [project.urls]
42
+ "Homepage" = "https://github.com/attid/sqlalchemy-firebird-async"
@@ -0,0 +1,115 @@
1
+ import asyncio
2
+ from functools import partial
3
+
4
+ from sqlalchemy.util.concurrency import await_only
5
+
6
+
7
+ class AsyncCursor:
8
+ def __init__(self, sync_cursor, loop):
9
+ self._sync_cursor = sync_cursor
10
+ self._loop = loop
11
+
12
+ def execute(self, operation, parameters=None):
13
+ if parameters is None:
14
+ func = partial(self._sync_cursor.execute, operation)
15
+ else:
16
+ func = partial(self._sync_cursor.execute, operation, parameters)
17
+ await_only(self._loop.run_in_executor(None, func))
18
+ return self
19
+
20
+ def executemany(self, operation, seq_of_parameters):
21
+ func = partial(self._sync_cursor.executemany, operation, seq_of_parameters)
22
+ await_only(self._loop.run_in_executor(None, func))
23
+ return self
24
+
25
+ def fetchone(self):
26
+ return await_only(self._loop.run_in_executor(None, self._sync_cursor.fetchone))
27
+
28
+ def fetchmany(self, size=None):
29
+ if size is None:
30
+ return await_only(self._loop.run_in_executor(None, self._sync_cursor.fetchmany))
31
+ func = partial(self._sync_cursor.fetchmany, size)
32
+ return await_only(self._loop.run_in_executor(None, func))
33
+
34
+ def fetchall(self):
35
+ return await_only(self._loop.run_in_executor(None, self._sync_cursor.fetchall))
36
+
37
+ def close(self):
38
+ return await_only(self._loop.run_in_executor(None, self._sync_cursor.close))
39
+
40
+ def __getattr__(self, name):
41
+ return getattr(self._sync_cursor, name)
42
+
43
+
44
+ class AsyncConnection:
45
+ def __init__(self, sync_connection, loop):
46
+ self._sync_connection = sync_connection
47
+ self._loop = loop
48
+
49
+ def cursor(self):
50
+ return AsyncCursor(self._sync_connection.cursor(), self._loop)
51
+
52
+ def commit(self):
53
+ await_only(self._loop.run_in_executor(None, self._sync_connection.commit))
54
+
55
+ def rollback(self):
56
+ await_only(self._loop.run_in_executor(None, self._sync_connection.rollback))
57
+
58
+ def close(self):
59
+ await_only(self._loop.run_in_executor(None, self._sync_connection.close))
60
+
61
+ def __getattr__(self, name):
62
+ return getattr(self._sync_connection, name)
63
+
64
+
65
+ class AsyncDBAPI:
66
+ def __init__(self, sync_dbapi):
67
+ self._sync_dbapi = sync_dbapi
68
+ self.paramstyle = getattr(sync_dbapi, "paramstyle", "qmark")
69
+ self.apilevel = getattr(sync_dbapi, "apilevel", "2.0")
70
+ self.threadsafety = getattr(sync_dbapi, "threadsafety", 0)
71
+ for attr in (
72
+ "Warning",
73
+ "Error",
74
+ "InterfaceError",
75
+ "DatabaseError",
76
+ "DataError",
77
+ "OperationalError",
78
+ "IntegrityError",
79
+ "InternalError",
80
+ "ProgrammingError",
81
+ "NotSupportedError",
82
+ ):
83
+ if hasattr(sync_dbapi, attr):
84
+ setattr(self, attr, getattr(sync_dbapi, attr))
85
+
86
+ def connect(self, *args, **kwargs):
87
+ async_creator_fn = kwargs.pop("async_creator_fn", None)
88
+ loop = asyncio.get_running_loop()
89
+ if async_creator_fn is not None:
90
+ sync_conn = await_only(async_creator_fn(*args, **kwargs))
91
+ else:
92
+ func = partial(self._sync_dbapi.connect, *args, **kwargs)
93
+ sync_conn = await_only(loop.run_in_executor(None, func))
94
+ return AsyncConnection(sync_conn, loop)
95
+
96
+ from sqlalchemy.pool import AsyncAdaptedQueuePool
97
+ import sqlalchemy_firebird.fdb as fdb
98
+
99
+
100
+ class AsyncFDBDialect(fdb.FBDialect_fdb):
101
+ name = "firebird.fdb_async"
102
+ driver = "fdb_async"
103
+ is_async = True
104
+ supports_statement_cache = False
105
+ poolclass = AsyncAdaptedQueuePool
106
+
107
+ @classmethod
108
+ def import_dbapi(cls):
109
+ import fdb as sync_fdb
110
+
111
+ return AsyncDBAPI(sync_fdb)
112
+
113
+ @classmethod
114
+ def dbapi(cls):
115
+ return cls.import_dbapi()