Skip to content
Documentation
Drop Method

Drop Method

The drop method is responsible for removing a session by its ID. It deletes the session data from both memory and disk, ensuring complete removal of the session.

Features

  • In-Memory Deletion: Removes sessions from memory.
  • File-Based Deletion: Deletes sessions from the file system.
  • Logging: Provides detailed logging for session deletion operations.

Usage

import versedb from 'verse.db';
 
const adapter = new versedb.connect({
  adapter: "session",
  dataPath: './sessions',
  maxSize: 1000, // for deafualt it will be 10
  ttl: 3600000, // 1 hour in milliseconds, for deafualt it will be 10000
  useMemory: true, // for defualt it will be false
  secure: {
    enable: true,
    secret: 'your-secret-key'
  },
  devLogs: { enable: false, path: "" },
});
 
async function dropSession(sessionId: string) {
  const result = await adapter.drop(sessionId);
  if (result.acknowledged) {
    console.log('Session dropped:', result.message);
  } else {
    console.log('Failed to drop session:', result.errorMessage);
  }
}
 
dropSession('your-session-id');

Parameters

  • sessionId (string): The unique identifier for the session you want to drop.

Returns

  • A Promise that resolves with an AdapterResults object indicating the success or failure of the operation.

Example

const sessionId = "abc123";
adapter
  .drop(sessionId)
  .then((result) => {
    if (result.acknowledged) {
      console.log("Session dropped:", result.message);
    } else {
      console.log("Failed to drop session:", result.errorMessage);
    }
  })
  .catch((error) => {
    console.error("Error dropping session:", error);
  });

Detailed Explanation

  1. In-Memory Deletion: The method first removes the session data from memory.

    • If the session exists in memory, it is deleted.
    • If the session does not exist in memory, the method proceeds to check the file system.
  2. File System Deletion: The method constructs the file path for the session and deletes the file if it exists.

    • If the file exists, it is deleted from the disk.
    • If the file does not exist, an error message is returned.
  3. Logging: Throughout the process, detailed logs are generated for debugging and tracking purposes.

    • Logs include information about session deletion and errors encountered during the operation.

VERSE.DB. Powered by JEDI Studio.