discordjs-nextgen-db
v1.0.2
Published
Flexible, model-based database abstraction layer for discordjs-nextgen
Maintainers
Readme
discordjs-nextgen-db
Turkish Documentation (Türkçe Dökümantasyon)
A flexible, model-based database abstraction layer for discordjs-nextgen. Designed to be database-agnostic while providing a Mongoose-like developer experience.
🚀 Features
- Adapter-Based: Support for Memory, SQLite, and more.
- Model-Driven: Define models once, use them everywhere.
- Auto-Loading: Automatically load model definitions from a directory (and subdirectories).
- Framework Integration: Seamlessly integrates with
discordjs-nextgenviaapp.dbandctx.db. - Type Safe: Full TypeScript support with module augmentation.
📦 Installation
npm install discordjs-nextgen-dbFor SQLite support:
npm install better-sqlite3🛠️ Setup
1. Register the Plugin
You can choose from several adapters. Use the folder option to automatically load models from a directory.
SQLite (Recommended for Small/Medium Bots)
npm install better-sqlite3import { DatabasePlugin, SQLiteAdapter } from 'discordjs-nextgen-db';
app.use(new DatabasePlugin({
folder: './models', // Auto-load models from this folder
adapter: new SQLiteAdapter({ path: './database.sqlite' })
}));MySQL (Recommended for Large/Scalable Bots)
npm install mysql2import { DatabasePlugin, MySQLAdapter } from 'discordjs-nextgen-db';
app.use(new DatabasePlugin({
folder: './models',
adapter: new MySQLAdapter({
host: 'localhost',
user: 'root',
password: 'password',
database: 'nextgen'
})
}));MongoDB / Mongoose (Recommended for NoSQL lovers)
npm install mongooseimport { DatabasePlugin, MongooseAdapter } from 'discordjs-nextgen-db';
app.use(new DatabasePlugin({
folder: './models',
adapter: new MongooseAdapter({
uri: 'mongodb://localhost:27017/nextgen'
})
}));2. Define Your Models
Create a file in your models/ directory (e.g., models/user.ts):
export default (db) => {
db.define('user');
};💡 Usage
Access your models via ctx.db.<modelName> in commands or events.
CRUD Operations
// Create or Set
await ctx.db.user.create('123', { username: 'Burak', coins: 100 });
// Get
const user = await ctx.db.user.get('123');
// Update
await ctx.db.user.update('123', { coins: user.coins + 50 });
// Delete
await ctx.db.user.delete('123');
// Get All
const allUsers = await ctx.db.user.all();📄 License
Apache-2.0
