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.

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 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.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

sqlalchemy_sqlitecloud-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlalchemy-sqlitecloud-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 80051f2626bb8482d7ae73635c54acb8f97a134e57d69dd792a2d488d0345523
MD5 57fdc75005c73b747346cbefa2ee1e45
BLAKE2b-256 d846bda10aaf7eaa9f8d7a4870d08e71e965675f8c3d38575c5da862b19b071a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlalchemy_sqlitecloud-0.1.0-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

Hashes for sqlalchemy_sqlitecloud-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e4c1ef98ec0377915d1cd2076f45950b38ac43be72bb3f07d18c05e4c46db14
MD5 b11180516f24a3dbe19b707865af6963
BLAKE2b-256 4a212dab3ab4ea0d0fb2a619c65fcded5aef0755c719c8275a8b7255f8bed18a

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