# SQLite Cloud Dialect for SQLAlchemy (Beta)
![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)
![PyPI - Downloads](https://img.shields.io/pypi/dm/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)
This package enables SQLAlchemy to work seamlessly with SQLite Cloud. The dialect is built upon the existing `sqlite` dialect in SQLAlchemy.
## Beta Version
This dialect is in its early stages and is compatible with Python >= 3.6.
It has been tested on both `SQLAlchemy 2.0` and `SQLAlchemy 1.4`.
The dialect has undergone testing against the SQLAlchemy `test_suite`, as outlined in the [official documentation](https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4_53/README.dialects.rst).
You can track the progress of the remaining test issues [in this issue](https://github.com/sqlitecloud/sqlitecloud-py/issues/32).
_The same tests failed and passed on Python 3.6, 3.7 and 3.11._
## References
- [SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/20/)
- [SQLAlchemy Official Website](https://www.sqlalchemy.org/)
## Installation and Usage
To install the package, use the following command:
```bash
$ pip install sqlalchemy-sqlitecloud
```
> Get your SQLite Cloud connection string from the SQLite Cloud dashboard, or register at [sqlitecloud.io](https://sqlitecloud.io) to get one.
Create an SQLAlchemy engine using the SQLite Cloud connection string::
```python
from sqlalchemy import create_engine
engine = create_engine('sqlitecloud://mynode.sqlite.io?apikey=key1234')
```
### Example
_The example is based on `chinook.sqlite` database on SQLite Cloud_
```python
import sqlalchemy
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.dialects import registry
from sqlalchemy.orm import backref, declarative_base, relationship, sessionmaker
Base = declarative_base()
class Artist(Base):
__tablename__ = "artists"
ArtistId = Column("ArtistId", Integer, primary_key=True)
Name = Column("Name", String)
Albums = relationship("Album", backref=backref("artist"))
class Album(Base):
__tablename__ = "albums"
AlbumId = Column("AlbumId", Integer, primary_key=True)
ArtistId = Column("ArtistId", Integer, ForeignKey("artists.ArtistId"))
Title = Column("Title", String)
# SQLite Cloud connection string
connection_string = "sqlitecloud://myhost.sqlite.cloud:8860/mydatabase.sqlite?apikey=myapikey"
engine = sqlalchemy.create_engine(connection_string)
Session = sessionmaker(bind=engine)
session = Session()
name = "John Doe"
query = sqlalchemy.insert(Artist).values(Name=name)
result_insert = session.execute(query)
title = "The Album"
query = sqlalchemy.insert(Album).values(
ArtistId=result_insert.lastrowid, Title=title
)
session.execute(query)
query = (
sqlalchemy.select(Artist, Album)
.join(Album, Artist.ArtistId == Album.ArtistId)
.where(Artist.ArtistId == result_insert.lastrowid)
)
result = session.execute(query).fetchone()
print("Artist Name: " + result[0].Name)
print("Album Title: " + result[1].Title)
```
# Run the Test Suite
To run the test suite, first install the sqlitecloud package:
```bash
$ pip install sqlitecloud # last version
```
or install the reference to the local version:
```bash
$ cd ../src # sqlitecloud src directory
$ pip install -e .
```
Then, run the test suite with:
```bash
$ cd sqlalchemy-sqlitecloud
$ pytest
```
> Note: VSCode Test Explorer and VSCode GUI debugger doesn't work because the actual implementation of tests
is not in the `test/test_suite.py` file. The test source code is located in a third-party directory and it's not recognized.
For command-line debugging, use `pytest --pdb` with `pdb.set_trace()`.
Some useful `pdb` commands include:
- `s` step into
- `n` next line
- `r` jump to the end of the function
- `c` continue
- `w` print stack trace
More info: [https://docs.python.org/3/library/pdb.html](https://docs.python.org/3/library/pdb.html)
Raw data
{
"_id": null,
"home_page": "https://github.com/sqlitecloud/sqlitecloud-py",
"name": "sqlalchemy-sqlitecloud",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "SQLAlchemy SQLite Cloud",
"author": "sqlitecloud.io",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/85/5b/96601abf2e38288785f42ea0b3f825ffe08b8b4af393f304c3fbef4fe10f/sqlalchemy-sqlitecloud-0.1.2.tar.gz",
"platform": null,
"description": "# SQLite Cloud Dialect for SQLAlchemy (Beta)\n\n![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-sqlitecloud?link=https%3A%2F%2Fpypi.org%2Fproject%2Fsqlalchemy-sqlitecloud%2F)\n\n\nThis package enables SQLAlchemy to work seamlessly with SQLite Cloud. The dialect is built upon the existing `sqlite` dialect in SQLAlchemy.\n\n## Beta Version\n\nThis dialect is in its early stages and is compatible with Python >= 3.6.\n\nIt has been tested on both `SQLAlchemy 2.0` and `SQLAlchemy 1.4`.\n\nThe dialect has undergone testing against the SQLAlchemy `test_suite`, as outlined in the [official documentation](https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4_53/README.dialects.rst).\n\nYou can track the progress of the remaining test issues [in this issue](https://github.com/sqlitecloud/sqlitecloud-py/issues/32). \n_The same tests failed and passed on Python 3.6, 3.7 and 3.11._\n\n## References\n\n- [SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/20/)\n- [SQLAlchemy Official Website](https://www.sqlalchemy.org/)\n\n## Installation and Usage\n\nTo install the package, use the following command:\n\n```bash\n$ pip install sqlalchemy-sqlitecloud\n```\n\n> Get your SQLite Cloud connection string from the SQLite Cloud dashboard, or register at [sqlitecloud.io](https://sqlitecloud.io) to get one.\n\nCreate an SQLAlchemy engine using the SQLite Cloud connection string::\n\n```python\nfrom sqlalchemy import create_engine\n\nengine = create_engine('sqlitecloud://mynode.sqlite.io?apikey=key1234')\n```\n\n### Example\n\n_The example is based on `chinook.sqlite` database on SQLite Cloud_\n\n```python\nimport sqlalchemy\nfrom sqlalchemy import Column, ForeignKey, Integer, String\nfrom sqlalchemy.dialects import registry\nfrom sqlalchemy.orm import backref, declarative_base, relationship, sessionmaker\n\nBase = declarative_base()\n\n\nclass Artist(Base):\n __tablename__ = \"artists\"\n\n ArtistId = Column(\"ArtistId\", Integer, primary_key=True)\n Name = Column(\"Name\", String)\n Albums = relationship(\"Album\", backref=backref(\"artist\"))\n\n\nclass Album(Base):\n __tablename__ = \"albums\"\n\n AlbumId = Column(\"AlbumId\", Integer, primary_key=True)\n ArtistId = Column(\"ArtistId\", Integer, ForeignKey(\"artists.ArtistId\"))\n Title = Column(\"Title\", String)\n\n# SQLite Cloud connection string\nconnection_string = \"sqlitecloud://myhost.sqlite.cloud:8860/mydatabase.sqlite?apikey=myapikey\"\n\nengine = sqlalchemy.create_engine(connection_string)\nSession = sessionmaker(bind=engine)\nsession = Session()\n\nname = \"John Doe\"\nquery = sqlalchemy.insert(Artist).values(Name=name)\nresult_insert = session.execute(query)\n\ntitle = \"The Album\"\nquery = sqlalchemy.insert(Album).values(\n ArtistId=result_insert.lastrowid, Title=title\n)\nsession.execute(query)\n\nquery = (\n sqlalchemy.select(Artist, Album)\n .join(Album, Artist.ArtistId == Album.ArtistId)\n .where(Artist.ArtistId == result_insert.lastrowid)\n)\n\nresult = session.execute(query).fetchone()\n\nprint(\"Artist Name: \" + result[0].Name)\nprint(\"Album Title: \" + result[1].Title)\n\n```\n\n\n\n# Run the Test Suite\n\nTo run the test suite, first install the sqlitecloud package:\n\n```bash\n$ pip install sqlitecloud # last version\n```\nor install the reference to the local version:\n\n\n```bash\n$ cd ../src # sqlitecloud src directory\n$ pip install -e .\n```\n\nThen, run the test suite with:\n\n```bash\n$ cd sqlalchemy-sqlitecloud\n$ pytest\n```\n\n> Note: VSCode Test Explorer and VSCode GUI debugger doesn't work because the actual implementation of tests\nis not in the `test/test_suite.py` file. The test source code is located in a third-party directory and it's not recognized.\n\nFor command-line debugging, use `pytest --pdb` with `pdb.set_trace()`.\n\nSome useful `pdb` commands include:\n\n - `s` step into\n - `n` next line\n - `r` jump to the end of the function\n - `c` continue\n - `w` print stack trace\n\n More info: [https://docs.python.org/3/library/pdb.html](https://docs.python.org/3/library/pdb.html)\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "SQLAlchemy Dialect for SQLite Cloud.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/sqlitecloud/sqlitecloud-py"
},
"split_keywords": [
"sqlalchemy",
"sqlite",
"cloud"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7ff6f2a5c49495ff841f9269b0f49f88105541fbb6d15137c514f818ca5869d0",
"md5": "13f01b157bde2a6178d424c231ede97e",
"sha256": "be5ad4d0b14a54739f02c9c307dfddeb37a950893fbd1be116826829a3232d76"
},
"downloads": -1,
"filename": "sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13f01b157bde2a6178d424c231ede97e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7136,
"upload_time": "2024-09-02T07:49:20",
"upload_time_iso_8601": "2024-09-02T07:49:20.401064Z",
"url": "https://files.pythonhosted.org/packages/7f/f6/f2a5c49495ff841f9269b0f49f88105541fbb6d15137c514f818ca5869d0/sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "855b96601abf2e38288785f42ea0b3f825ffe08b8b4af393f304c3fbef4fe10f",
"md5": "dc764ee1554a6a94f95512a23070607c",
"sha256": "0e351bec6722a469250dc3d05c6caaf5b57f1584d0fec2de3a2b3708cb441475"
},
"downloads": -1,
"filename": "sqlalchemy-sqlitecloud-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "dc764ee1554a6a94f95512a23070607c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5701,
"upload_time": "2024-09-02T07:49:22",
"upload_time_iso_8601": "2024-09-02T07:49:22.208218Z",
"url": "https://files.pythonhosted.org/packages/85/5b/96601abf2e38288785f42ea0b3f825ffe08b8b4af393f304c3fbef4fe10f/sqlalchemy-sqlitecloud-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-02 07:49:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sqlitecloud",
"github_project": "sqlitecloud-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "lz4",
"specs": [
[
">=",
"3.1.10"
]
]
}
],
"lcname": "sqlalchemy-sqlitecloud"
}