New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kysely-replication

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kysely-replication - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

package.json
{
"name": "kysely-replication",
"version": "0.2.0",
"version": "0.2.1",
"description": "Replication-aware Kysely query execution",

@@ -5,0 +5,0 @@ "repository": {

@@ -146,1 +146,40 @@ # kysely-replication

```
## Wait for Propagation (PostgreSQL-Only)
When writing to the primary, you may want to ensure that replicas have caught up before considering a mutation as complete. This can be critical for consistency in systems that rely on replicated reads immediately following a write.
Replication is usually near-instantaneous but can occasionally take longer (e.g., 30+ seconds). Therefore, waiting for replication increases mutation execution time, so use this approach selectively where required.
### All Mutations
To wait for replication on every mutation, configure the primary database connection:
```diff
-import { Kysely, PostgresDialect } from 'kysely'
+import { CompiledQuery, Kysely, PostgresDialect } from 'kysely'
import { KyselyReplicationDialect } from 'kysely-replication'
import { RoundRobinReplicaStrategy } from 'kysely-replication/strategy/round-robin'
import { Pool } from 'pg'
const primaryDialect = new PostgresDialect({
pool: new Pool({ connectionString: process.env.DATABASE_URL_PRIMARY }),
+ onCreateConnection: async (connection) => {
+ await connection.executeQuery(CompiledQuery.raw(`set synchronous_commit = 'remote_apply'`))
+ },
})
```
### Ad-Hoc Mutations
If waiting for replication is only required for specific operations, use SET LOCAL within a transaction. This scopes the setting to the transaction without affecting the connection’s global state.
```ts
import { sql } from 'kysely'
await db.transaction().execute(async (trx) => {
await sql`set local synchronous_commit = 'remote_apply'`.execute(trx)
// continue with the transaction as normal
})
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc