Writes ``table`` to a Microsoft SQL Server table. The connector works in two modes: **snapshot** mode and **stream of changes**. In **snapshot** mode, the table maintains the current snapshot of the data using MSSQL's ``MERGE`` statement for atomic upserts. In **stream of changes**
(
table: Table,
connection_string: str,
table_name: str,
*,
schema_name: str = "dbo",
max_batch_size: int | None = None,
init_mode: Literal["default", "create_if_not_exists", "replace"] = "default",
output_table_type: Literal["stream_of_changes", "snapshot"] = "stream_of_changes",
primary_key: list[ColumnReference] | None = None,
name: str | None = None,
sort_by: Iterable[ColumnReference] | None = None,
)
| 274 | @check_arg_types |
| 275 | @trace_user_frame |
| 276 | def write( |
| 277 | table: Table, |
| 278 | connection_string: str, |
| 279 | table_name: str, |
| 280 | *, |
| 281 | schema_name: str = "dbo", |
| 282 | max_batch_size: int | None = None, |
| 283 | init_mode: Literal["default", "create_if_not_exists", "replace"] = "default", |
| 284 | output_table_type: Literal["stream_of_changes", "snapshot"] = "stream_of_changes", |
| 285 | primary_key: list[ColumnReference] | None = None, |
| 286 | name: str | None = None, |
| 287 | sort_by: Iterable[ColumnReference] | None = None, |
| 288 | ) -> None: |
| 289 | """Writes ``table`` to a Microsoft SQL Server table. |
| 290 | |
| 291 | The connector works in two modes: **snapshot** mode and **stream of changes**. |
| 292 | In **snapshot** mode, the table maintains the current snapshot of the data |
| 293 | using MSSQL's ``MERGE`` statement for atomic upserts. |
| 294 | In **stream of changes** mode, the table contains the log of all data updates |
| 295 | with ``time`` and ``diff`` columns. |
| 296 | |
| 297 | Compatible with all MSSQL versions on Linux (SQL Server 2017, 2019, 2022, |
| 298 | and Azure SQL Edge). Uses pure Rust TDS implementation — no ODBC drivers required. |
| 299 | |
| 300 | Args: |
| 301 | table: Table to be written. |
| 302 | connection_string: ADO.NET-style connection string for the MSSQL database. |
| 303 | Example: ``"Server=tcp:localhost,1433;Database=mydb;User Id=sa;Password=pass;TrustServerCertificate=true"`` |
| 304 | table_name: Name of the target table. |
| 305 | schema_name: Name of the database schema containing the table. Defaults to |
| 306 | ``"dbo"``, which is the default schema in MSSQL. |
| 307 | max_batch_size: Maximum number of entries allowed to be committed within a |
| 308 | single transaction. |
| 309 | init_mode: ``"default"``: The default initialization mode; |
| 310 | ``"create_if_not_exists"``: creates the table if it does not exist; |
| 311 | ``"replace"``: drops and recreates the table. |
| 312 | output_table_type: Defines how the output table manages its data. If set to |
| 313 | ``"stream_of_changes"`` (the default), the system outputs a stream of |
| 314 | modifications with ``time`` and ``diff`` columns. If set to ``"snapshot"``, |
| 315 | the table maintains the current state using atomic MERGE upserts. |
| 316 | primary_key: When using snapshot mode, one or more columns that form the primary |
| 317 | key in the target MSSQL table. |
| 318 | name: A unique name for the connector. If provided, this name will be used in |
| 319 | logs and monitoring dashboards. |
| 320 | sort_by: If specified, the output will be sorted in ascending order based on the |
| 321 | values of the given columns within each minibatch. When multiple columns are provided, |
| 322 | the corresponding value tuples will be compared lexicographically. |
| 323 | |
| 324 | Returns: |
| 325 | None |
| 326 | |
| 327 | Example: |
| 328 | |
| 329 | To test this connector locally, run a MSSQL instance using Docker: |
| 330 | |
| 331 | .. code-block:: bash |
| 332 | |
| 333 | docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=YourStrong!Passw0rd' \\ |
nothing calls this directly
no test coverage detected