ドキュメントナビゲーションを開く
R2D1 / ドキュメント

D1 IndexStore

D1IndexStore は Cloudflare D1 REST API を使う built-in IndexStore です。document identifier と indexed field value だけを再構築可能な projection として保存し、完全な document content は DocumentStore に残します。

依存関係と生成

D1 adapter は dev.nexcraft:r2d1 に含まれます。account、database、API token を明示的に設定します。以下は placeholder で、token は secret configuration から渡します。

implementation("dev.nexcraft:r2d1:<version>")

D1Config

D1Config.toString() は account、database、token の値を隠します。

D1Config config = new D1Config(accountId, databaseId, apiToken);
D1IndexStore indexes = new D1IndexStore(config);

REST transport の境界

public constructor は Java の reusable asynchronous HttpClient で Cloudflare D1 REST API を呼びます。Cloudflare Worker transport を作る、またはサポートすると解釈しないでください。

adapter は executor、scheduler、automatic retry を作りません。アプリケーション所有の HttpClient を渡せますが、store を閉じても client は閉じません。

Collection schema の初期化

initialize(Class<?>) は document annotation を検査し、managed collection schema を作成または検証して CompletionStage を返します。indexes::initialize を PersistenceCollectionFactory に渡します。

D1Config config = new D1Config(accountId, databaseId, apiToken);
D1IndexStore indexes = new D1IndexStore(config);

R2D1 database =
    R2D1.builder()
        .collectionFactory(
            new PersistenceCollectionFactory(
                documentStore, indexes, documentCodec, indexes::initialize))
        .build();

Query projection

D1 adapter は indexed String、Long、Double、Boolean をサポートします。query のために R2 object をダウンロードし、application memory で filter することはありません。

clear(String) は derived rows だけを削除します。table、column、managed index は rebuildIndex() の replacement rows 用に残ります。