Files
rust-ipam/src/server/repository/mod.rs
mathieu a352a8edfd feat(repository): add CRUD layer for all domain entities
- Add server/repository/ module with networks, hosts, ports, applications
- Use sqlx::query() + manual row mapping (no compile-time DB required)
- Handle unique-constraint conflicts with is_unique_violation() for
  cross-database compatibility (SQLite + PostgreSQL via AnyPool)
- add_port_to_host auto-registers the port in the catalog (prevents FK errors)
- application_ports has no FK to ports (intentional: loose association)
- Add DbError::NotFound variant for missing-record cases

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 21:52:32 +02:00

20 lines
812 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// server/repository — Database access layer (CRUD)
//
// Each sub-module owns the queries for one domain entity.
// All functions accept `&AnyPool` and return `Result<_, DbError>`,
// so the caller never has to think about raw SQL or connection management.
//
// Design choices:
// - Free functions (not struct methods) keep the API simple.
// - `sqlx::query()` is used instead of `sqlx::query!()` because the
// compile-time macro requires a live database at build time.
// - All integer columns are read as `i64` (the AnyPool normalizes
// INTEGER/BIGINT to 64-bit integers internally).
// - Port numbers are stored as i64 in the DB and cast to u16 in Rust
// (safe because valid port numbers 065535 fit in u16).
pub mod applications;
pub mod hosts;
pub mod networks;
pub mod ports;