0.0.1-alpha.1 • Published 3 years ago
@lyrasearch/plugin-disk-persistence v0.0.1-alpha.1
Disk Persistence Plugin
Experimental stage, use at your own risk.
Installation
You can install the disk persistence plugin using npm, yarn, pnpm:
npm i @lyrasearch/plugin-disk-persistenceyarn add @lyrasearch/plugin-disk-persistencepnpm add @lyrasearch/plugin-disk-persistenceUsage
You can save and restore a database by using the methods exposed by the plugin-disk-persistence package.
Given the following database:
import { create, insert } from '@nearform/lyra'
const myPrimaryDB = create({
schema: {
quote: 'string',
author: 'string'
}
})
insert(myPrimaryDB, {
quote: 'Impossible is for the unwilling',
author: 'John Keats'
})
insert(myPrimaryDB, {
quote: 'I have not failed. I’ve just found 10,000 ways that won’t work.',
author: 'Thomas A. Edison'
})you can save the database to disk:
import { persist } from '@lyrasearch/plugin-disk-persistence'
persist(myPrimaryDB, 'binary')Available formats are:
binary: saves the database to a compressed, binary file usingdpackalgorithm (recommended)json: saves the database to a JSON file
The persist function accepts as a third argument the file name.
When no argument, a default name will be used: lyra_bump_623432432.
Note: you can use the environment variable LYRA_DB_NAME to override the default name.
At this point, you can also restore the database from disk:
import { search } from '@nearform/lyra'
import { restore } from '@lyrasearch/plugin-disk-persistence'
const mySecondaryDB = restore('binary')
search(mySecondaryDB, {
term: 'work'
})License
0.0.1-alpha.1
3 years ago
0.0.1-alpha.0
3 years ago