···1+package repo
2+3+import (
4+ "context"
5+6+ "stormlightlabs.org/noteleaf/internal/models"
7+)
8+9+// Repository defines a general, behavior-focused interface for data access
10+type Repository interface {
11+ // Create stores a new model and returns its assigned ID
12+ Create(ctx context.Context, model models.Model) (int64, error)
13+14+ // Get retrieves a model by ID
15+ Get(ctx context.Context, table string, id int64, dest models.Model) error
16+17+ // Update modifies an existing model
18+ Update(ctx context.Context, model models.Model) error
19+20+ // Delete removes a model by ID
21+ Delete(ctx context.Context, table string, id int64) error
22+23+ // List retrieves models with optional filtering and sorting
24+ List(ctx context.Context, table string, opts ListOptions, dest any) error
25+26+ // Find retrieves models matching specific conditions
27+ Find(ctx context.Context, table string, conditions map[string]any, dest any) error
28+29+ // Count returns the number of models matching conditions
30+ Count(ctx context.Context, table string, conditions map[string]any) (int64, error)
31+32+ // Execute runs a custom query with parameters
33+ Execute(ctx context.Context, query string, args ...any) error
34+35+ // Query runs a custom query and returns results
36+ Query(ctx context.Context, query string, dest any, args ...any) error
37+}
38+39+// ListOptions defines generic options for listing items
40+type ListOptions struct {
41+ // field: value pairs for WHERE conditions
42+ Where map[string]any
43+ Limit int
44+ Offset int
45+ // field name to sort by
46+ SortBy string
47+ // "asc" or "desc"
48+ SortOrder string
49+ // general search term
50+ Search string
51+ // fields to search in
52+ SearchFields []string
53+}