mssql

package
v1.0.38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

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

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:

go test ./pkg/readers/mssql/...

For integration testing with a live MSSQL database:

docker-compose up -d mssql
go test -tags=integration ./pkg/readers/mssql/...
docker-compose down

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements the readers.Reader interface for MSSQL databases

func NewReader

func NewReader(options *readers.ReaderOptions) *Reader

NewReader creates a new MSSQL reader

func (*Reader) ReadDatabase

func (r *Reader) ReadDatabase() (*models.Database, error)

ReadDatabase reads the entire database schema from MSSQL

func (*Reader) ReadSchema

func (r *Reader) ReadSchema() (*models.Schema, error)

ReadSchema reads a single schema (returns the first schema from the database)

func (*Reader) ReadTable

func (r *Reader) ReadTable() (*models.Table, error)

ReadTable reads a single table (returns the first table from the first schema)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL