1.1.3 • Published 12 months ago

aikodb v1.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Downloads DownloadPerMonth

AikoDB

AikoDB is a simple and easy-to-use database module that supports both JSON-based databases. It is especially ideal for Discord bots.

Installation

You can install AikoDB using npm:

npm install aikodb

Usage Using AikoDB is very simple. You can create a JSON database and perform various database operations.

Usage with Discord Bot Using AikoDB with a Discord bot is also very straightforward. Here is a simple example:

const { Client, GatewayIntentBits, Partials } = require('discord.js');
const client = new Client({
  intents: Object.values(GatewayIntentBits),
  partials: Object.values(Partials),
  shards: 'auto'
});
const AikoDB = require('aikodb'); // Added AikoDB module

// Create a database with AikoDB
const db = new AikoDB('json', 'data.json'); // const yamlDb = new AikoDB('yaml','aikodb yml');

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate', async message => {
  if (message.content.startsWith('!set')) {
    const args = message.content.slice('!set'.length).trim().split(' ');
    const key = args[0];
    const value = args.slice(1).join(' ');

    await db.set(key, value);
    message.channel.send(`Data set successfully: ${key} -> ${value}`);
  } else if (message.content.startsWith('!get')) {
    const key = message.content.slice('!get'.length).trim();

    const value = db.get(key);
    if (value) {
      message.channel.send(`Data found: ${key} -> ${value}`);
    } else {
      message.channel.send(`Data not found: ${key}`);
    }
  }
});

client.login('YOUR_BOT_TOKEN');

API

add(key, value)
Adds the specified key and value to the database.

get(key)
Retrieves the value for the specified key.

set(key, value)
Updates or adds the value for the specified key.

delete(key)
Deletes the data for the specified key.

all()
Returns the entire contents of the database.

deleteAll()
Deletes all the contents of the database.

push(key, value)
Adds a value to the array for the specified key. If the key does not exist, it creates a new array.

filter(callback)
Filters saved data within data based on the callback function.

search(key, value)
Searches for data entries that match the specified key-value pair.

sort(key, order = 'asc')
Sorts the database entries based on the specified key and order (ascending or descending).

Example for Advanced Features Here's how to use the new filter, search, and sort features:

const AikoDB = require('aikodb'); // Added AikoDB module

// Create a database with AikoDB
const db = new AikoDB('json', 'data.json');

async function advancedFeatures() {
  await db.set('user1', { name: 'Furki', age: 25 });
  await db.set('user2', { name: 'Ufuk', age: 30 });
  await db.set('user3', { name: 'Nazmi', age: 20 });

  // Filter users by age > 20
  const filteredUsers = db.filter(user => user.age > 20);
  console.log('Filtered Users:', filteredUsers);

  // Search user by name
  const searchedUser = db.search('name', 'Alice');
  console.log('Searched User:', searchedUser);

  // Sort users by age
  const sortedUsers = db.sort('age', 'asc');
  console.log('Sorted Users:', sortedUsers);
}

advancedFeatures();

✨ Support

You can come to our Discord server and get help and support on #support channel. Or if you send a friend to my discord account, I will return as soon as possible.

1.1.3

12 months ago

1.1.2

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago