SQLite Cloud Dialect for SQLAlchemy (Beta)
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.
You can track the progress of the remaining test issues in this issue.
The same tests failed and passed on Python 3.6, 3.7 and 3.11.
References
Installation and Usage
To install the package, use the following command:
$ pip install sqlalchemy-sqlitecloud
Get your SQLite Cloud connection string from the SQLite Cloud dashboard, or register at sqlitecloud.io to get one.
Create an SQLAlchemy engine using the SQLite Cloud connection string::
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
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:
$ pip install sqlitecloud # last version
or install the reference to the local version:
$ cd ../src # sqlitecloud src directory
$ pip install -e .
Then, run the test suite with:
$ 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.pyfile. 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:
sstep intonnext linerjump to the end of the functionccontinuewprint stack trace
More info: https://docs.python.org/3/library/pdb.html
Metadata
Release files for sqlalchemy-sqlitecloud 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy-sqlitecloud-0.1.2.tar.gz | 5.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / sqlalchemy-sqlitecloud-0.1.2.tar.gz
| Download URL | sqlalchemy-sqlitecloud-0.1.2.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e351bec6722a469250dc3d05c6caaf5b57f1584d0fec2de3a2b3708cb441475
|
|
BLAKE2b-256 checksum How to use checksums |
855b96601abf2e38288785f42ea0b3f825ffe08b8b4af393f304c3fbef4fe10f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.19 tqdm/4.64.1 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|
Release files / sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl
| Download URL | sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be5ad4d0b14a54739f02c9c307dfddeb37a950893fbd1be116826829a3232d76
|
|
BLAKE2b-256 checksum How to use checksums |
7ff6f2a5c49495ff841f9269b0f49f88105541fbb6d15137c514f818ca5869d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.19 tqdm/4.64.1 importlib-metadata/4.2.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
|