Hojo: An ORM built on top of SQL Alchemy
Project description
Hojo - An Opinionated ORM on Top of SQL Alchemy
Hojo is a library that simplifies the usage of SQL Alchemy, providing an interface that is familiar to Django users. While it is not an exact replication of the Django ORM API, it strives to be reminiscent of it, making it easier for Django developers to work with SQL Alchemy.
Please note that this library is currently in Alpha version and is not yet ready for production use.
Installation
You can install Hojo using pip:
pip install hojo
Basic Usage
Here's a basic example of how to use Hojo:
# file: models.py
from hojo import automap, model
@model
class Soldier:
name: str
weapon: str
level: int
# Create the mappers automatically
automap()
# file: query.py
# Insert the hero into the 'soldiers' table
hero = Soldier.objects.create(name='Cloud Strife', weapon='Buster Sword', level=50)
# Insert the antagonist into the 'soldiers' table
antagonist = Soldier.objects.create(name='Sephiroth', weapon='Masamune', level=99)
# Retrieve a Soldier with the name 'Cloud' from the 'soldiers' table
soldier = Soldier.objects.filter(name='Cloud Strife')
# Retrieve a Soldier filtering by the weapon
soldier = Soldier.objects.filter(weapon__startswith='Buster')
# Retrieve a list of Soldiers filtering by level greater than 10
soldiers = Soldier.objects.filter(level__gt=10)
Schema usage
Hojo provides a BaseSchema class, that you can use with attrs @define and get some abstractions over it:
from attrs import define
from hojo import BaseSchema
from enum import StrEnum
class MateriaType(StrEnum):
MAGIC = 'magic'
SUPPORT = 'support'
SUMMON = 'summon'
COMMAND = 'command'
@define
class Materia(BaseSchema):
name: str
materia_type: MateriaType
ifrit = Materia.load({'name': 'Ifrit', 'materia_type': 'summon'})
print(ifrit) # => Materia(name='Ifrit', materia_type=<MateriaType.SUMMON: 'summon'>)
print(ifrit.dump()) # => {'name': 'Ifrit', 'materia_type': 'summon'}
print(ifrit.dump(only=['name'])) # => {'name': 'Ifrit'}
print(ifrit.dump(exclude=['name'])) # => {'materia_type': 'summon'}
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
Built Distribution
File details
Details for the file hojo-0.2.0.tar.gz
.
File metadata
- Download URL: hojo-0.2.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.13 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2ced36964bfde364d4902b7e2ca9d59b2d722cab1b1038febc43403e3522f8 |
|
MD5 | 5ab2c463b25f2dfebd290e0546a8f90c |
|
BLAKE2b-256 | 5575fa81e9cc68295c048e66937f8a1e46e7d27431503bf7e1b1642f76cc5817 |
File details
Details for the file hojo-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: hojo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.13 Darwin/22.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb2940e04ebac1bb994a7bfa5136d309dbf77c67b9555a877cef52a4ace1f29a |
|
MD5 | abda0f314fa822f1923f68add12c667d |
|
BLAKE2b-256 | 6e2f00eb0fbfba031c1a414dd271bfae3cffbe6b874bec7b9f4487e8ad291899 |