Skip to main content

SQLALchemy JSONField implementation for storing dicts at SQL

Project description

SQLAlchemy_JSONField

https://travis-ci.org/penguinolog/sqlalchemy_jsonfield.svg?branch=master https://coveralls.io/repos/github/penguinolog/sqlalchemy_jsonfield/badge.svg?branch=master https://img.shields.io/circleci/project/github/penguinolog/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/v/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/pyversions/sqlalchemy_jsonfield.svg https://img.shields.io/pypi/status/sqlalchemy_jsonfield.svg https://img.shields.io/github/license/penguinolog/sqlalchemy_jsonfield.svg

SQLALchemy JSONField implementation for storing dicts at SQL independently from JSON type support.

Why?

SqlAlchemy provides JSON field support for several database types (PostgreSQL and MySQL for now) and semi-working dict <-> JSON <-> VARCHAR example, but… In real scenarios we have tests on sqlite, production on MySQL/MariaDB/Percona/PostgreSQL and some of them (modern Oracle MySQL & PostgreSQL) support JSON, some of them (SQLite, Percona & MariaDB) requires data conversion to Text (not VARCHAR).

As addition, we have different levels of Unicode support on database and connector side, so we may be interested to switch JSON encoding between deployments.

Solution:

SQLALchemy JSONField has API with suport for automatic switch between native JSON and JSON encoded data, and encoding to JSON string can be enforced.

Pros:

Python 2.7
Python 3.4
Python 3.5
Python 3.6
PyPy
PyPy3

Usage

Direct usage with MariaDB (example extracted from functional tests):

import sqlalchemy_jsonfield

class ExampleTable(Base):
    __tablename__ = table_name
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    row_name = sqlalchemy.Column(
        sqlalchemy.Unicode(64),
        unique=True,
    )
    json_record = sqlalchemy.Column(
        sqlalchemy_jsonfield.JSONField(
            # MariaDB does not support JSON for now
            enforce_string=True,
            # MariaDB connector requires additional parameters for correct UTF-8
            enforce_unicode=False
        ),
        nullable=False
    )

Usage on PostgreSQL/Oracle MySQL(modern version)/SQLite(testing) environments allows to set enforce_string=False and use native JSON fields.

Testing

The main test mechanism for the package sqlalchemy_jsonfield is using tox. Test environments available:

pep8
py27
py34
py35
py36
pypy
pypy3
pylint
docs

CI systems

For code checking several CI systems is used in parallel:

  1. Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.

  2. coveralls: is used for coverage display.

  3. Circle CI: is used for functional tests at separate docker infrastructure. This CI used for HUGE tests.

CD system

Travis CI: is used for package delivery on PyPI.

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_JSONField-0.5.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

SQLAlchemy_JSONField-0.5.0-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file SQLAlchemy_JSONField-0.5.0.tar.gz.

File metadata

File hashes

Hashes for SQLAlchemy_JSONField-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8866169a56ef932d6c14fef5fd4b9be663455c594f5cfb3ce326d0b31ed183cb
MD5 f792b4227ef0ca91dd7e4bdadfa93885
BLAKE2b-256 c549f59b4867d94b6abc80959273d7903ccd5d52e4e1a17248bbee8613d89bd1

See more details on using hashes here.

File details

Details for the file SQLAlchemy_JSONField-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for SQLAlchemy_JSONField-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f361d7f0fc7194319381b987a88f26da2eeaa6fd2391c5d77e2c4a80db90fd21
MD5 b398e55d2fccb429d0e5bbb7846156ed
BLAKE2b-256 a36d196489c10bc5e21024a752d8a4920c8c98abd12b5b0e15f9550dcdb1ed88

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