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>
This commit is contained in:
19
src/server/repository/mod.rs
Normal file
19
src/server/repository/mod.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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 0–65535 fit in u16).
|
||||
|
||||
pub mod applications;
|
||||
pub mod hosts;
|
||||
pub mod networks;
|
||||
pub mod ports;
|
||||
Reference in New Issue
Block a user