# SQLAlchemy SQLFlite ADBC Dialect
[<img src="https://img.shields.io/badge/GitHub-prmoore77%2Fsqlalchemy--sqlflite--adbc--dialect-blue.svg?logo=Github">](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect)
[![sqlalchemy-sqlflite-adbc-dialect-ci](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect/actions/workflows/ci.yml)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--sqlflite--adbc--dialect)](https://pypi.org/project/sqlalchemy-sqlflite-adbc-dialect/)
[![PyPI version](https://badge.fury.io/py/sqlalchemy-sqlflite-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-sqlflite-adbc-dialect)
[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--sqlflite--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-sqlflite-adbc-dialect/)
Basic SQLAlchemy dialect for [SQLFlite](https://github.com/voltrondata/SQLFlite)
## Installation
### Option 1 - from PyPi
```sh
$ pip install sqlalchemy-sqlflite-adbc-dialect
```
### Option 2 - from source - for development
```shell
git clone https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect
cd sqlalchemy-sqlflite-adbc-dialect
# Create the virtual environment
python3 -m venv .venv
# Activate the virtual environment
. .venv/bin/activate
# Upgrade pip, setuptools, and wheel
pip install --upgrade pip setuptools wheel
# Install SQLAlchemy SQLFlite ADBC Dialect - in editable mode with dev dependencies
pip install --editable .[dev]
```
### Note
For the following commands - if you running from source and using `--editable` mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:
```shell
export PYTHONPATH=$(pwd)/src
```
## Usage
Once you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search
### Start a SQLFlite Server - example below - see https://github.com/voltrondata/SQLFlite for more details
```bash
docker run --name sqlflite \
--detach \
--rm \
--tty \
--init \
--publish 31337:31337 \
--env TLS_ENABLED="1" \
--env SQLFLITE_PASSWORD="sqlflite_password" \
--env PRINT_QUERIES="1" \
--pull missing \
voltrondata/sqlflite:latest
```
### Connect with the SQLAlchemy SQLFlite ADBC Dialect
```python
import os
import logging
from sqlalchemy import create_engine, MetaData, Table, select, Column, text, Integer, String, Sequence
from sqlalchemy.orm import Session
from sqlalchemy.orm import declarative_base
from sqlalchemy.engine.url import URL
# Setup logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
Base = declarative_base()
class FakeModel(Base): # type: ignore
__tablename__ = "fake"
id = Column(Integer, Sequence("fakemodel_id_sequence"), primary_key=True)
name = Column(String)
def main():
# Build the URL
url = URL.create(drivername="sqlflite",
host="localhost",
port=31337,
username=os.getenv("SQLFLITE_USERNAME", "sqlflite_username"),
password=os.getenv("SQLFLITE_PASSWORD", "sqlflite_password"),
query={"disableCertificateVerification": "True",
"useEncryption": "True"
}
)
print(f"Database URL: {url}")
engine = create_engine(url=url)
Base.metadata.create_all(bind=engine)
metadata = MetaData()
metadata.reflect(bind=engine)
for table_name in metadata.tables:
print(f"Table name: {table_name}")
with Session(bind=engine) as session:
# Try ORM
session.add(FakeModel(id=1, name="Joe"))
session.commit()
joe = session.query(FakeModel).filter(FakeModel.name == "Joe").first()
assert joe.name == "Joe"
# Execute some raw SQL
results = session.execute(statement=text("SELECT * FROM fake")).fetchall()
print(results)
# Try a SQLAlchemy table select
fake: Table = metadata.tables["fake"]
stmt = select(fake.c.name)
results = session.execute(statement=stmt).fetchall()
print(results)
if __name__ == "__main__":
main()
```
### Credits
Much code and inspiration was taken from repo: https://github.com/Mause/duckdb_engine
Raw data
{
"_id": null,
"home_page": null,
"name": "sqlalchemy-sqlflite-adbc-dialect",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "sqlalchemy, flight-sql, sqlflite, adbc, dialect",
"author": null,
"author_email": "Philip Moore <prmoore77@hotmail.com>",
"download_url": "https://files.pythonhosted.org/packages/87/2f/c74759497212ea94a4cb3b876cc7e407e0bf2dc533525876d466defb235b/sqlalchemy_sqlflite_adbc_dialect-0.0.15.tar.gz",
"platform": null,
"description": "# SQLAlchemy SQLFlite ADBC Dialect \n\n[<img src=\"https://img.shields.io/badge/GitHub-prmoore77%2Fsqlalchemy--sqlflite--adbc--dialect-blue.svg?logo=Github\">](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect)\n[![sqlalchemy-sqlflite-adbc-dialect-ci](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect/actions/workflows/ci.yml/badge.svg)](https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect/actions/workflows/ci.yml)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy--sqlflite--adbc--dialect)](https://pypi.org/project/sqlalchemy-sqlflite-adbc-dialect/)\n[![PyPI version](https://badge.fury.io/py/sqlalchemy-sqlflite-adbc-dialect.svg)](https://badge.fury.io/py/sqlalchemy-sqlflite-adbc-dialect)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/sqlalchemy--sqlflite--adbc--dialect.svg)](https://pypi.org/project/sqlalchemy-sqlflite-adbc-dialect/)\n\nBasic SQLAlchemy dialect for [SQLFlite](https://github.com/voltrondata/SQLFlite)\n\n## Installation\n\n### Option 1 - from PyPi\n```sh\n$ pip install sqlalchemy-sqlflite-adbc-dialect\n```\n\n### Option 2 - from source - for development\n```shell\ngit clone https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect\n\ncd sqlalchemy-sqlflite-adbc-dialect\n\n# Create the virtual environment\npython3 -m venv .venv\n\n# Activate the virtual environment\n. .venv/bin/activate\n\n# Upgrade pip, setuptools, and wheel\npip install --upgrade pip setuptools wheel\n\n# Install SQLAlchemy SQLFlite ADBC Dialect - in editable mode with dev dependencies\npip install --editable .[dev]\n```\n\n### Note\nFor the following commands - if you running from source and using `--editable` mode (for development purposes) - you will need to set the PYTHONPATH environment variable as follows:\n```shell\nexport PYTHONPATH=$(pwd)/src\n```\n\n## Usage\n\nOnce you've installed this package, you should be able to just use it, as SQLAlchemy does a python path search\n\n### Start a SQLFlite Server - example below - see https://github.com/voltrondata/SQLFlite for more details\n```bash\ndocker run --name sqlflite \\\n --detach \\\n --rm \\\n --tty \\\n --init \\\n --publish 31337:31337 \\\n --env TLS_ENABLED=\"1\" \\\n --env SQLFLITE_PASSWORD=\"sqlflite_password\" \\\n --env PRINT_QUERIES=\"1\" \\\n --pull missing \\\n voltrondata/sqlflite:latest\n```\n\n### Connect with the SQLAlchemy SQLFlite ADBC Dialect\n```python\nimport os\nimport logging\n\nfrom sqlalchemy import create_engine, MetaData, Table, select, Column, text, Integer, String, Sequence\nfrom sqlalchemy.orm import Session\nfrom sqlalchemy.orm import declarative_base\nfrom sqlalchemy.engine.url import URL\n\n# Setup logging\nlogging.basicConfig()\nlogging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)\n\n\nBase = declarative_base()\n\n\nclass FakeModel(Base): # type: ignore\n __tablename__ = \"fake\"\n\n id = Column(Integer, Sequence(\"fakemodel_id_sequence\"), primary_key=True)\n name = Column(String)\n\n\ndef main():\n # Build the URL\n url = URL.create(drivername=\"sqlflite\",\n host=\"localhost\",\n port=31337,\n username=os.getenv(\"SQLFLITE_USERNAME\", \"sqlflite_username\"),\n password=os.getenv(\"SQLFLITE_PASSWORD\", \"sqlflite_password\"),\n query={\"disableCertificateVerification\": \"True\",\n \"useEncryption\": \"True\"\n }\n )\n\n print(f\"Database URL: {url}\")\n\n engine = create_engine(url=url)\n Base.metadata.create_all(bind=engine)\n\n metadata = MetaData()\n metadata.reflect(bind=engine)\n\n for table_name in metadata.tables:\n print(f\"Table name: {table_name}\")\n\n with Session(bind=engine) as session:\n\n # Try ORM\n session.add(FakeModel(id=1, name=\"Joe\"))\n session.commit()\n\n joe = session.query(FakeModel).filter(FakeModel.name == \"Joe\").first()\n\n assert joe.name == \"Joe\"\n\n # Execute some raw SQL\n results = session.execute(statement=text(\"SELECT * FROM fake\")).fetchall()\n print(results)\n\n # Try a SQLAlchemy table select\n fake: Table = metadata.tables[\"fake\"]\n stmt = select(fake.c.name)\n\n results = session.execute(statement=stmt).fetchall()\n print(results)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Credits\nMuch code and inspiration was taken from repo: https://github.com/Mause/duckdb_engine\n",
"bugtrack_url": null,
"license": null,
"summary": "A SQLAlchemy dialect for connecting to a [SQLFlite](https://github.com/voltrondata/SQLFlite) server with ADBC",
"version": "0.0.15",
"project_urls": {
"Homepage": "https://github.com/prmoore77/sqlalchemy-sqlflite-adbc-dialect"
},
"split_keywords": [
"sqlalchemy",
" flight-sql",
" sqlflite",
" adbc",
" dialect"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3cdefd80afcf7e0d854d54895bb857a6d2030f8dd2765358151a2ea55447f9c3",
"md5": "31c2a9b1741bbe17ea05c437258ef0a1",
"sha256": "fdef42a0d2e80b6510b3f64d7e29c8619fa3e8c7f99c353769fcfaf77a988f2c"
},
"downloads": -1,
"filename": "sqlalchemy_sqlflite_adbc_dialect-0.0.15-py3-none-any.whl",
"has_sig": false,
"md5_digest": "31c2a9b1741bbe17ea05c437258ef0a1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10144,
"upload_time": "2024-07-22T14:52:03",
"upload_time_iso_8601": "2024-07-22T14:52:03.554971Z",
"url": "https://files.pythonhosted.org/packages/3c/de/fd80afcf7e0d854d54895bb857a6d2030f8dd2765358151a2ea55447f9c3/sqlalchemy_sqlflite_adbc_dialect-0.0.15-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "872fc74759497212ea94a4cb3b876cc7e407e0bf2dc533525876d466defb235b",
"md5": "30ae78a1a245efbbfc40b4c98223118a",
"sha256": "4dc41ca885ff248d44d5a8ecc53f6b2e8f5137491e6e079eba287b98ac8ef3d0"
},
"downloads": -1,
"filename": "sqlalchemy_sqlflite_adbc_dialect-0.0.15.tar.gz",
"has_sig": false,
"md5_digest": "30ae78a1a245efbbfc40b4c98223118a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11288,
"upload_time": "2024-07-22T14:52:05",
"upload_time_iso_8601": "2024-07-22T14:52:05.049024Z",
"url": "https://files.pythonhosted.org/packages/87/2f/c74759497212ea94a4cb3b876cc7e407e0bf2dc533525876d466defb235b/sqlalchemy_sqlflite_adbc_dialect-0.0.15.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-22 14:52:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "prmoore77",
"github_project": "sqlalchemy-sqlflite-adbc-dialect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sqlalchemy-sqlflite-adbc-dialect"
}