Nestipy dababase adapter for edgy
Project description
NestipyDB
NestipyDB is the official database module for Nestipy. It is built on top of Edgy and designed to be modular and configurable.
Installation
NestipyDB depends on Edgy. Make sure to follow the Edgy installation guide to set up dependencies for your specific database.
pip install nestipy-db
Usage
First, in your app_module.py, replace the url in DbConfig with your own:
from nestipy.common import Module
from nestipy_db import DbConfig, DbModule,AdminConfig
@Module(
imports=[
DbModule.for_root(
DbConfig(
url="sqlite:///db.sqlite",
models=[],
admin=AdminConfig(enable=True, url="/admin"), # if you need admin dashboard for model
)
),
# other modules...
]
)
class AppModule:
...
To load the config asynchronously, use DbModule.for_root_async:
from typing import Annotated
from nestipy.common import Module
from nestipy.ioc import Inject
from nestipy_config import ConfigModule, ConfigService, ConfigOption
from nestipy_db import DbConfig, DbModule
async def get_db_config(config: Annotated[ConfigService, Inject()]):
return DbConfig(
url=config.get("DATABASE_URL"),
models=[]
)
@Module(
imports=[
ConfigModule.for_root(ConfigOption(), is_global=True),
DbModule.for_root_async(
factory=get_db_config,
inject=[ConfigService]
),
# other modules...
]
)
class AppModule:
...
Models
Every model must be decorated with Model and must extends BaseModel from nestipy_db
from datetime import datetime
from uuid import UUID, uuid4
import edgy
from ..user.user_model import User
from nestipy_db import BaseModel, Model
@Model()
class Post(BaseModel):
id: UUID = edgy.UUIDField(primary_key=True, default=uuid4, editable=False)
title: str = edgy.CharField(max_length=256, default="")
user: User = edgy.ForeignKey(User, on_delete=edgy.CASCADE, related_name="posts")
reaction: list[User] = edgy.ManyToManyField(
User, through_tablename=edgy.NEW_M2M_NAMING
)
created_at: datetime = edgy.DateTimeField(auto_now_add=True)
updated_at: datetime = edgy.DateTimeField(auto_now=True)
Note
Note that, you need to register all of your models inside DbConfig(..., models=[]) or by importing DbModule.for_feature(Model1, Model2) in your current module.
CLI
NestipyDB aliases Edgy CLI commands and adds support for model generation.
Instead of using edgy, use:
nestipy run db #follow edgy command
NestipyDB introduces a new model generation command:
nestipy run db new|g|gen|generate model_name module_name
module_nameis optional.- If omitted,
model_namewill also be used as themodule_name. - The model will be created inside the specified module, or the module folder will be created if it doesn't exist.
Admin
If admin is enabled, you can access it with the url specified in AdminConfig. The default credential for llogin is email: test@admin.com,password: admin.
You can override this via AdminConfig. Other options are also available.
Support
Nestipy is an MIT-licensed open source project. It continues to grow thanks to support from the community. If you'd like to contribute or sponsor, please [read more here].
Stay in Touch
- Author - Tsiresy Mila
License
Nestipy is MIT licensed.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nestipy_db-0.2.0.tar.gz.
File metadata
- Download URL: nestipy_db-0.2.0.tar.gz
- Upload date:
- Size: 864.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afd0340558b889790675971674983b02fba33b96cf9cdce0afe3af93b05a462b
|
|
| MD5 |
dcbbe7dc8bb967a589f580806debd2b8
|
|
| BLAKE2b-256 |
b4a71e3794cc46c5d76f38ce76ad261491ec3062e04d4326a13d437e09e18e62
|
File details
Details for the file nestipy_db-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nestipy_db-0.2.0-py3-none-any.whl
- Upload date:
- Size: 590.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4af315785ab161dda96d86cd08f05a02dd76dd9617ada4021488f2785195ae1
|
|
| MD5 |
b6cac740443c497574654e146f088f87
|
|
| BLAKE2b-256 |
71e3642d5c1aba570bb4cdfb75b60c5dc05daa08a1b8def08869fbd19748dc03
|