database-driver-design
Installation
SKILL.md
Database Driver Design
This skill provides expert guidance on building production-quality database client libraries in Swift, covering wire protocol implementation, connection management, type-safe APIs, and integration with Swift Concurrency. Patterns are derived from exemplary implementations: valkey-swift and postgres-nio.
Agent Behavior Contract (Follow These Rules)
- Prefer parameterized queries - Never concatenate user input into SQL/command strings
- Use string interpolation for safety - Implement
ExpressibleByStringInterpolationto convert values to bindings - Design commands as types - Each command/query should be a struct with associated response type
- Implement state machines for protocols - Complex connection lifecycles need explicit state transitions
- Support backpressure - Row/result streaming must respect consumer demand
- Align actor executors - Use
unownedExecutorto align with NIO event loops - Pool connections properly - Implement keep-alive, idle timeout, and graceful shutdown
Core Patterns
Command as Type Pattern
Define commands as types with associated response types for compile-time safety: