Class FileAsDataBase

java.lang.Object
me.axolotl.api.sql.FileAsDataBase
All Implemented Interfaces:
BaseDB

public final class FileAsDataBase extends Object implements BaseDB
FileAsDataBase類提供了與存儲在文件中的SQLite數據庫交互的功能。
Since:
2024-02-22
  • Constructor Details

    • FileAsDataBase

      public FileAsDataBase(String path)
      使用指定的文件路徑構造一個新的FileAsDataBase實例。
      Parameters:
      path - SQLite數據庫的文件路徑
  • Method Details

    • getStatus

      public SQLStatus getStatus()
      獲取當前SQL連接的狀態。
      Returns:
      當前SQL狀態
    • connect

      public void connect()
      連接到SQLite數據庫。
      Specified by:
      connect in interface BaseDB
      Throws:
      RuntimeException - 如果無法連接到數據庫
    • disconnect

      public void disconnect()
      斷開與SQLite數據庫的連接。
      Specified by:
      disconnect in interface BaseDB
      Throws:
      RuntimeException - 如果無法從數據庫斷開連接
    • createTable

      public void createTable(String tableId, TableUnit... data)
      在數據庫中創建一個具有指定表ID和數據模式的新表。
      Parameters:
      tableId - 要創建的表的ID
      data - 表的數據模式
      Throws:
      RuntimeException - 在表創建過程中發生錯誤時
    • removeTable

      public void removeTable(String tableId)
      從數據庫中刪除具有指定表ID的現有表。
      Parameters:
      tableId - 要刪除的表的ID
      Throws:
      RuntimeException - 在表刪除過程中發生錯誤時
    • getTableValues

      public ResultSet getTableValues(String tableId, String filter)
      從數據庫中檢索指定表中的值。
      Parameters:
      tableId - 表的ID
      filter - 查詢的過濾條件
      Returns:
      包含查詢值的ResultSet
      Throws:
      RuntimeException - 在查詢過程中發生錯誤時
    • writeToTable

      public void writeToTable(String tableId, Map<String,Object> value)
      將值寫入數據庫中指定的表。
      Parameters:
      tableId - 表的ID
      value - 包含列名和相應值的Map以進行插入
      Throws:
      RuntimeException - 在寫操作過程中發生錯誤時
    • deleteFromTable

      public void deleteFromTable(String tableId, String filter)
      基於提供的過濾器從指定表中刪除記錄。
      Parameters:
      tableId - 表的ID,從中刪除記錄
      filter - 刪除記錄的過濾條件(可以為空)
      Throws:
      RuntimeException - 在刪除過程中發生錯誤時
    • runSearch

      public ResultSet runSearch(String command) throws SQLException
      執行SQL命令並返回生成的ResultSet。
      Specified by:
      runSearch in interface BaseDB
      Parameters:
      command - 要執行的SQL命令
      Returns:
      通過SQL命令執行生成的ResultSet
      Throws:
      SQLException - 如果發生數據庫訪問錯誤或SQL命令無法執行
    • runNormal

      public void runNormal(String command) throws SQLException
      在數據庫上執行一個非查詢的SQL命令。
      Specified by:
      runNormal in interface BaseDB
      Parameters:
      command - 要執行的SQL命令
      Throws:
      SQLException - 如果發生數據庫訪問錯誤或SQL命令無法執行
    • toString

      public String toString()
      Overrides:
      toString in class Object