Better Giveaways - v1.0.0-beta.2
    Preparing search index...

    Class JSONAdapter

    File-based storage adapter using JSON format.

    This adapter provides persistent storage for giveaway data using a local JSON file. It's ideal for simple deployments, development environments, or small bots where database setup might be overkill.

    Features:

    • Automatic file creation if it doesn't exist
    • In-memory caching for better performance
    • Atomic write operations to prevent data corruption
    • Human-readable JSON format for easy debugging
    import { JSONAdapter } from 'better-giveaways';

    // Use default file location (./giveaways.json)
    const adapter = new JSONAdapter();

    // Or specify a custom file path
    const adapter = new JSONAdapter('./data/my-giveaways.json');

    // Use with GiveawayManager
    const giveawayManager = new GiveawayManager(client, adapter, options);

    Implements

    Index

    Constructors

    Methods

    Constructors

    • Creates a new JSONAdapter instance.

      Parameters

      • filePath: string = "./giveaways.json"

        The path to the JSON file for storing giveaway data. Defaults to './giveaways.json' in the current working directory. The file will be created automatically if it doesn't exist.

      Returns JSONAdapter

      // Use default location
      const adapter = new JSONAdapter();

      // Use custom location
      const adapter = new JSONAdapter('./data/giveaways.json');

      // Use absolute path
      const adapter = new JSONAdapter('/var/lib/bot/giveaways.json');

    Methods

    • Saves or updates giveaway data.

      If a giveaway with the same ID already exists, it will be updated. Otherwise, a new giveaway will be added to the storage.

      Parameters

      Returns Promise<void>

      If the file cannot be written

    • Deletes a giveaway from storage.

      Parameters

      • id: string

        The unique giveaway ID to delete

      Returns Promise<void>

      If the file cannot be written

    • Updates an existing giveaway with new data.

      This implementation deletes the old giveaway and saves the new data, ensuring the giveaway ID can be changed if needed.

      Parameters

      • id: string

        The current giveaway ID to update

      • data: GiveawayData

        The new giveaway data

      Returns Promise<void>

      If the file cannot be written