Skip to main content

A fast and efficient way to interact with databases using pydantic models

Project description

DataModel ORM

DataModel ORM is a Python library that provides a fast and efficient way to interact with databases using Pydantic models.

Installation

Use the package manager pip to install DataModel.

pip install datamodel_orm

Usage

This example demonstrates how to use the User data model in Python. The User data model is defined using Pydantic and includes fields for id, name, and age.

Setup

First, import the necessary modules and define the User data model.

from typing import Optional
from pydantic import Field
from data_model_orm import DataModel

class User(DataModel):
    id: Optional[int] = Field(json_schema_extra={"primary_key": True}, default=None)
    name: str
    age: int

Creating the Data Source

Create the data source for the User model. If the data source already exists, this operation will be ignored.

User.create_source(ignore_if_exists=True)

Saving a New User

To save a user, instantiate the User class and call the save method.

user = User(name="John", age=30)
user.save()
print(user.id)  # Prints the ID of the newly created user

Retrieving a User

To retrieve a user, use the get_one method and provide the user's name.

user = User.get_one(name="John")

Retrieving All Users with a Specific Name

To retrieve all users with a specific name, use the get_all method and provide the name.

users = User.get_all(name="John")

Deleting a User

To delete a user, call the delete method on a User instance.

user.delete()

Please note that the actual usage may vary depending on the implementation of the DataModel class and the data source.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

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

datamodel_orm-0.1.0a0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

datamodel_orm-0.1.0a0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file datamodel_orm-0.1.0a0.tar.gz.

File metadata

  • Download URL: datamodel_orm-0.1.0a0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for datamodel_orm-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 a27b3ccd29d552e8daa0fef0cb30024c28552704893e3e10c97f1bf1c7a7496a
MD5 327dbf8678e2ab0ef8c583edfcedc30d
BLAKE2b-256 55b4220c41544bab7bd9fd87ff28dddf357b65c557adcd0016d4a4eaec3742c0

See more details on using hashes here.

File details

Details for the file datamodel_orm-0.1.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for datamodel_orm-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 3353e7fec2b658e12e0746da307125618911e694d6e0e1750f3942c095eb16e0
MD5 97b6f28864fd4863c2cefe6116018155
BLAKE2b-256 fb2b1b969c0b25dbab7c446fd1fe020b3a00b7b36cd77585e4ca2b183d563552

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