blackcat.js-database - v1.0.6
    Preparing search index...

    Class JSONDriver

    Driver lưu trữ dữ liệu dạng JSON.

    ⚠️ Đây không phải database hoàn chỉnh. Class này chỉ đóng vai trò driver lưu trữ (storage layer) cho class chính Database.

    Toàn bộ logic xử lý key path (a.b.c), validate dữ liệu, và các thao tác database sẽ được thực hiện trong class Database.

    JSONDriver chỉ chịu trách nhiệm:

    • Đọc dữ liệu từ file JSON
    • Ghi dữ liệu xuống file JSON
    const database = new Database({
    driber: new JSONDriver({\
    filePath: "./database.json",
    minifyJSON: false
    })
    });
    Index

    Constructors

    Properties

    Methods

    Constructors

    • Khởi tạo một instance mới của JSONDriver.

      Parameters

      • options: JSONDriverOptions

        Cấu hình driver

        • filePath

          Đường dẫn tới file JSON dùng làm database.

        • minifyJSON

          Nếu true, nội dung JSON sẽ được minify khi ghi ra file để giảm dung lượng.

      Returns JSONDriver

      const database = new Database({
      driver: db = new JSONDriver({
      filePath: "./database.json"
      })
      });

    Properties

    minifyJSON: boolean

    Cho biết có minify JSON khi ghi file hay không.

    Methods

    • Đọc toàn bộ dữ liệu từ file database JSON.

      Nếu file không tồn tại hoặc lỗi parse, method sẽ trả về object rỗng.

      Type Parameters

      • V

        Kiểu dữ liệu database.

      Returns Promise<V>

      Promise chứa toàn bộ dữ liệu database.

    • Xóa toàn bộ database.

      Method này chỉ reset file JSON về {}.

      Returns Promise<boolean>

      true nếu reset thành công.

    • Ghi toàn bộ dữ liệu database xuống file JSON.

      Method này không xử lý key path. Logic cập nhật dữ liệu sẽ được xử lý ở class Database trước khi truyền object hoàn chỉnh vào đây.

      Type Parameters

      • R = any

        Kiểu dữ liệu database.

      Parameters

      • data: R

        Toàn bộ dữ liệu database sau khi đã được cập nhật.

      Returns Promise<R>

      Promise chứa dữ liệu đã ghi.