Skip to content

v0.2.0 - Force execute with specific dialect.

Compare
Choose a tag to compare
@igalklebanov igalklebanov released this 29 Dec 15:11
· 10 commits to main since this release

Hey πŸ‘‹

This release allows forcing execution with a specific dialect on the fly.

First, import the force module where you define your db instance:

import 'kysely-replication/force'

It will add the withPrimary and withReplica methods in various places in the
Kysely API.

Force execute on primary:

const users = await db
  .withPrimary()
  .selectFrom('users')
  .selectAll()
  .execute() // executes on primary instead of replica

Force execute on replica:

const users = await db
  .withReplica()
  .insertInto('users')
  .values({ email: '[email protected]', is_verified: false })
  .execute() // executes on a replica instead of primary

You can also provide a specific replica index to override the replica strategy:

const users = await db
  .withReplica(2)
  .insertInto('users')
  .values({ email: '[email protected]', is_verified: false })
  .execute() // executes on replica 2 instead of primary