/** * @adonisjs/session * * (c) AdonisJS * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import type { QueryClientContract } from '@adonisjs/lucid/types/database'; import type { SessionStoreWithTaggingContract, SessionData, TaggedSession } from '../types.ts'; /** * Database store to read/write session data to SQL databases using Lucid. * Supports PostgreSQL, MySQL, SQLite, and other Lucid-compatible databases. * Includes automatic garbage collection of expired sessions. * * @example * const dbStore = new DatabaseStore(db.connection(), '2 hours', { * tableName: 'sessions', * gcProbability: 2 * }) */ export declare class DatabaseStore implements SessionStoreWithTaggingContract { #private; /** * Creates a new database store instance * * @param client - Lucid query client instance * @param age - Session age in seconds or time expression (e.g. '2 hours') * @param options - Configuration options * @param options.tableName - Database table name (defaults to "sessions") * @param options.gcProbability - Garbage collection probability in percent (defaults to 2) */ constructor(client: QueryClientContract, age: string | number, options?: { /** * Defaults to "sessions" */ tableName?: string; /** * The probability (in percent) that garbage collection will be * triggered on any given request. For example, 2 means 2% chance. * * Set to 0 to disable garbage collection. * * Defaults to 2 (2% chance) */ gcProbability?: number; }); /** * Reads session data from the database * * @param sessionId - Session identifier * * @example * const data = await store.read('sess_abc123') */ read(sessionId: string): Promise; /** * Writes session values to the database with expiry. * Uses UPSERT to handle both new and existing sessions. * * @param sessionId - Session identifier * @param values - Session data to store * * @example * await store.write('sess_abc123', { userId: 123 }) */ write(sessionId: string, values: Object): Promise; /** * Removes session data from the database * * @param sessionId - Session identifier to remove * * @example * await store.destroy('sess_abc123') */ destroy(sessionId: string): Promise; /** * Updates the session expiry time in the database * * @param sessionId - Session identifier * * @example * await store.touch('sess_abc123') */ touch(sessionId: string): Promise; /** * Tags a session with a user ID for tracking user sessions. * Uses UPSERT to handle both existing and new sessions. * * @param sessionId - Session identifier * @param userId - User identifier to tag the session with * * @example * await store.tag('sess_abc123', 'user_456') */ tag(sessionId: string, userId: string | number): Promise; /** * Removes the tag association between a session and a user ID. * Sets the user_id column to null for the given session. * * @param sessionId - Session identifier * @param userId - User identifier (for logging purposes) * * @example * await store.untag('sess_abc123', 'user_456') */ untag(sessionId: string, userId: string | number): Promise; /** * Returns all active sessions for a given user ID (tag). * Only returns non-expired sessions. * * @param userId - User identifier to get sessions for * * @example * const sessions = await store.tagged('user_456') */ tagged(userId: string): Promise; }