grammyjs / storage-denodb

DenoDB database storage adapter for grammY
GNU General Public License v3.0
3 stars 0 forks source link

Archived!!!

All storages moved to our new monorepository, contained all adapters inside of it. Check it out: https://github.com/grammyjs/storages

DenoDB Database Storage Adapter for grammY

Database storage adapter that can be used to store your session data via DenoDB when using sessions.

Instructions

  1. Import the adapter

    import { DenoDBAdapter } from "https://deno.land/x/grammy_session_denodb/mod.ts";
  2. Create a Database

    const db = new Database(connection);
  3. Define session structure

    interface SessionData {
       count: number;
    }
    type MyContext = Context & SessionFlavor<SessionData>;
  4. Register adapter's middleware

    const bot = new Bot<MyContext>("<Token>");
    
    bot.use(session({
       initial: () => ({ count: 0 }),
       storage: new DenoDBAdapter(db),
    }));
  5. Use ctx.session as explained in session plugin's docs.

How to Use

You can check examples folder for full blown usage, or see a simple use case below:

const connection = new SQLite3Connector({ filepath: "./example.db" });
const db = new Database(connection);

type MyContext = Context & SessionFlavor<string>;
const bot = new Bot<MyContext>("<Token>");

bot.use(session({
    initial: () => "test",
    storage: new DenoDBAdapter(db),
}));