Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@matanyall
Copy link

Summary

This PR adds Microsoft SQL Server (MSSQL) dialect support to the ent entity framework.

Core SQL Server dialect implementation

File Changes
dialect/dialect.go Added SQLServer = "sqlserver" constant
dialect/sql/builder.go [brackets] identifier quoting, @pN parameter placeholders, OFFSET/FETCH pagination syntax
dialect/sql/builder_test.go Comprehensive SQL Server dialect tests
dialect/sql/driver.go Added SQLServer to dialect detection
dialect/sql/schema/sqlserver.go NEW - Schema adapter with type mappings (BIT, NVARCHAR, DATETIME2, UNIQUEIDENTIFIER, etc.)
dialect/sql/schema/atlas.go Added SQLServer to entDialect switch
dialect/sql/schema/writer.go SQL Server placeholder handling for WriteDriver
dialect/sql/sqlgraph/graph.go SQLServer batch insert with SCOPE_IDENTITY() support
dialect/sql/sqljson/*.go JSON support using JSON_VALUE, JSON_QUERY, OPENJSON functions + tests

Code generation

File Changes
entc/gen/storage.go Added dialect.SQLServer to SQL dialects list
entc/integration/*/ent/client.go Regenerated to include SQLServer in Open() switch

CI/Testing

File Changes
.github/workflows/ci.yml SQL Server 2019/2022/2025 containers for integration/migration jobs
entc/integration/docker-compose.yaml Same SQL Server containers for local development
entc/integration/integration_test.go Added TestSQLServer function
entc/integration/go.mod Added github.com/microsoft/go-mssqldb driver dependency

SQL Server Features Implemented

  • Identifier quoting with [brackets]
  • Parameter placeholders using @p1, @p2, ... syntax
  • Pagination using OFFSET x ROWS FETCH NEXT y ROWS ONLY (auto-adds ORDER BY (SELECT NULL) when missing)
  • IDENTITY(1,1) for auto-increment columns
  • Type mappings: BIT for bool, NVARCHAR for strings, DATETIME2 for time, UNIQUEIDENTIFIER for UUID
  • JSON support using JSON_VALUE, JSON_QUERY, OPENJSON functions
  • SCOPE_IDENTITY() for retrieving last inserted IDs

Known Limitation

The open-source Atlas Go library (ariga.io/atlas) does not include a SQL Server driver. SQL Server support in Atlas is a Pro/Cloud-only feature. This means:

  • Schema migrations via migrate.Create() will fail with an error message directing users to Atlas CLI or manual migrations
  • All dialect/sql unit tests pass
  • Integration tests that require Atlas migrations are blocked

Future work could implement a WriteDriver-based migration approach to bypass Atlas for SQL Server.

@matanyall matanyall marked this pull request as draft December 10, 2025 01:18
@matanyall
Copy link
Author

referenced here: #2781

@matanyall matanyall marked this pull request as ready for review December 10, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant