Class Map - Trebossalol/localdb GitHub Wiki
A map is a key-value based storage. Each key has its own value, it is basically an object.
class Map<Template = any>
Create a map using an interface to get autocomplete
interface Settings {
some_bool: boolean
some_string: string
}
const settings = new Map<Settings>('settings', {
template: {
some_bool: true,
some_string: 'hello!'
}
// Options
})
template
:<Settings>
- Optional template data, this will be set on init
folderPath
:string
- A path to a folder, where all collection details should be stored (note: This will be automatically specified by your Database instance!)
normalize
:(document) => string
- A callback which will normalize the output json string (default:(doc) => JSON.stringify(doc, null, 3)
)
fileNameGenerator
:(collection) => string
- A callback which will generate the filename of the collection (note: This will be automatically specified by yourDatabase
instance!)
onErrorBehaviour
:string
- A string which specifies the behaviour of the map if an error occuesCREATE_BACKUP_AND_OVERWRITE
-> Creates a backup of the error-version and creates a new empty mapOVERWRITE
-> Overwrites the error-version to an empty map(Data will be lost!)LOG_ERROR
-> Throws an exceptionundefined
->LOG_ERROR
onRestartBehaviour
:string
- A string which specifies the behaviour of the map on initOVERWRITE
-> Overwrites the collection (Data will be lost!)undefined
-> Normal behaviour
You can see every method here, or in your prefered code editor, because this library has almost fully typescript support!