All storages moved to our new monorepository, contained all adapters inside of it. Check it out: https://github.com/grammyjs/storages
Database storage adapter that can be used to store your session data via DenoDB when using sessions.
Import the adapter
import { DenoDBAdapter } from "https://deno.land/x/grammy_session_denodb/mod.ts";
Create a Database
const db = new Database(connection);
Define session structure
interface SessionData {
count: number;
}
type MyContext = Context & SessionFlavor<SessionData>;
Register adapter's middleware
const bot = new Bot<MyContext>("<Token>");
bot.use(session({
initial: () => ({ count: 0 }),
storage: new DenoDBAdapter(db),
}));
Use ctx.session
as explained in session plugin's docs.
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),
}));