Enhanced Maps are a data structure that can be used to store data in memory that can also be saved in a database behind the scenes. These operations are fast, safe, and painless.
The data is synchronized to the database automatically, seamlessly, and asynchronously for maximum effectiveness.
The storage system used is an sqlite
database which is fast, performant, can be easily backed up,
and supports multiple simultaneous connections.
npm i github:lunabot/enhanced-map#main
import { EnhancedMap } from 'enhanced-map';
// Normal enhanced map with default options
const myEnhancedMap = new EnhancedMap({name: "points"});
// non-cached, auto-fetch enhanced map:
const otherEnhancedMap = new EnhancedMap({
name: "settings",
autoFetch: true,
fetchAll: false
});
A: Enhanced maps extend the Javascript Map() data structure with additional utility methods. This started as a pretty straight clone of the Discord.js Collections but since its creation has grown far beyond those methods alone.
A: By using a database layer with better-sqlite3
, any data added to the enhanced map
is stored not only in temporary memory but also backed up in a local database. This means that
when you restart your project, your data is not lost and is loaded on startup.
A: The size of the memory used is directly proportional to the size of all the keys loaded in memory. The more data you have, the more complex it is, the more memory it can use. You can use the fetchAll options to reduce memory usage.
A: Enhanced maps are useful for storing very simple key/value data for easy retrieval; And also for more complex objects with many properties. This is used in Discord.js bots to save currencies, content blocks, server settings, user information for bans, blocklists, timers, warning systems, etc.