Registry / database / resolve-snapshot-mysql

resolve-snapshot-mysql

JSON →
library0.23.2jsnpmunverified

An adapter for storing event sourcing snapshots in MySQL, part of the reSolve framework for CQRS/ES applications. As of v0.23.2, it provides loadSnapshot, saveSnapshot, and dispose operations with configurable bucket size and table name. Typically used alongside resolve-command and resolve-query. The package relies on mysql2 for database connectivity. Alternative adapters exist for PostgreSQL and SQLite within the reSolve ecosystem.

npm install resolve-snapshot-mysql
INSTALL
IMPORT
SIG · RESOLVE-SNAPSHOT-M
R
resolve-snapshot-mysql
databasejavascriptv0.23.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createSnapshotAdapter
import createSnapshotAdapter from 'resolve-snapshot-mysql'
import { createSnapshotAdapter } from 'resolve-snapshot-mysql'
Package exports a default function. Named import will fail.
createSnapshotAdapter
const createSnapshotAdapter = require('resolve-snapshot-mysql')
const { createSnapshotAdapter } = require('resolve-snapshot-mysql')
CommonJS require imports the default export; destructuring fails.
createSnapshotAdapter type
import { Adapter } from 'resolve-snapshot-mysql'
import Adapter from 'resolve-snapshot-mysql'
TypeScript users may need to import the type Adapter separately if using module augmentation.

Creates a snapshot adapter for MySQL, saves and loads a snapshot, then disposes without dropping snapshots.

import createSnapshotAdapter from 'resolve-snapshot-mysql' const snapshotAdapter = createSnapshotAdapter({ bucketSize: 100, tableName: 'snapshots', host: 'localhost', port: 3306, user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'mydb' }) await snapshotAdapter.saveSnapshot('user-123', { state: 'active' }) const snapshot = await snapshotAdapter.loadSnapshot('user-123') console.log(snapshot) // { state: 'active' } await snapshotAdapter.dispose({ dropSnapshots: false })
Debug
Known issues
gotchaThe adapter does not create the table automatically; it must exist before calling saveSnapshot.
fix
Create the snapshots table manually or use a migration tool before creating the adapter.
affects: all
gotchaThe bucketSize parameter must be an integer; passing a non-integer will cause silent data corruption.
fix
Always pass an integer value for bucketSize (e.g., bucketSize: 100).
affects: all
breakingIn v0.20.0, the default export changed from an object with individual functions to a single factory function createSnapshotAdapter. Old code using destructured imports will break.
fix
Use import createSnapshotAdapter from 'resolve-snapshot-mysql' and call it to get the adapter.
affects: <0.20.0
deprecatedThe connection settings object now uses the 'host' key instead of 'hostname' as of mysql2 v2.3.0.
fix
Use 'host' instead of 'hostname' in the connection settings.
affects: >=0.23.0
Errors
Common errors & fixes
Error: Cannot find module 'resolve-snapshot-mysql'
Package not installed.
fix
npm install resolve-snapshot-mysql
TypeError: createSnapshotAdapter is not a function
Using named import instead of default import.
fix
Use import createSnapshotAdapter from 'resolve-snapshot-mysql' (default import).
Error: ER_NO_SUCH_TABLE: Table 'mydb.snapshots' doesn't exist
The snapshots table does not exist in the database.
fix
Create the snapshots table with the required schema before using the adapter.
Upgrade
Version history
0.23.2latest on npm
Audit
Dependencies
mysql2requiredRequired for MySQL database connectivity.
Agent activity
8 hits · last 30 days
node
8
Resources
resolve-snapshot-mysql — npm install resolve-snapshot-mysql · libregistry