TinyBase logoTinyBase β

persister-mssql

The persister-mssql module of the TinyBase project lets you save and load Store data to and from a SQL Server database, via the mssql module (in an appropriate environment).

Since the mssql module speaks the SQL Server protocol, this module works with SQL Server itself, Azure SQL Database, and Azure SQL Managed Instance alike.

The Persister takes a mssql connection pool that you have already configured, so it stays out of the way of how you choose to authenticate. That includes the passwordless options that Microsoft recommends for applications hosted in Azure:

import {ConnectionPool} from 'mssql';
import {createStore} from 'tinybase';
import {createMsSqlPersister} from 'tinybase/persisters/persister-mssql';

const pool = new ConnectionPool({
  server: 'myserver.database.windows.net',
  database: 'my_database',
  authentication: {type: 'azure-active-directory-default'},
  options: {encrypt: true},
});
await pool.connect();

const store = createStore();
const persister = await createMsSqlPersister(store, pool, 'my_tinybase');
await persister.startAutoPersisting();

This module currently supports the JSON serialization mode only.

The examples below connect to a local tinybase database. A real connection string also carries the login, or the authentication type that stands in for one on Azure.

See also

Database Persistence guide

Since

10.0.0

Interfaces

Functions