Skip to main content

Using dataclasses with SQL databases.

Project description

dataclasses-sql

GitHub Workflow Status PyPI

Using dataclasses with SQL databases.

Examples:

import dataclasses
import sqlalchemy
import dataclasses_sql

@dataclasses.dataclass
class Car:
    brand: str = dataclasses.field(metadata={"key": True})
    model: str = dataclasses.field(metadata={"key": True})
    milage: float

# Connect to database
engine = sqlalchemy.create_engine("sqlite:///:memory:")
metadata = sqlalchemy.MetaData(engine)
metadata.reflect()

# Insert
car = Car("Kia", "Ceed", 15678)
dataclasses_sql.insert(metadata, car, check_exists=True)

car = Car("Ford", "Mustang", 4032)
dataclasses_sql.insert(metadata, car, check_exists=True)

# Select
builder = dataclasses_sql.SelectStatementBuilder()
builder.add_column(Car, "mileage")
builder.add_clause(Car, "brand", "Kia")
statement = builder.build()

with metadata.bind.begin() as conn:
    row = conn.execute(statement).fetchone()
    print(row)

Installation

Easiest way to install using pip:

pip install dataclasses-sql

For development installation from the git repository::

git clone git@github.com/ppinard/dataclasses-sql.git
cd dataclasses-sql
pip install -e .

Release notes

0.3

  • Add delete function

0.2

  • Add update function

Contributors

License

The library is provided under the MIT license license.

Copyright (c) 2020, Philippe Pinard

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

dataclasses-sql-0.3.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dataclasses_sql-0.3.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file dataclasses-sql-0.3.0.tar.gz.

File metadata

  • Download URL: dataclasses-sql-0.3.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for dataclasses-sql-0.3.0.tar.gz
Algorithm Hash digest
SHA256 15ea499f3b1a36c737b8faf4c543de0570dc10e595cbd865f08be4a0ce14e1e1
MD5 117bb58c45875586b29e47f22bd087dd
BLAKE2b-256 13d18f5d6679572af2afb6b5e716bfb0c2285e74be7c3d2e23c34cb6b551f748

See more details on using hashes here.

File details

Details for the file dataclasses_sql-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dataclasses_sql-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for dataclasses_sql-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12741b947d7c43bcd6d0972fde7b4dcba3c99ea6e5e5103424d994307c82b2a7
MD5 99cbfd273373ffe2ca4986e47903ee3d
BLAKE2b-256 18b37577fc93a2bb67c9d24b0c1a24f68e38195077339dcfd1059456b8be807a

See more details on using hashes here.

Supported by

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