Repository navigation
v0.2.0
Added
- One-to-many relationship between tables
Example
To define a foreign key, use other models as fields in the model.
from ormagic import DBModel
class User(DBModel):
name: str
class Post(DBModel):
title: str
content: str
user: User
User.create_table()
Post.create_table()
user = User(name="John")
user.save()
Post(title="Hello", content="World", user=user).save()
# You can also save child models with new parent object in one step, this will save the parent object first and then the child object
Post(title="Hello", content="World", user=User(name="Alice")).save()Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Relationships between tables
- One-to-many
- Create a tables with a foreign key
- Save data with a foreign key
- Read data with a foreign key
- Update data with a foreign key
- Delete data with a foreign key
- Set null
- Cascade
- Restrict
- No action
- Set default
- One-to-one
- Many-to-many
- One-to-many
- Custom primary key
- Bulk operations (save, update, delete)
- Migrations
Full Changelog: v0.1.0...v0.2.0