https://github.com/deadnews/firebirdsql-run
Firebirdsql wrapper inspired by subprocess.run
https://github.com/deadnews/firebirdsql-run
api firebird sql
Last synced: about 1 year ago
JSON representation
Firebirdsql wrapper inspired by subprocess.run
- Host: GitHub
- URL: https://github.com/deadnews/firebirdsql-run
- Owner: DeadNews
- License: mit
- Created: 2022-07-21T13:01:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-26T11:52:57.000Z (about 1 year ago)
- Last Synced: 2025-06-08T13:43:29.040Z (about 1 year ago)
- Topics: api, firebird, sql
- Language: Python
- Homepage: https://deadnews.github.io/firebirdsql-run
- Size: 603 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# firebirdsql-run
> [Firebirdsql](https://github.com/nakagami/pyfirebirdsql/) wrapper inspired by [subprocess.run](https://docs.python.org/3/library/subprocess.html#subprocess.run)
[](https://pypi.org/project/firebirdsql-run)
[](https://github.com/deadnews/firebirdsql-run/releases/latest)
[](https://deadnews.github.io/firebirdsql-run)
[](https://results.pre-commit.ci/latest/github/deadnews/firebirdsql-run/main)
[](https://github.com/deadnews/firebirdsql-run/actions/workflows/main.yml)
[](https://app.codecov.io/gh/deadnews/firebirdsql-run)
**[Installation](#installation)** • **[Examples](#examples)** • **[Env Variables](#env-variables)**
## Installation
```sh
pip install firebirdsql-run
# or
poetry add firebirdsql-run
```
## Examples
Execute a query with read-only access:
```py
from firebirdsql_run import DBAccess, execute
# Execute a query with read-only access.
result = execute(query="SELECT * FROM table", db="database", access=DBAccess.READ_ONLY)
# Output: List of dictionaries containing the query results.
print(result.data)
```
Execute a query with parameters and log the result:
```py
# Execute a query with parameters.
result = execute(query="INSERT INTO customers (name, age) VALUES (?, ?)", params=("John", 25))
# Log the result.
if result.returncode != 0:
logger.error(result)
else:
logger.info(result)
```
Execute a query using the existing connection:
```py
# Create a connection object.
conn = connection(db="database", access=DBAccess.READ_ONLY)
# Execute a query using the existing connection.
result = execute(query="SELECT * FROM table", use_conn=conn)
# Close the connection.
conn.close()
# Output: Named tuple representing the completed transaction.
print(result)
```
An example of a successful transaction:
```py
>>> print(result)
CompletedTransaction(
host="127.0.0.1",
db="database",
user="TWUSER",
access="READ_ONLY",
returncode=0,
exception="",
query="SELECT * FROM table",
params=(),
time=0.001,
data=[
{'id': 1, 'name': 'John Doe', 'department': 'Sales'},
{'id': 2, 'name': 'Jane Smith', 'department': 'Sales'},
],
)
```
An example of a failed transaction:
```py
>>> print(result)
CompletedTransaction(
host="127.0.0.1",
db="database",
user="TWUSER",
access="READ_ONLY",
returncode=1,
exception="Dynamic SQL Error\nSQL error code = -204\nTable unknown\ntable\nAt line 1, column 15\n",
query="SELECT * FROM table",
params=(),
time=0.001,
data=[],
)
```
## Env Variables
```ini
FIREBIRD_KEY=
```
The `FIREBIRD_KEY` environment variable can be overridden with the functions argument `passwd`.