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

    Class SequelizeAdapter

    Database storage adapter using Sequelize ORM.

    This adapter provides persistent storage for giveaway data using any SQL database supported by Sequelize (PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server). It's ideal for production environments, larger bots, or when you need advanced database features like transactions, relationships, and complex queries.

    Features:

    • Support for multiple database engines
    • Automatic table creation and schema management
    • Built-in connection pooling and optimization
    • Transaction support for data integrity
    • Scalable for high-volume applications
    import { Sequelize } from 'sequelize';
    import { SequelizeAdapter } from 'better-giveaways';

    // PostgreSQL example
    const sequelize = new Sequelize('postgresql://user:pass@localhost:5432/giveaways');

    // SQLite example (good for development)
    const sequelize = new Sequelize({
    dialect: 'sqlite',
    storage: './giveaways.db'
    });

    // MySQL example
    const sequelize = new Sequelize('mysql://user:pass@localhost:3306/giveaways');

    const adapter = new SequelizeAdapter(sequelize);
    const giveawayManager = new GiveawayManager(client, adapter, options);

    // Don't forget to sync the database
    await sequelize.sync();

    Implements

    Index

    Constructors

    Methods

    Constructors

    • Creates a new SequelizeAdapter instance.

      The adapter will automatically initialize the GiveawayModel using the provided Sequelize instance. Make sure to call sequelize.sync() to create the database tables before using the adapter.

      Parameters

      • sequelize: Sequelize

        A configured Sequelize instance connected to your database

      Returns SequelizeAdapter

      import { Sequelize } from 'sequelize';

      const sequelize = new Sequelize({
      dialect: 'postgres',
      host: 'localhost',
      database: 'giveaways',
      username: 'user',
      password: 'password',
      logging: false // Set to console.log to see SQL queries
      });

      const adapter = new SequelizeAdapter(sequelize);

      // Create tables if they don't exist
      await sequelize.sync();

    Methods

    • Saves or updates giveaway data in the database.

      Uses Sequelize's upsert operation which will insert a new record if the giveaway doesn't exist, or update the existing record if it does.

      Parameters

      Returns Promise<void>

      If database operation fails

    • Retrieves a specific giveaway by its primary key (giveawayId).

      Parameters

      • id: string

        The unique giveaway ID to retrieve

      Returns Promise<null | GiveawayData>

      The giveaway data or null if not found

      If database operation fails

    • Deletes a giveaway from the database.

      Parameters

      • id: string

        The unique giveaway ID to delete

      Returns Promise<void>

      If database operation fails