discord-nedb
v0.1.0
Published
NeDB-based database hosted on Discord
Downloads
4
Maintainers
Readme
Discord NeDB
NeDB-based database hosted on Discord.
Installation
From npm :
yarn add discord.db
or
npm install discord.db
Built with
discord.js
: Discord API wrappernedb-promises
: NeDB wrapper with Promises (based onnedb
: JS database)
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
oruserId
- When
messageId
is undefined, a new message will be created - Always call
loadDatabase
, which will returnmessageId
, 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
istrue
(default), the local database file is deleted. - When
isDeletingRemotely
istrue
(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.