Skip to content
Discordjs-NextgenPublic

About

A flexible, model-based database abstraction layer for discordjs-nextgen. Designed to be database-agnostic while providing a Mongoose-like developer experience.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

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-nextgen via app.db and ctx.db.
  • Type Safe: Full TypeScript support with module augmentation.

📦 Installation

npm install discordjs-nextgen-db

For 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-sqlite3
import { 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 mysql2
import { 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 mongoose
import { 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

About

A flexible, model-based database abstraction layer for discordjs-nextgen. Designed to be database-agnostic while providing a Mongoose-like developer experience.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages