@keyv/postgres 2.2.0 → 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
@@ -109,12 +109,8 @@ var KeyvPostgres = class extends import_node_events.default {
109
109
  async getMany(keys) {
110
110
  const getMany = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = ANY($1)`;
111
111
  const rows = await this.query(getMany, [keys]);
112
- const results = [];
113
- for (const key of keys) {
114
- const rowIndex = rows?.findIndex((row) => row.key === key);
115
- results.push(rowIndex > -1 ? rows[rowIndex].value : void 0);
116
- }
117
- return results;
112
+ const rowsMap = new Map(rows.map((row) => [row.key, row]));
113
+ return keys.map((key) => rowsMap.get(key)?.value);
118
114
  }
119
115
  // biome-ignore lint/suspicious/noExplicitAny: type format
120
116
  async set(key, value) {
@@ -124,6 +120,19 @@ var KeyvPostgres = class extends import_node_events.default {
124
120
  DO UPDATE SET value=excluded.value;`;
125
121
  await this.query(upsert, [key, value]);
126
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
+ }
127
136
  async delete(key) {
128
137
  const select = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
129
138
  const del = `DELETE FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
@@ -192,3 +201,4 @@ var index_default = KeyvPostgres;
192
201
  KeyvPostgres,
193
202
  createKeyv
194
203
  });
204
+ /* v8 ignore next -- @preserve */
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
@@ -73,12 +73,8 @@ var KeyvPostgres = class extends EventEmitter {
73
73
  async getMany(keys) {
74
74
  const getMany = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = ANY($1)`;
75
75
  const rows = await this.query(getMany, [keys]);
76
- const results = [];
77
- for (const key of keys) {
78
- const rowIndex = rows?.findIndex((row) => row.key === key);
79
- results.push(rowIndex > -1 ? rows[rowIndex].value : void 0);
80
- }
81
- return results;
76
+ const rowsMap = new Map(rows.map((row) => [row.key, row]));
77
+ return keys.map((key) => rowsMap.get(key)?.value);
82
78
  }
83
79
  // biome-ignore lint/suspicious/noExplicitAny: type format
84
80
  async set(key, value) {
@@ -88,6 +84,19 @@ var KeyvPostgres = class extends EventEmitter {
88
84
  DO UPDATE SET value=excluded.value;`;
89
85
  await this.query(upsert, [key, value]);
90
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
+ }
91
100
  async delete(key) {
92
101
  const select = `SELECT * FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
93
102
  const del = `DELETE FROM ${this.opts.schema}.${this.opts.table} WHERE key = $1`;
@@ -156,3 +165,4 @@ export {
156
165
  createKeyv,
157
166
  index_default as default
158
167
  };
168
+ /* v8 ignore next -- @preserve */
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@keyv/postgres",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "PostgreSQL storage adapter for Keyv",
5
5
  "type": "module",
6
- "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "require": "./dist/index.cjs",
12
- "import": "./dist/index.js"
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
13
19
  }
14
20
  },
15
21
  "repository": {
@@ -42,13 +48,13 @@
42
48
  "keyv": "^5.5.4"
43
49
  },
44
50
  "devDependencies": {
45
- "@biomejs/biome": "^2.2.6",
46
- "@types/pg": "^8.15.5",
47
- "@vitest/coverage-v8": "^3.2.4",
48
- "rimraf": "^6.0.1",
51
+ "@biomejs/biome": "^2.3.6",
52
+ "@types/pg": "^8.15.6",
53
+ "@vitest/coverage-v8": "^4.0.10",
54
+ "rimraf": "^6.1.0",
49
55
  "tsd": "^0.33.0",
50
- "vitest": "^3.2.4",
51
- "@keyv/test-suite": "^2.1.1"
56
+ "vitest": "^4.0.10",
57
+ "@keyv/test-suite": "^2.1.2"
52
58
  },
53
59
  "tsd": {
54
60
  "directory": "test"