TinyBase logoTinyBase

createCustomMsSqlPersister

The createCustomMsSqlPersister function creates a Persister object that you can configure to persist the Store to a SQL Server database.

createCustomMsSqlPersister<Persist>(
  store: PersistedStore<Persist>,
  configOrStoreTableName: string | DatabasePersisterConfig | undefined,
  executeCommand: DatabaseExecuteCommand,
  onSqlCommand: ((sql: string, params?: any[]) => void) | undefined,
  onIgnoredError: ((error: any) => void) | undefined,
  destroy: () => void,
  persist: Persist,
  thing: any,
  getThing?: string,
): Persister<Persist>
TypeDescription
storePersistedStore<Persist>

The Store to persist.

configOrStoreTableNamestring | DatabasePersisterConfig | undefined

A DpcJson object, or a string that will be used as the name of the Store's table in the database.

executeCommandDatabaseExecuteCommand

A function that will execute a command against the database.

onSqlCommand((sql: string, params?: any[]) => void) | undefined

A function that will be called for each SQL command executed against the database.

onIgnoredError((error: any) => void) | undefined

An optional handler for the errors that the Persister would otherwise ignore when trying to save or load data. This is suitable for debugging persistence issues in a development environment.

destroy() => void

A function that will be called to perform any extra clean up on the Persister.

persistPersist

An integer from the Persists enum to indicate which types of Store are supported by this Persister: 1 indicates only a regular Store is supported, 2 indicates only a MergeableStore is supported, and 3 indicates that both Store and MergeableStore are supported.

thingany

A reference to the database or connection that can be returned with a method, by default called getDb.

getThing?string

An optional string that will be used to get the reference to the database or connection from the Persister, defaulting to getDb.

returnsPersister<Persist>

A reference to the new Persister object.

This is only used when developing custom database-oriented Persisters, and most TinyBase users will not need to be particularly aware of it.

Unlike the PostgreSQL equivalent, this takes no change listener functions. SQL Server has no notification mechanism that is available on every one of its hosted flavors, so automatic loading polls a rowversion column that the Persister maintains instead.

The createMsSqlPersister function uses this function under the covers, and so you may wish to look at that implementation for ideas on how to build your own Persister type, and as a functional example.

Since

10.0.0