Add parseable `@<namespace>[(<target>)]: <args>` directives embedded in DBML.
They are stored losslessly on each object's Metadata, round-trip unchanged
through the DBML writer, and are translated to SQL only by the writer for the
matching dialect.
- models: Directive type + catalog; Metadata map added to Column and Index
- dbml reader: parse and attach directives at database/table/column/index
level; line-numbered errors; repeatable by default with singleton duplicate
detection. Fixes a preexisting bug where an `indexes {}` closing brace ended
the table early, dropping trailing Note: and directive lines.
- dbml writer: re-emit directives at their location; idempotent output
- pgsql writer: PARTITION BY / INHERITS / WITH / TABLESPACE (table),
STORAGE / COMPRESSION / identity (column), WITH / TABLESPACE (index)
- sqlite writer: WITHOUT ROWID / STRICT (table), COLLATE (column)
- --strict-directives flag on ReaderOptions and WriterOptions
- docs/DBML_DIRECTIVES.md + reader/writer READMEs
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ss2MY5J11cRGwEz86ZXk7d
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package readers
|
|
|
|
import (
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
)
|
|
|
|
// Reader defines the interface for reading database specifications
|
|
// from various input formats at different granularity levels
|
|
type Reader interface {
|
|
// ReadDatabase reads and parses the input, returning a Database model
|
|
ReadDatabase() (*models.Database, error)
|
|
|
|
// ReadSchema reads and parses the input, returning a Schema model
|
|
ReadSchema() (*models.Schema, error)
|
|
|
|
// ReadTable reads and parses the input, returning a Table model
|
|
ReadTable() (*models.Table, error)
|
|
}
|
|
|
|
// ReaderOptions contains common options for readers
|
|
type ReaderOptions struct {
|
|
// FilePath is the path to the input file (if applicable)
|
|
FilePath string
|
|
|
|
// ConnectionString is the database connection string (for DB readers)
|
|
ConnectionString string
|
|
|
|
// Prisma7 enables Prisma 7-specific handling for Prisma schemas.
|
|
Prisma7 bool
|
|
|
|
// StrictDirectives makes DBML dialect directives (@postgres:, @sqlite:, …)
|
|
// fail on an unknown namespace or key instead of preserving them silently.
|
|
StrictDirectives bool
|
|
|
|
// Additional options can be added here as needed
|
|
Metadata map[string]interface{}
|
|
}
|