0.1.0 • Published 3 years ago

discord-nedb v0.1.0

Weekly downloads
2
License
MIT
Repository
-
Last release
3 years ago

Discord NeDB

NeDB-based database hosted on Discord.

Installation

From npm :

  • yarn add discord.db

or

  • npm install discord.db

Built with

Usage

Initialization

const Datastore = require('discord.db');

const database = new Datastore(
    'token',
    'guildId',
    'channelId',
    'userId',
    'messageId'
);

const messageId = await database.loadDatabase();
  • The token parameter is a required bot token
  • Either provide guildId + channelId or userId
  • When messageId is undefined, a new message will be created
  • Always call loadDatabase, which will return messageId, especially useful at first initialization

Data manimulation

Methods provided by nedb-promises (check Datastore docs) :

Read

  • find
  • findOne
  • count

Write

  • update
  • remove
  • ensureIndex
  • removeIndex

Database compaction

await database.persistence.compactDatafile();

Database compaction is automatically called when the message exceeds Discord's maximum limit.

If compaction doesn't free enough space for additional data, an error will be thrown.

Database deletion

await database.deleteData(
    isDeletingLocally,
    isDeletingRemotely
)
  • When isDeletingLocally is true (default), the local database file is deleted.
  • When isDeletingRemotely is true (not default), the Discord message is deleted.

Changelog

  • 0.1.0 (2020-12-17) • Initial release

License

This project is released under the MIT license.