CRUD Operations

AN5 ORM provides a clean, type-safe API for all CRUD operations tailored for Python.


Client Setup

from an5_client import An5Client

db = An5Client()  # automatically connects to DATABASE_URL

1. Create

Create a Single Record

user = db.user.create(data={
    "email": "john@example.com",
    "name": "John Doe"
})
print("Created user:", user)

Create Many Records

# Batch creation in Python
users = [
    db.user.create(data={"email": "alice@example.com", "name": "Alice"}),
    db.user.create(data={"email": "bob@example.com", "name": "Bob"}),
]

2. Read

Find by Primary Key or Unique Field

user = db.user.find_first(
    where={"email": "john@example.com"}
)

Find Many Records with Filter & Sort

users = db.user.find_many(
    where={
        "isActive": True,
        "email": {"contains": "@example.com"}
    },
    order_by={"createdAt": "desc"},
    skip=0,
    take=10,
)

Keys are the schema field names (isActive, createdAt). The Python SQL builder quotes a key verbatim, so the snake_case spelling the generated dataclasses use would compile to a column that does not exist.


3. Update

Update Single Record

updated = db.user.update(
    where={"id": user["id"]},
    data={"name": "Johnny Doe"}
)

4. Delete

Delete Single Record

db.user.delete(where={"id": user["id"]})

Next Steps