@@ -135,6 +135,88 @@ properties:
135135[ `node:sqlite` ] : https://nodejs.org/api/sqlite.html
136136
137137
138+ ` PostgresRepository `
139+ --------------------
140+
141+ * This API is available since BotKit 0.4.0.*
142+
143+ The ` PostgresRepository ` is a repository that stores data in PostgreSQL using
144+ the [ Postgres.js] driver. It is suited for deployments where multiple bot
145+ processes need to share the same persistent repository state, or where you
146+ already operate PostgreSQL for other infrastructure.
147+
148+ Unlike [ ` KvRepository ` ] ( #kvrepository ) , ` PostgresRepository ` stores BotKit data
149+ in ordinary PostgreSQL tables rather than a key-value abstraction. It creates
150+ tables inside a dedicated PostgreSQL schema, uses transactions for multi-step
151+ updates, and supports either an internally owned connection pool or an injected
152+ Postgres.js client.
153+
154+ In order to use ` PostgresRepository ` , you need to install the
155+ * @fedify/botkit-postgres * package:
156+
157+ ::: code-group
158+
159+ ~~~~ sh [Deno]
160+ deno add jsr:@fedify/botkit-postgres
161+ ~~~~
162+
163+ ~~~~ sh [npm]
164+ npm add @fedify/botkit-postgres
165+ ~~~~
166+
167+ ~~~~ sh [pnpm]
168+ pnpm add @fedify/botkit-postgres
169+ ~~~~
170+
171+ ~~~~ sh [Yarn]
172+ yarn add @fedify/botkit-postgres
173+ ~~~~
174+
175+ :::
176+
177+ The ` PostgresRepository ` constructor accepts an options object with the
178+ following properties:
179+
180+ ` sql `
181+ : An existing [ Postgres.js] client. When this is provided, the repository
182+ does not own the client and calling ` close() ` will not shut it down.
183+
184+ ` url `
185+ : A PostgreSQL connection string used to create an internal connection pool.
186+ Exactly one of ` sql ` and ` url ` must be provided.
187+
188+ ` schema ` (optional)
189+ : The PostgreSQL schema used for BotKit tables. Defaults to ` "botkit" ` .
190+
191+ ` maxConnections ` (optional)
192+ : The maximum number of connections for the internally created pool. This
193+ option is only valid when ` url ` is used.
194+
195+ ` prepare ` (optional)
196+ : Whether to use prepared statements for repository queries. Defaults to
197+ ` true ` .
198+
199+ These options are mutually exclusive: use either ` sql ` or ` url ` . The
200+ ` maxConnections ` option is only meaningful together with ` url ` .
201+
202+ The repository initializes its tables and indexes automatically. If you want
203+ to provision them before creating the repository, use the exported
204+ ` initializePostgresRepositorySchema() ` helper:
205+
206+ ~~~~ typescript
207+ import postgres from " postgres" ;
208+ import { initializePostgresRepositorySchema } from " @fedify/botkit-postgres" ;
209+
210+ const sql = postgres (" postgresql://localhost/botkit" );
211+ await initializePostgresRepositorySchema (sql , " botkit" );
212+ ~~~~
213+
214+ If you disable prepared statements for PgBouncer-style deployments, pass
215+ ` false ` as the third argument so schema initialization uses the same setting.
216+
217+ [ Postgres.js ] : https://github.com/porsager/postgres
218+
219+
138220` MemoryRepository `
139221------------------
140222
0 commit comments