@keyv/postgres 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -120,6 +120,19 @@ var KeyvPostgres = class extends import_node_events.default {
120
120
  DO UPDATE SET value=excluded.value;`;
121
121
  await this.query(upsert, [key, value]);
122
122
  }
123
+ async setMany(entries) {
124
+ const keys = [];
125
+ const values = [];
126
+ for (const { key, value } of entries) {
127
+ keys.push(key);
128
+ values.push(value);
129
+ }
130
+ const upsert = `INSERT INTO ${this.opts.schema}.${this.opts.table} (key, value)
131
+ SELECT * FROM UNNEST($1::text[], $2::text[])
132
+ ON CONFLICT(key)
133
+ DO UPDATE SET value=excluded.value;`;
134
+ await this.query(upsert, [keys, values]);
135
+ }
123
136
  async delete(key) {
124
137
  const select = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
125
138
  const del = `DELETE FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import Keyv, { KeyvStoreAdapter } from 'keyv';
2
+ import Keyv, { KeyvStoreAdapter, KeyvEntry } from 'keyv';
3
3
  import { PoolConfig } from 'pg';
4
4
 
5
5
  type KeyvPostgresOptions = {
@@ -23,6 +23,7 @@ declare class KeyvPostgres extends EventEmitter implements KeyvStoreAdapter {
23
23
  get(key: string): Promise<any>;
24
24
  getMany(keys: string[]): Promise<any[]>;
25
25
  set(key: string, value: any): Promise<void>;
26
+ setMany(entries: KeyvEntry[]): Promise<void>;
26
27
  delete(key: string): Promise<boolean>;
27
28
  deleteMany(keys: string[]): Promise<boolean>;
28
29
  clear(): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import Keyv, { KeyvStoreAdapter } from 'keyv';
2
+ import Keyv, { KeyvStoreAdapter, KeyvEntry } from 'keyv';
3
3
  import { PoolConfig } from 'pg';
4
4
 
5
5
  type KeyvPostgresOptions = {
@@ -23,6 +23,7 @@ declare class KeyvPostgres extends EventEmitter implements KeyvStoreAdapter {
23
23
  get(key: string): Promise<any>;
24
24
  getMany(keys: string[]): Promise<any[]>;
25
25
  set(key: string, value: any): Promise<void>;
26
+ setMany(entries: KeyvEntry[]): Promise<void>;
26
27
  delete(key: string): Promise<boolean>;
27
28
  deleteMany(keys: string[]): Promise<boolean>;
28
29
  clear(): Promise<void>;
package/dist/index.js CHANGED
@@ -84,6 +84,19 @@ var KeyvPostgres = class extends EventEmitter {
84
84
  DO UPDATE SET value=excluded.value;`;
85
85
  await this.query(upsert, [key, value]);
86
86
  }
87
+ async setMany(entries) {
88
+ const keys = [];
89
+ const values = [];
90
+ for (const { key, value } of entries) {
91
+ keys.push(key);
92
+ values.push(value);
93
+ }
94
+ const upsert = `INSERT INTO ${this.opts.schema}.${this.opts.table} (key, value)
95
+ SELECT * FROM UNNEST($1::text[], $2::text[])
96
+ ON CONFLICT(key)
97
+ DO UPDATE SET value=excluded.value;`;
98
+ await this.query(upsert, [keys, values]);
99
+ }
87
100
  async delete(key) {
88
101
  const select = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
89
102
  const del = `DELETE FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/postgres",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "PostgreSQL storage adapter for Keyv",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",