Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.cocobase.buzz/llms.txt

Use this file to discover all available pages before exploring further.

Quick Reference

Query Operators

# Comparison
db.query("posts", status="published")           # Equal
db.query("posts", status_ne="draft")            # Not equal
db.query("posts", views_gt="100")               # Greater than
db.query("posts", views_gte="100")              # Greater or equal
db.query("posts", views_lt="1000")              # Less than
db.query("posts", views_lte="1000")             # Less or equal

# String
db.query("posts", title_contains="python")      # Contains
db.query("posts", title_startswith="How to")    # Starts with
db.query("posts", email_endswith="@gmail.com")  # Ends with

# Array
db.query("posts", status_in="published,featured")   # In array
db.query("posts", category_notin="spam,nsfw")        # Not in array

# Null check
db.query("posts", deleted_at_isnull="true")     # Is null

Boolean Logic

# Simple OR
db.query("posts", **{
    "[or]status": "published",
    "[or]status_2": "featured"
})

# OR across different fields
db.query("posts", **{
    "[or]title_contains": "python",
    "[or]content_contains": "python"
})

# Named OR groups (ANDed together)
db.query("posts", **{
    "[or:cats]category": "tech",
    "[or:cats]category_2": "programming",
    "[or:status]status": "published",
    "[or:status]status_2": "featured"
})

Relationships

# Single relationship
db.query("posts", populate=["author"])

# Multiple relationships
db.query("posts", populate=["author", "category", "tags"])

# Nested population
db.query("posts", populate=["author.company.location"])

# Filter by relationship field
db.query("posts", **{"author.role": "admin"}, populate=["author"])

# Select specific fields
db.query("posts", populate=["author"], select=["id", "title", "author"])

User Queries

# Query users
db.query_users(role="premium", age_gte="18", limit=50)

# Find user
db.find_user(id="user-123")
db.find_user(email="john@example.com")

# User relationships
db.get_user_relationships("user-123", "followers", limit=50)
db.get_user_relationships("user-123", "following", limit=50)

# User documents
db.get_user_collections("user-123", "posts", limit=20)

# Add/remove relationships
db.add_user_relationship("user-1", "user-2", "following")
db.remove_user_relationship("user-1", "user-2", "following")

Common Patterns

Pagination

page = 1
per_page = 20

result = db.query("posts",
    status="published",
    limit=per_page,
    offset=(page - 1) * per_page,
    sort="created_at",
    order="desc"
)

return {
    "data": result["data"],
    "page": page,
    "total": result["total"],
    "has_more": result["has_more"]
}
keyword = req.get("keyword", "")

posts = db.query("posts", **{
    "[or]title_contains": keyword,
    "[or]content_contains": keyword,
    "status": "published"
}, limit=20)

Authentication Check

def main():
    if not req.user:
        return {"error": "Unauthorized"}, 401

    user_id = req.user["id"]
    return {"user_id": user_id}

Error Handling

def main():
    try:
        result = db.query("posts", limit=20)
        return {"posts": result["data"]}
    except Exception as e:
        print(f"Error: {str(e)}")
        return {"error": "Internal server error"}, 500

Response Format

# Standard response from db.query
{
    "data": [...],      # Array of documents
    "total": 150,       # Total matching documents
    "limit": 20,        # Requested limit
    "offset": 0,        # Offset used
    "has_more": True    # More results available
}

Tips

  • Always use limit to avoid large result sets
  • Use populate only for fields you actually need
  • Use select to return only required fields
  • Handle errors gracefully with try/except
  • Use queue for non-blocking background tasks
  • Check req.user for authenticated endpoints