Skip to main content

Python library to create databases

Project description

Pypi version Python versions Black


relationaldb

RelationalDB is a python ODM library for MongoDB that allows you to design collections like you do it for your normal dataclasses objects.

DISCLAMER

This library is in alpha-release, it's a work in progress for the moment, excellent libraries for MongoDB ODM in python exist:

There are a lot of none implemented main features (I implement them when I have time or when I need it for my project).

Quickstart

relationaldb wraps attrs to create classes boilerplate and add few parameters.

One to Many relation

Let's say you want a simple one to many relations, with two entities: Animal and Person.

  • Each animal can have one owner (Person)
  • Each person can have 0 to many animals
from relationaldb import conception

# Object to design the architecture of the database
c = conception()


# Add collection woth 'define' like with attrs
@c.define
class Person:
    # add new attribute with 'field' method
    # in_filter_query parameter allows to use the 'db.Person.feed' method to upsert new documents
    name: str = c.field(in_filter_query=True)

    # all attrs.fields parameters are available
    money: int = c.field(kw_only=True, default=0)
    birth_year: int = c.field(kw_only=True, default=None)


@c.define
class Animal:
    # We can reference
    name: Person = c.field(in_filter_query=True)

    owner: Person = c.field(kw_only=True, default=None)
    birth_year: int = c.field(kw_only=True, default=None)


# Create a new mongodb named "mydb"
db = c.mongodb("relationaldb_mydb_01")

# Create second DB with same architecture
db2 = c.mongodb("relationaldb_mydb_02")

# Create a new person
db.Person.insert_one("John")

# Get the person
person = db.Person.first()
assert isinstance(person, Person)
assert person.name == "John"

for person in db.Person:
    print(person)

# Upsert (create or update) person named 'Smith' if it does not exists (based on in_filter_query)
db.Person.feed("Smith")  # will create the person
db.Person.feed("Smith")  # will do nothing, person already exist
db.Person.feed("Smith", money=1000)  # will update the person 'Smith'

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

relationaldb-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

relationaldb-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file relationaldb-0.1.0.tar.gz.

File metadata

  • Download URL: relationaldb-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for relationaldb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9cb317884d2012ab3582cab2fae8e15dcb23f5b9f2440e7e5b980549dc08cf6d
MD5 6b12c84767248868cbf7c3c2c821d256
BLAKE2b-256 55301b397bf262c3b82394ed4bbdc1ff69226ac7809638d8754e3276753a2231

See more details on using hashes here.

File details

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

File metadata

  • Download URL: relationaldb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for relationaldb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 acaf8a2181a693c7300b292135798fa7cdfe16d5254766dbd74a70774075a0f7
MD5 a2a3be8571e48477f6232ec1b7dcd638
BLAKE2b-256 9be4afd8ff9094c1c41006751b8d98d433d9b2ecee1672218c94758c46fbd729

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