Skip to content

Support D1 Sessions API for global read replication #33

@juanferreras

Description

@juanferreras

Cloudflare recently released global read replication for D1 (🎊 ) but it requires tagging all queries within a session to assure read-after-write consistency.

https://developers.cloudflare.com/d1/best-practices/read-replication/#replica-lag-and-consistency-model

I don't think a similar concept exists in Kysely, but we could potentially add a new session? argument to the constructor, and if used, .executeQuery would run against the const session = env.DB.withSession(...) instead of env.DB.

I think we might need to also expose some way of returning session.getBookmark(), and then users would need to:

  1. Make sure to re-initialize on every request and not share a global singleton/etc.
  2. Handle storing the resulting bookmark in an HTTP header and reading from it before initializing in their own code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions