Database Package Guidelines
Thekarma/database package simplifies PostgreSQL interaction using idiomatic Go. Follow these conventions when defining your database schema.
1. Schema Design Using Go Structs
Each database table is defined as a Go struct. Karma uses struct tags to generate queries and handle data serialization.2. Struct Field Tag Guidelines
✅ Follow these rules
✅ Follow these rules
- Field Names: Use CamelCase (e.g.,
AudioId,ConversationId) - JSON Tags: Use
snake_caseto match DB columns - Complex Types: Use both
jsonanddbtags for slices, maps, and nested structs - Primary Key: Mark primary key field using
karma:"primary" - Table Name: Include a dummy
struct{}field with thekarma_tabletag
🛑 Common mistakes
🛑 Common mistakes
Environment Configuration Guidelines
The Karma suite uses environment variables for all credentials and configuration. No secrets should be hardcoded in your codebase.1. Using the Config Package
Use thegithub.com/MelloB1989/karma/config package to access environment variables. This package provides utility functions to securely load values from .env.
2. Required Environment Variables
DATABASE_URL: default fallback connection stringENVIRONMENT: one ofdev,prod, orstaging<ENVIRONMENT>_DATABASE_URL: environment-specific connection string
3. Connection Resolution Logic
- If
ENVIRONMENTis not set → usesDATABASE_URL - If
ENVIRONMENTis set → uses{ENVIRONMENT}_DATABASE_URL