Skip to main content

No project description provided

Project description

relations-dil

DB/API Modeling

Relations is designed to be a simple, straight forward, flexible DIL (data interface layer).

Quite different from other DIL's, it has the singular, microservice based purpose to:

  • Create models with very little code, independent of backends
  • Create CRUD API with a database backend from those models with very little code
  • Create microservices to use those same models but with that CRUD API as the backend

Ya, that last one is kinda new I guess.

Say we create a service, composed of microservices, which in turn is to be consumed by other services made of microservices.

You should only need to define the model once. Your conceptual structure is the same, to the DB, the API, and anything using that API. You shouldn't have say that structure over and over. You shouldn't have to define CRUD endpoints over and over. That's so boring, tedious, and unnecessary.

Furthermore, the conceptual structure is based not the backend of what you've going to use at that moment of time (scaling matters) but on the relations, how the pieces interact. If you know the structure of the data, that's all you need to interact with the data.

So with Relations, Models and Fields are defined independent of any backend, which instead is set at runtime. So the API will use a DB, everything else will use that API.

This is package is just a piece of that whole process, the base abstract classes, etc. But with a mock source, you can see how it all works.

Example

import relations

# The SOURCE in a model is a string, used to access a source in Relations's global registry

class Base(relations.Model):
    SOURCE = "example"

# The Models automatically have the same SOURCE by using this Base

class Unit(Base):
    id = int
    name = str

class Test(Base):
    id = int
    unit_id = int  # Relations aren't defined here, but outside the models
    name = str

# Creation a Relation from unit.id to test.unit_id (default)

relations.OneToMany(Unit, Test)

# This defines the "example" source to be an in memory store

relations.unittest.MockSource("example")

# Create Unit named yep and store

Unit("yep").create()

# Query a single Unit with the name "yep" and access its id
Unit.one(name="yep").id # 1

# Create two Units, named people and stuff, because name is the first non readdonly field
Unit([["people"], ["stuff"]]).create()

# Retrieve a single Unit with name stuff, and set the name to "things" (but don't save)
unit = Unit.one(name="stuff").set(name="things")

# Save the update (returns number of records updated))
unit.update() # 1

# Retrieve a single Unit with id 2, and set the name to "thing"
unit = Unit.one(2)
unit.name = "thing"

# Add a child test with name "more" (first non readonly that's not already set)

unit.test.add("moar")
unit.update()

# Find all the Tests with a parent Unit with name "thing", and an id greater than 0
tests = Test.many(unit__name="thing", id__gt=0)
tests[0].name # "moar"

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

relations_dil-0.6.15.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

relations_dil-0.6.15-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file relations_dil-0.6.15.tar.gz.

File metadata

  • Download URL: relations_dil-0.6.15.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for relations_dil-0.6.15.tar.gz
Algorithm Hash digest
SHA256 282f03fca2bbdb8b451da19abc7804cf23100f5c6a980ae2593a0ac43ccf1022
MD5 de6be0d3be56b1d7e9f2ba701a51c5de
BLAKE2b-256 e6f58327aab0cfbaf88fa3014e21822f9c834959eaf95a964a3c8d0a8f0b3310

See more details on using hashes here.

File details

Details for the file relations_dil-0.6.15-py3-none-any.whl.

File metadata

  • Download URL: relations_dil-0.6.15-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for relations_dil-0.6.15-py3-none-any.whl
Algorithm Hash digest
SHA256 55683bb35335b97290763d60aa3793e70adbd118459acd7aee3d83dbef2ad8ef
MD5 076d08d7a15bb7fda2878ad0c1b3a48a
BLAKE2b-256 67fd184bb1e73fa866e0e07bb2a2e3ca1ea748742c76d8718580bc36e07506c5

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