Skip to main content

SQLAlchemy Dialect for SQLite Cloud.

Project description

SQLite Cloud Dialect for SQLAlchemy (Beta)

PyPI - Version PyPI - Downloads PyPI - Python Version

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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy-sqlitecloud-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-sqlitecloud-0.1.2.tar.gz.

File metadata

  • Download URL: sqlalchemy-sqlitecloud-0.1.2.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

Hashes for sqlalchemy-sqlitecloud-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0e351bec6722a469250dc3d05c6caaf5b57f1584d0fec2de3a2b3708cb441475
MD5 dc764ee1554a6a94f95512a23070607c
BLAKE2b-256 855b96601abf2e38288785f42ea0b3f825ffe08b8b4af393f304c3fbef4fe10f

See more details on using hashes here.

File details

Details for the file sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 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

Hashes for sqlalchemy_sqlitecloud-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be5ad4d0b14a54739f02c9c307dfddeb37a950893fbd1be116826829a3232d76
MD5 13f01b157bde2a6178d424c231ede97e
BLAKE2b-256 7ff6f2a5c49495ff841f9269b0f49f88105541fbb6d15137c514f818ca5869d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page