문서 탐색 열기
R2D1 / 문서

D1 IndexStore

D1IndexStore는 Cloudflare D1 REST API를 사용하는 built-in IndexStore입니다. document identifier와 indexed field 값만 rebuildable 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 값을 redacts합니다.

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를 소유한다면 두 인자 constructor로 전달할 수 있고 store close는 그 client를 닫지 않습니다.

Collection schema 초기화

initialize(Class<?>)는 document annotation을 검사하고 managed collection schema를 만들거나 검증한 뒤 CompletionStage를 반환합니다. PersistenceCollectionFactory에 indexes::initialize를 전달합니다.

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 값을 지원합니다. D1은 query를 위해 R2 object를 내려받아 application memory에서 filter하지 않습니다.

clear(String)는 derived rows만 제거합니다. table, column, managed index는 rebuildIndex()가 replacement rows를 쓸 때 다시 사용됩니다.