From 1e38e9e9ce01112309714ace3528e44562f6d8e8 Mon Sep 17 00:00:00 2001 From: Hein Date: Thu, 18 Dec 2025 14:35:05 +0200 Subject: [PATCH] Newest changes --- CLAUDE.md | 70 ------------------------------------------------------- 1 file changed, 70 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 30c4ee5..4de79a8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -49,37 +49,6 @@ Database └── Relationships (map[string]Relationship) ``` -**Key architectural decisions:** -- Tables use **maps** for Columns, Constraints, Indexes, and Relationships (keyed by name for O(1) lookup) -- Schemas use **slices** for Tables (order matters for generation) -- All model types implement `SQLNamer` interface (returns lowercase SQL-safe names) -- Use `Init*` functions (e.g., `InitTable()`, `InitSchema()`) to create properly initialized models with empty maps/slices - -**Model Views:** -- `flatview.go`: Provides denormalized views with fully qualified names (e.g., `database.schema.table.column`) -- `summaryview.go`: Lightweight summary views with counts and essential metadata -- Use `.ToFlatColumns()`, `.ToSummary()` methods to convert between views - -### Reader/Writer Pattern (pkg/readers/, pkg/writers/) - -All readers and writers implement consistent interfaces with three granularity levels: - -```go -// Reader interface -type Reader interface { - ReadDatabase() (*models.Database, error) - ReadSchema() (*models.Schema, error) - ReadTable() (*models.Table, error) -} - -// Writer interface -type Writer interface { - WriteDatabase(db *models.Database) error - WriteSchema(schema *models.Schema) error - WriteTable(table *models.Table) error -} -``` - **Important patterns:** - Each format (dbml, dctx, drawdb, etc.) has its own `pkg/readers//` and `pkg/writers//` subdirectories - Use `ReaderOptions` and `WriterOptions` structs for configuration (file paths, connection strings, metadata) @@ -98,45 +67,6 @@ Contains PostgreSQL-specific helpers: ## Development Patterns -### Adding a New Reader - -1. Create `pkg/readers//` directory -2. Implement the `Reader` interface with all three methods -3. Create a `NewReader(options *readers.ReaderOptions)` constructor -4. Parse format-specific data into the canonical `models.Database` structure -5. Use `models.Init*()` functions to create properly initialized structs - -### Adding a New Writer - -1. Create `pkg/writers//` directory -2. Implement the `Writer` interface with all three methods -3. Create a `NewWriter(options *writers.WriterOptions)` constructor -4. Transform canonical models into format-specific output -5. Handle file writing or other I/O in the writer implementation - -### Working with Models - -```go -// Creating models - ALWAYS use Init functions -db := models.InitDatabase("mydb") -schema := models.InitSchema("public") -table := models.InitTable("users", "public") -column := models.InitColumn("id", "users", "public") - -// Adding to parent structures -schema.Tables = append(schema.Tables, table) -table.Columns["id"] = column // Use map key access for columns -db.Schemas = append(db.Schemas, schema) - -// Accessing primary keys and foreign keys -pk := table.GetPrimaryKey() // Returns *Column or nil -fks := table.GetForeignKeys() // Returns []*Constraint -``` - -## CLI Implementation Status - -The CLI in `cmd/relspec/main.go` is currently a placeholder showing usage examples. It will be implemented using the Cobra framework (already in dependencies). - ## Testing - Test files should be in the same package as the code they test