Nivo ORM - A lightweight async ORM for Python using SQLite and aiosqlite.
Project description
Nivo ORM
Nivo یک ORM سبک و غیرهمزمان (async) برای Python است که با استفاده از aiosqlite ساخته شده و مدیریت پایگاه داده SQLite را ساده میکند.
این کتابخانه برای پروژههایی مناسب است که میخواهند از پایگاه داده SQLite به صورت async استفاده کنند و نیازی به ORM های سنگین ندارند.
ویژگیها
- پشتیبانی کامل از CRUD (ایجاد، خواندن، بروزرسانی، حذف)
- روابط یک به چند (ForeignKey)
- روابط چند به چند (ManyToMany)
- async / await
- ساده و سبک
- مدیریت تراکنشها با
atomic()
نصب
با pip:
pip install aiosqlite
pip install git+https://github.com/Mahdy-Ahmadi/nivo.git
یا اگر فایل setup.py دارید:
python setup.py install
استفاده
import asyncio
from nivo import *
# --- Models ---
class Author(Model):
name = CharField(max_length=100)
class Book(Model):
title = CharField(max_length=200)
author = ForeignKey(Author)
async def main():
# Connect to the database
db = Connection("library.db")
await db.connect()
# Bind models to the database
Author.bind(db)
Book.bind(db)
# Create tables
await Author.create_table()
await Book.create_table()
# Clear previous data (for testing)
await db.cur.execute("DELETE FROM Author")
await db.cur.execute("DELETE FROM Book")
await db.conn.commit()
# Create an author
author = await Author.create(name="George Orwell")
print("✅ Author created:", author.id, author.name)
# Create books
await Book.create(title="1984", author=author)
await Book.create(title="Animal Farm", author=author)
print("✅ Two books added.")
# Display all books
print("\n📚 All books:")
books = await Book.objects().all()
for book in books:
book_author = await book.author
print(f"- {book.title} (Author: {book_author.name})")
# Get the first book
first_book = await Book.objects().first()
print("\n📖 First book:", first_book.title)
# Update a book title
await Book.objects().filter(title="1984").update(title="Nineteen Eighty-Four")
updated_book = await Book.objects().filter(title="Nineteen Eighty-Four").first()
print("\n✏️ After update:", updated_book.title)
# Delete a book
await Book.objects().filter(title="Animal Farm").delete()
remaining_books = await Book.objects().all()
print("\n❌ After deleting 'Animal Farm':")
for book in remaining_books:
print("-", book.title)
# Close the database connection
await db.close()
if __name__ == "__main__":
asyncio.run(main())
License
MIT License
لینکها
Project details
Release history Release notifications | RSS feed
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 nivo-1.0.0.tar.gz.
File metadata
- Download URL: nivo-1.0.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dc18b30922e3c784f206d04fc4cd68dd2cff8bf57f1e16921c6590f096d005f
|
|
| MD5 |
4ed6161c7d39b66a76f7cad073f0fd9f
|
|
| BLAKE2b-256 |
ecd1c7fbe335febd9eef9f466491eff6fb05741d3a4c53d75708da2ef772f7fd
|
File details
Details for the file nivo-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nivo-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18bbb6e537288a42cebbf9cb88de6b78201f4928425396c2597fc76fb0bfe6ed
|
|
| MD5 |
b3e9ef4da43a5eea2f7cb0559ea2fbf0
|
|
| BLAKE2b-256 |
644a43e2f4c9330d99bca44047503e64f28a96b154d29bc55993aad22aee8a39
|