SQLAlchemy Dialect for SQLite Cloud.
Project description
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.
Note: It has been tested only 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 both Python 3.6 and Python 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.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 inton
next liner
jump to the end of the functionc
continuew
print stack trace
More info: https://docs.python.org/3/library/pdb.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sqlalchemy-sqlitecloud-0.1.1.tar.gz
.
File metadata
- Download URL: sqlalchemy-sqlitecloud-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed25373eaf10c9a5029a0f4cc6e0c328c254fc21977c550eb20f250a3d351081 |
|
MD5 | 9037414b2b1a945a2378328f49193d5e |
|
BLAKE2b-256 | 1167d0ece8ae24c9e49a6ab019f7fb6234e9b8b4b909dcb6b785dba925dd4062 |
File details
Details for the file sqlalchemy_sqlitecloud-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_sqlitecloud-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 336433bed34076c8c3af00f5515b18478f8b6651c7d9f44b32bc4715f0e33b79 |
|
MD5 | c381d6dbd43bedd9ef66504754d142f5 |
|
BLAKE2b-256 | 40520f848ff6ced54fae3fe4aa76c7154fd90f69f3ece5a7e8c02606b1d71fa7 |