litellm/litellm-rust/crates/db/AGENTS.md
yujonglee 554b011787
feat(rust): add typed database query foundation (#48214)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-26 17:05:04 -07:00

1.5 KiB

Database crate

Keep each static query in queries/ and call it through a typed SQLx query function. Rust does not create or migrate the database

  • Own reusable row projections in src/ and export those consumed by other crates or integration tests
  • Apply #[macro_rules_attribute::apply(crate::db_row)] to row types for shared derives, without adding serialization or schema derives automatically
  • Apply #[macro_rules_attribute::apply(crate::db_input)] to write inputs, adding Default only where supported
  • Keep function tests inline in their owning query module and reuse the strict database fixture in test_support
  • Transaction-local setup in begin is the approved exception to static query files
  • Keep write inputs separate from stored rows and keep test-only assertions out of public types
  • FromRow supports runtime reads, but production static reads still use query_file_as! for compile-time checking

Database integration tests are ignored by default, but still compile in workspace checks. Run them explicitly against a local database already migrated by Prisma. Missing or invalid database configuration must fail the selected tests:

DATABASE_URL=postgresql://... cargo test -p litellm-db --locked -- --include-ignored

After changing a query, refresh the checked query metadata from this directory:

SQLX_OFFLINE=false cargo sqlx prepare

Tests use transactions and leave them uncommitted so fixture rows roll back when each test finishes