Skip to main content

A relational database -like table of rows.

Project description

RelaTable

A relational database -like table of rows.

Supports foreign key -style referencing to an another RelaTable or other containers.

An Example

from relatable import RelaTable

colors = ["red", "blue", "green"]
pet_names = {"dog": "Musti", "cat": "Mirri"}

persons = RelaTable(
    primary_key_column="id",
    foreign_keys={"color": colors},
    rows=[
        {"id": 123, "name": "Jaakko", "color": 0},
        {"id": 456, "name": "Teppo", "color": 1},
    ],
)

# Insert new user in the middle of the table
persons.insert(1, {"id": 789, "name": "Seppo", "color": 2})

pets = RelaTable(
    # No primary key defined => index is used
    foreign_keys={"name": pet_names, "owner": persons},
    rows=[
        {"name": "cat", "owner": 123},  # index 0
        {"name": "dog", "owner": 456},  # index 1
    ],
)

print(persons)
# Prints out:
#   [{'id': 123, 'name': 'Jaakko', 'color': 'red'},
#    {'id': 789, 'name': 'Seppo', 'color': 'green'},
#    {'id': 456, 'name': 'Teppo', 'color': 'blue'}]

print(pets)
# Prints out:
#   [{'name': 'Mirri', 'owner': {'id': 123, 'name': 'Jaakko', 'color': 'red'}},
#    {'name': 'Musti', 'owner': {'id': 456, 'name': 'Teppo', 'color': 'blue'}}]

print(persons[789].name)
# Prints out:
#   Seppo

print(pets[0].owner.color)
# Prints out:
#   red

print(pets[0].data())
# Prints out the non-expanded row data:
#   {'name': 'cat', 'owner': 123}

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

talamus_relatable-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

talamus_relatable-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file talamus_relatable-1.0.0.tar.gz.

File metadata

  • Download URL: talamus_relatable-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-52-generic

File hashes

Hashes for talamus_relatable-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bddfc5a683d2e534a91a7213c1a697a07c2a13f4435382a1a1fc789bbd8c9846
MD5 ee11aed6ff5f4202ce7dd1c86e4acc2b
BLAKE2b-256 b2d00753b57c299438d5c11a78f2549225a245d6a505cc1d3685b82c34941efb

See more details on using hashes here.

File details

Details for the file talamus_relatable-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: talamus_relatable-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-52-generic

File hashes

Hashes for talamus_relatable-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a556a9ac92b669a90f83e5247cdd68174d8f8c81a21d0e1bbebe261a023434d7
MD5 fa26c018b196212f05aad177c4fe94dd
BLAKE2b-256 ddbccfc20c950c021e0cb0e790080f9e9f2840bcac30ac086869d2bd4971c701

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