Add an mssql Persister for SQL Server and Azure SQL - #295
Open
nltgpeterskoglund wants to merge 4 commits into
Open
Add an mssql Persister for SQL Server and Azure SQL#295nltgpeterskoglund wants to merge 4 commits into
nltgpeterskoglund wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
persister-mssql, binding to themssqlpackage so that SQL Server,Azure SQL Database and Azure SQL Managed Instance are all covered by one
Persister. It follows the
persister-pgshape: you pass in aConnectionPoolyou have configured yourself, which keeps TinyBase out of the authentication
story entirely — including the passwordless Entra ID options that Microsoft
recommends for applications hosted in Azure.
Scope
JSON serialization only, for both
StoreandMergeableStore. Tabular mappingis deliberately left out; it would need per-table change detection, which is
the part of this that SQL Server makes expensive.
json.test.tsandmergeable-json.test.tstherefore run a newALL_JSON_VARIANTSroll-up, whiletabular.test.tsstays onALL_VARIANTS.Change detection
There is no LISTEN/NOTIFY equivalent available across every flavor of SQL
Server — Service Broker is not on Azure SQL Database, and Change Tracking needs
ALTER DATABASE, which is more privilege than a library should assume. Soauto-loading adds a
rowversioncolumn and polls it. SQL Server maintains thatcolumn itself on every insert and update, so writes from other clients are
still picked up.
The one subtlety: the dialect's
querySchemaexcludesDATA_TYPE='timestamp',which hides the column from the shared schema handling. Without that,
saveTablewould drop it as an unaccounted-for column on every save. Excludingit is also just correct, since a rowversion column can never be written to.
Please look closely at these
Three small parameters are threaded through the shared database code
(
commands.ts,common.ts,json.ts,tabular.ts), because T-SQL differsfrom both existing dialects:
trueCondition—WHERE(true)is not valid T-SQL; it needs1=1.rowIdColumnType—nvarchar(max)cannot be a primary key, so the row Idcolumn needs a narrower type than the others.
DROP COLUMN.All three default to the current spelling, so SQLite and PostgreSQL emit
byte-identical SQL. The test harness also gains a dialect discriminator in
place of the
isPostgresboolean. Happy to reshape any of this if you wouldprefer it done differently.
Separately,
getLabelBlocksin the gulpfile memoized itsMapbefore fillingit, so concurrent
copyDefinitioncalls could see it empty. Adding a modulewas enough to make that surface as
Missing docs label. It now memoizes thepromise instead.
Testing
Run against SQL Server 2022 and PostgreSQL 17, both in Docker: zero failures
for
mssql,pg,postgres,pgliteand every SQLite variant across thepersister suites, and both
docs.jsexamples execute. The remaining failuresin my environment are pre-existing Windows ones, unrelated to this change.
The matrix variant reads
TINYBASE_MSSQL_SERVER,TINYBASE_MSSQL_PORT,TINYBASE_MSSQL_USERandTINYBASE_MSSQL_PASSWORDrather than hard-coding aconnection string, since SQL Server cannot be trust-authenticated the way the
local PostgreSQL variants are.
Two things left for you:
coverage.jsonis untouched. It is only rewritten by a fully greengulp testUnit, which I could not reach on Windows.@since 9.8.0is a guess at the next version.Opened alongside #294, where I asked about the scope first — happy to close
this and rework it there if you would rather it landed differently.