🗄️ Rust-Native Database Engine
RustAPI embeds high-concurrency sqlx connection pooling directly inside the engine for PostgreSQL and SQLite.
import rustapi
app = rustapi.Engine()
# SQLite Connection Pool
db = app.connect_db("sqlite://data.db")
# PostgreSQL Connection Pool
# db = app.connect_db("postgres://user:pass@localhost/dbname")
⚡ Zero-Copy JSON Streaming (db.query_json())
Why query_json() is up to 30x Faster
In standard FastAPI, SQL rows are mapped into Python tuples, instantiated into Python dicts, validated by Pydantic models, and converted to strings via json.dumps. This creates thousands of CPython heap allocations and holds the GIL.
In RustAPI, db.query_json() reads raw bytes from sqlx, formats UTF-8 JSON buffers natively in Rust memory, and streams bytes directly into Hyper TCP sockets without ever instantiating Python objects or holding the GIL.
@app.get("/products")
def get_products():
return db.query_json("SELECT id, name, price, stock FROM products WHERE active = 1")
✏️ Executing SQL Mutations (db.execute())
Execute INSERT, UPDATE, and DELETE queries with automatic thread handle reuse:
@app.post("/products")
def create_product(name: str, price: float):
rows_affected = db.execute(f"INSERT INTO products (name, price) VALUES ('{name}', {price})")
return {"status": "created", "affected": rows_affected}