Skip to main content

Traducteur 是一个使用 pydantic 模型的简单数据库管理器。目前只支持mongodb。

项目描述

翻译家

Traducteur 是一个基于 pydantic 模型的数据库管理器。目前只支持mongodb。

要求

  • python >= 3.8和:
    • pymongo >= 4.0.1
    • pydantic >= 1.9.0

示例用法

'''
    Set a connection string and database name in the environment.
    Preferably using a .env file.
'''
import os

CON_STR = 'mongodb://root:example@localhost:27017/'
DB_NAME = 'traducteur'

os.environ['TRADUCTEUR_CONNECTION_STR'] = CON_STR
os.environ['TRADUCTEUR_DATABASE'] = DB_NAME


'''
    Import the base model for the database you are using.
'''

from traducteur import BaseMongoModel

'''
    Make a model using the base model.
'''

class User(BaseMongoModel):
    username: str
    fname: str
    lname: str
    email: str

'''
    Easily create, save, update and delete the model
'''
user = User(
    username='johndoe',
    fname='John',
    lname='Doe',
    email='john.doe@mail.com'
)

# saving the model
user = user.save()

# saving also updates the model
user.lname = 'Doe updated'
user = user.save()

# save the user id and set user to None for the GET example
user_id = user.id
user = None

# getting a model by its ID from the database
user = User.get(user_id)
print(user.dict())

# deleting a model from the database
deleted_user = user.delete()

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

traducteur-0.1.9.tar.gz (6.3 kB 查看哈希

已上传 source

内置分布

traducteur-0.1.9-py3-none-any.whl (7.5 kB 查看哈希

已上传 py3