Class Map - Trebossalol/localdb GitHub Wiki

What is a map ?

A map is a key-value based storage. Each key has its own value, it is basically an object.

Declaration

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
})  

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 your Database instance!)

onErrorBehaviour : string - A string which specifies the behaviour of the map if an error occues CREATE_BACKUP_AND_OVERWRITE -> Creates a backup of the error-version and creates a new empty map OVERWRITE -> Overwrites the error-version to an empty map(Data will be lost!) LOG_ERROR -> Throws an exception undefined -> LOG_ERROR

onRestartBehaviour : string - A string which specifies the behaviour of the map on init OVERWRITE -> Overwrites the collection (Data will be lost!) undefined -> Normal behaviour

Methods

You can see every method here, or in your prefered code editor, because this library has almost fully typescript support!

⚠️ **GitHub.com Fallback** ⚠️