Skip to content

fix(mssql): make Unicode strings configurable - #18264

Draft
coyaSONG wants to merge 5 commits into
sequelize:mainfrom
coyaSONG:codex/mssql-configurable-unicode-strings
Draft

coyaSONG wants to merge 5 commits into
sequelize:mainfrom
coyaSONG:codex/mssql-configurable-unicode-strings

Conversation

@coyaSONG

@coyaSONG coyaSONG commented Jul 15, 2026 •

Copy link
Copy Markdown

Pull Request Checklist

  • Have you added new tests to prevent regressions?
  • If a documentation update is necessary, have you opened a PR to the documentation repository? (Not necessary: the new dialect option is documented in its public TypeScript definition.)
  • Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Does the name of your PR follow our conventions?

Description of Changes

Relates to #18260.

This adds a useUnicodeStrings MSSQL dialect option. Its default remains true, preserving the existing N'...' literal and TYPES.NVarChar bind behavior for all current deployments.

Applications whose schemas intentionally use code-page-compatible VARCHAR columns can explicitly set useUnicodeStrings: false. In that mode, string literals omit the N prefix and string bind parameters use Tedious' TYPES.VarChar; non-string bind types are unchanged.

The tests cover both the backward-compatible default and the explicit opt-out for literals and bound strings.

Validation performed:

  • NX_DAEMON=false yarn build
  • yarn workspace @sequelize/mssql test-unit (10 passing)
  • yarn exec tsc --noEmit --project packages/mssql/tsconfig.json
  • ESLint and Prettier checks for all changed files
  • git diff --check

List of Breaking Changes

None. Unicode strings remain enabled by default; behavior changes only when the new option is explicitly set to false.

Summary by CodeRabbit

  • New Features
    • Added an option to configure how Microsoft SQL Server handles strings. By default, strings use Unicode; disabling the option uses non-Unicode strings for SQL literals and query parameters.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 579204a4-f96f-4af7-9c5a-883c7a8b22f7

📥 Commits

Reviewing files that changed from the base of the PR and between d191d5b and 4db765b.


📒 Files selected for processing (3)
  • packages/mssql/src/dialect.test.ts
  • packages/mssql/src/dialect.ts
  • packages/mssql/src/query.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

The MSSQL dialect adds useUnicodeStrings. The option controls whether escaped string literals use the N prefix and whether string parameters use TYPES.NVarChar or TYPES.VarChar.

Changes

MSSQL Unicode strings

Layer / File(s) Summary
Unicode option and literal escaping
packages/mssql/src/dialect.ts, packages/mssql/src/dialect.test.ts
The dialect recognizes useUnicodeStrings. Escaped string literals omit the N prefix only when the option is false. Tests cover both settings.
String parameter type selection
packages/mssql/src/query.js, packages/mssql/src/dialect.test.ts
String parameters use TYPES.VarChar when the option is false and TYPES.NVarChar otherwise. Tests cover both mappings and verify the value and type options.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature


Merge Risk: ⚪ Minimal · up to 4db76

No actionable issue is established from the supplied evidence. Real SQL Server validation remains pending before the draft PR is ready to merge.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: making MSSQL Unicode string handling configurable through the new useUnicodeStrings option.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Biome (2.5.14)
packages/mssql/src/query.js

File contains syntax errors that prevent linting: Line 3: Illegal use of an import declaration outside of a module; Line 13: Illegal use of an import declaration outside of a module; Line 14: Illegal use of an import declaration outside of a module; Line 15: Illegal use of an import declaration outside of a module; Line 16: Illegal use of an import declaration outside of a module; Line 17: Illegal use of an import declaration outside of a module; Line 37: Illegal use of an export declaration outside of a module



Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@san7iya

san7iya commented Aug 5, 2026

Copy link
Copy Markdown

Hi @coyaSONG! I came across this via issue #18260; nice approach with the opt-in flag. I don't have a fix to contribute here since it looks like you and the maintainers have this well in hand, but I'd be happy to help test once it's out of draft :) I can spin up a local SQL Server instance and try useUnicodeStrings: false against a schema with plain VARCHAR columns to confirm the index seek behaves as expected. Let me know if that'd be useful.

@coyaSONG

Copy link
Copy Markdown
Author

@san7iya That would be very useful, thank you. The most valuable check would be against the current PR head with an indexed VARCHAR column: compare the default behavior with useUnicodeStrings: false, confirm the generated literal/bind type, and capture whether the opt-out restores an index seek. A quick default-mode Unicode value check would also guard the backwards-compatible path. The MSSQL CI matrix and focused unit tests are green; I am keeping the PR draft until this real-server validation or maintainer direction is available.

@coyaSONG

Copy link
Copy Markdown
Author

Branch synchronization is complete at 4db765b. The current GitHub CI reports 73 successful checks, with one skipped and no failed or pending checks, including the MSSQL matrix. The default Unicode and explicit opt-out behavior remain covered. The real-server VARCHAR index-seek comparison discussed above is still not claimed as completed; maintainer review or that additional validation remains welcome. No human review is claimed.

@sequelize-bot sequelize-bot Bot added the conflicted This PR has merge conflicts and will not be present in the list of PRs to review label Oct 20, 2026
@sequelize-bot
sequelize-bot Bot marked this pull request as draft October 26, 2026 00:24
@sequelize-bot

sequelize-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Warning

This pull request has been automatically converted to draft because it is not ready to be merged.

Reason(s):

  • 🔀 Merge conflicts — This PR has merge conflicts that must be resolved before it can be merged.

Once you have addressed the issue(s) above, you may
mark this pull request as ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicted This PR has merge conflicts and will not be present in the list of PRs to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants