# MSSQL Reader Reads database schema from Microsoft SQL Server databases using a live connection. ## Features - **Live Connection**: Connects to MSSQL databases using the Microsoft ODBC driver - **Multi-Schema Support**: Reads multiple schemas with full support for user-defined schemas - **Comprehensive Metadata**: Reads tables, columns, constraints, indexes, and extended properties - **Type Mapping**: Converts MSSQL types to canonical types for cross-database compatibility - **Extended Properties**: Extracts table and column descriptions from MS_Description - **Identity Columns**: Maps IDENTITY columns to AutoIncrement - **Relationships**: Derives relationships from foreign key constraints ## Connection String Format ``` sqlserver://[user[:password]@][host][:port][?query] ``` Examples: ``` sqlserver://sa:password@localhost/dbname sqlserver://user:pass@192.168.1.100:1433/production sqlserver://localhost/testdb?encrypt=disable ``` ## Supported Constraints - Primary Keys - Foreign Keys (with ON DELETE and ON UPDATE actions) - Unique Constraints - Check Constraints ## Type Mappings | MSSQL Type | Canonical Type | |------------|----------------| | INT | int | | BIGINT | int64 | | SMALLINT | int16 | | TINYINT | int8 | | BIT | bool | | REAL | float32 | | FLOAT | float64 | | NUMERIC, DECIMAL | decimal | | NVARCHAR, VARCHAR | string | | DATETIME2 | timestamp | | DATETIMEOFFSET | timestamptz | | UNIQUEIDENTIFIER | uuid | | VARBINARY | bytea | | DATE | date | | TIME | time | ## Usage ```go import "git.warky.dev/wdevs/relspecgo/pkg/readers/mssql" import "git.warky.dev/wdevs/relspecgo/pkg/readers" reader := mssql.NewReader(&readers.ReaderOptions{ ConnectionString: "sqlserver://sa:password@localhost/mydb", }) db, err := reader.ReadDatabase() if err != nil { panic(err) } // Process schema... for _, schema := range db.Schemas { fmt.Printf("Schema: %s\n", schema.Name) for _, table := range schema.Tables { fmt.Printf(" Table: %s\n", table.Name) } } ``` ## Testing Run tests with: ```bash go test ./pkg/readers/mssql/... ``` For integration testing with a live MSSQL database: ```bash docker-compose up -d mssql go test -tags=integration ./pkg/readers/mssql/... docker-compose down ```