Skip to main content

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


لینک‌ها

Metadata

Release files for nivo 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nivo 1.0.0
File Size Uploaded
nivo-1.0.0.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nivo 1.0.0
File Interpreter ABI Platform
nivo-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / nivo-1.0.0.tar.gz

Download URL nivo-1.0.0.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6dc18b30922e3c784f206d04fc4cd68dd2cff8bf57f1e16921c6590f096d005f
BLAKE2b-256 checksum
How to use checksums
ecd1c7fbe335febd9eef9f466491eff6fb05741d3a4c53d75708da2ef772f7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / nivo-1.0.0-py3-none-any.whl

Download URL nivo-1.0.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18bbb6e537288a42cebbf9cb88de6b78201f4928425396c2597fc76fb0bfe6ed
BLAKE2b-256 checksum
How to use checksums
644a43e2f4c9330d99bca44047503e64f28a96b154d29bc55993aad22aee8a39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page