Preparing search index...
    Index

    Constructors

    • Creates a new TableManipulation instance

      Parameters

      • tabName: string

        Name of the database table

      • colNames: databaseColumnType[]

        Array of column definitions (excluding the auto-increment ID column)

      Returns TableManipulation

      const table = new TableManipulation("users", [
      { colName: "name", type: "TEXT" },
      { colName: "email", type: "TEXT" },
      { colName: "age", type: "INTEGER" }
      ]);

    Properties

    m_tableName: string
    m_columnsTable: databaseColumnType[]
    m_idColumn: string = 'ID'

    Methods

    • Deletes the entire table from the database

      Parameters

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<boolean>

      Promise resolving to true if successful, false otherwise

      const success = await table.deleteTable(db);
      if (success) {
      console.log("Table deleted successfully");
      }
    • Creates the table in the database if it doesn't exist

      Creates a table with an auto-increment ID column plus all specified columns. All columns are marked as NOT NULL.

      Parameters

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<boolean>

      Promise resolving to true if successful, false otherwise

      const success = await table.createTable(db);
      if (success) {
      console.log("Table created successfully");
      }
    • Deletes a single element from the table by its ID

      Parameters

      • id: number

        The ID of the element to delete

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<boolean>

      Promise resolving to true if successful, false otherwise

      const success = await table.deleteElementById(123, db);
      if (success) {
      console.log("Element deleted successfully");
      }
    • Parameters

      • db: SQLiteDatabase
      • OptionalelementToSearch: Map<string, string | number | (string | number)[]>

      Returns Promise<boolean>

    • Inserts a single element into the table

      Type Parameters

      • TElement

      Parameters

      • element: TElement

        The element to insert (object with properties matching table columns)

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<undefined | number>

      Promise resolving to the inserted element's ID, or undefined if failed

      const user = { name: "John", email: "john@example.com", age: 30 };
      const id = await table.insertElement(user, db);
      if (id) {
      console.log(`User inserted with ID: ${id}`);
      }
    • Parameters

      • id: number
      • elementToUpdate: Map<string, string | number>
      • db: SQLiteDatabase

      Returns Promise<boolean>

    • Performs batch updates on multiple elements using a database transaction

      Updates multiple elements efficiently using a single transaction. If any update fails, the entire transaction is rolled back.

      Parameters

      • updates: { id: number; elementToUpdate: Map<string, string | number> }[]

        Array of update objects containing ID and fields to update

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<boolean>

      Promise resolving to true if all updates successful, false otherwise

      const updates = [
      { id: 1, elementToUpdate: new Map([["name", "John Updated"]]) },
      { id: 2, elementToUpdate: new Map([["age", 31]]) }
      ];
      const success = await table.batchUpdateElementsById(updates, db);
    • Searches for a single element by its ID

      Type Parameters

      • T

      Parameters

      • elementId: number

        The ID of the element to find

      • db: SQLiteDatabase

        SQLite database connection

      Returns Promise<undefined | T>

      Promise resolving to the found element or undefined if not found

      const user = await table.searchElementById<User>(123, db);
      if (user) {
      console.log(`Found user: ${user.name}`);
      }
    • Retrieves random elements from the table

      Type Parameters

      • T

      Parameters

      • numOfElements: number

        Number of random elements to retrieve

      • db: SQLiteDatabase

        SQLite database connection

      • Optionalcolumns: string[]

        Optional array of specific columns to select

      Returns Promise<undefined | T[]>

      Promise resolving to array of random elements or undefined if failed

      const randomUsers = await table.searchRandomlyElement<User>(5, db, ["name", "email"]);
      console.log(`Got ${randomUsers?.length} random users`);
    • Searches for elements matching specified criteria

      Supports both simple equality (e.g., {name: "John"}) and WHERE IN clauses (e.g., {name: ["John", "Jane"]}). Array values automatically generate IN clauses.

      Type Parameters

      • T

      Parameters

      • db: SQLiteDatabase

        SQLite database connection

      • OptionalelementToSearch: Map<string, string | number | (string | number)[]>

        Optional map of column-value pairs. Values can be arrays for IN clauses

      Returns Promise<undefined | T | T[]>

      Promise resolving to matching element(s) or undefined if failed

      // Simple equality search
      const users = await table.searchElement<User>(db, new Map([["age", 25]]));

      // WHERE IN search with array
      const users = await table.searchElement<User>(db, new Map([["name", ["Alice", "Bob"]]]));
    • Prepares WHERE clause from a Map, supporting both equality and IN clauses

      Generates SQL WHERE conditions from a Map of column-value pairs. Supports:

      • Simple values: generates equality conditions (column = ?)
      • Array values: generates IN clauses (column IN (?, ?, ?)) Returns both the WHERE clause string and parameter array for safe parameterized queries.

      Parameters

      • map: Map<string, string | number | (string | number)[]>

        Map of column names to values (can be single values or arrays)

      • Optionalseparator: string

        Separator between conditions (typically "AND" or "OR")

      Returns [string, SQLiteBindValue[]]

      Tuple of [whereClause, parameters]

      // Simple equality
      prepareQueryFromMap(new Map([["age", 25]]), "AND")
      // Returns: ['"age" = ?', [25]]

      // WHERE IN with array
      prepareQueryFromMap(new Map([["name", ["Alice", "Bob"]]]), "AND")
      // Returns: ['"name" IN (?, ?)', ["Alice", "Bob"]]