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-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

datamodel_orm-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: datamodel_orm-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for datamodel_orm-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f3650fc95d6c8e7d8d7df3a331a04c16e84ed8d7f4c53d111a3c97694c3f355c
MD5 23a7adb5007eccbe98c8130706c6d21b
BLAKE2b-256 fdda29b950c7ea86ee1ba249934af9df32dbce40377eae74f4120968be8c23de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datamodel_orm-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for datamodel_orm-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fcc4a4f8698e8927971feacab30de986521c9f00e687d509f139ff4b51e6c05
MD5 9838a60b8d30c4765053c91e38038109
BLAKE2b-256 787cac1556e5b8c67939c43ef5f149381e11e21bfeed264fc3f7beb13c795aee

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