Data Adapter
Data adapter that mediates data objects within the database and integration used for cache management. Like DAO or ORM.
Built-in Data Adapters
Section titled “Built-in Data Adapters”This integration includes three types of data adapters.
JsonFileDataAdapter (default)
Section titled “JsonFileDataAdapter (default)”A data adapter that saves data to a single JSON file.
- By default, saves to
cache.jsonin the image cache directory. - On the dev server, if there is no activity for 1 second after the last operation on the database object, the data is written to the file.
import { JsonFileDataAdapter, type JsonFileDataAdapterOptions,} from "../src/extras/JsonFileDataAdapter.js";
const options: JsonFileDataAdapterOptions = { // ...}
export default defineConfig({ integrations: [ astroImageProcessor({ dataAdapter: new JsonFileDataAdapter(options), }) ]});LokiDataAdapter
Section titled “LokiDataAdapter”A data adapter that utilizes the lightweight document database LokiJS.
- By default, saves to
cache.dbin the image cache directory. - On the dev server, data is written to the file every 10 seconds.
import { LokiDataAdapter, type LokiDataAdapterOptions,} from "../src/extras/LokiDataAdapter.js";
const options: LokiDataAdapterOptions = { // ...}
export default defineConfig({ integrations: [ astroImageProcessor({ dataAdapter: new LokiDataAdapter(options), }) ]});BunSqliteDataAdapter
Section titled “BunSqliteDataAdapter”A data adapter that utilizes the Bun built-in SQLite driver.
- Only available for use with Bun.
- By default, saves to
cache.sqlitein the image cache directory.
import { BunSqliteDataAdapter, type BunSqliteDataAdapterOptions,} from "../src/extras/BunSqliteDataAdapter.js";
const options: BunSqliteDataAdapterOptions = { // ...}
export default defineConfig({ integrations: [ astroImageProcessor({ dataAdapter: new BunSqliteDataAdapter(options), }) ]});Custom Data Adapter
Section titled “Custom Data Adapter”Custom data adapters can be created following the ImgProcDataAdapter interface.
import { ImgProcDataAdapter } from "astro-image-processor/types";
export class CustomDataAdapter implements ImgProcDataAdapter { // ...}Refer to the implementation of built-in data adapters for details.