@otwdesign/db-core 1.2.0 → 1.3.1
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/backup/api.d.ts +55 -0
- package/dist/backup/api.js +441 -0
- package/dist/backup/api.js.map +1 -0
- package/dist/backup/catalog.d.ts +47 -0
- package/dist/backup/catalog.js +348 -0
- package/dist/backup/catalog.js.map +1 -0
- package/dist/backup/dump.d.ts +49 -0
- package/dist/backup/dump.js +860 -0
- package/dist/backup/dump.js.map +1 -0
- package/dist/backup/format.d.ts +38 -0
- package/dist/backup/format.js +70 -0
- package/dist/backup/format.js.map +1 -0
- package/dist/backup/pg-tools.d.ts +30 -0
- package/dist/backup/pg-tools.js +154 -0
- package/dist/backup/pg-tools.js.map +1 -0
- package/dist/backup/restore.d.ts +42 -0
- package/dist/backup/restore.js +196 -0
- package/dist/backup/restore.js.map +1 -0
- package/dist/backup/split.d.ts +18 -0
- package/dist/backup/split.js +316 -0
- package/dist/backup/split.js.map +1 -0
- package/dist/backup/staging.d.ts +29 -0
- package/dist/backup/staging.js +96 -0
- package/dist/backup/staging.js.map +1 -0
- package/dist/browser.d.ts +5 -0
- package/dist/drivers/pglite.js +57 -0
- package/dist/drivers/pglite.js.map +1 -1
- package/dist/drivers/postgres.js +45 -0
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/handler.d.ts +5 -0
- package/dist/handler.js +48 -1
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/types.d.ts +30 -1
- package/package.json +2 -2
- package/src/backup/api.ts +543 -0
- package/src/backup/catalog.ts +381 -0
- package/src/backup/dump.ts +1103 -0
- package/src/backup/format.ts +114 -0
- package/src/backup/pg-tools.ts +186 -0
- package/src/backup/restore.ts +271 -0
- package/src/backup/split.ts +300 -0
- package/src/backup/staging.ts +143 -0
- package/src/browser.ts +5 -0
- package/src/drivers/pglite.ts +55 -0
- package/src/drivers/postgres.ts +46 -0
- package/src/handler.ts +56 -1
- package/src/index.ts +6 -0
- package/src/types.ts +29 -1
package/src/types.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface Capabilities {
|
|
|
47
47
|
* offers them with `databases()` and `withDatabase()`, and a connection may be pinned to its own.
|
|
48
48
|
*/
|
|
49
49
|
databases?: boolean
|
|
50
|
+
/**
|
|
51
|
+
* Whole-database backups and restores: PostgreSQL and PGlite. The API sets it: a driver offers
|
|
52
|
+
* them with `session()`.
|
|
53
|
+
*/
|
|
54
|
+
backup?: boolean
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/** What a schema-tree entry is: SQLite and MySQL have tables and views, PostgreSQL the rest too. */
|
|
@@ -271,9 +276,32 @@ export interface Driver {
|
|
|
271
276
|
* on first use; whoever asked for it closes it.
|
|
272
277
|
*/
|
|
273
278
|
withDatabase?(name: string): Driver
|
|
279
|
+
/**
|
|
280
|
+
* One transaction on a connection of its own, for a backup (`snapshot`: read-only, all of it as
|
|
281
|
+
* of one moment) or a restore (`write`: all of it or none). PostgreSQL and PGlite.
|
|
282
|
+
*/
|
|
283
|
+
session?(mode: 'snapshot' | 'write'): Promise<Session>
|
|
284
|
+
/**
|
|
285
|
+
* The URL pg_dump and pg_restore may connect with: a server's driver has one, PGlite's (a
|
|
286
|
+
* database in the host's own process) doesn't.
|
|
287
|
+
*/
|
|
288
|
+
readonly pgUrl?: string
|
|
274
289
|
close(): Promise<void>
|
|
275
290
|
}
|
|
276
291
|
|
|
292
|
+
/** A backup's or a restore's transaction. Values come back as the server's text. */
|
|
293
|
+
export interface Session {
|
|
294
|
+
/** One statement, its values as $1, $2… (a Uint8Array as bytea). */
|
|
295
|
+
query(sql: string, values?: unknown[]): Promise<{ rows: (string | null)[][] }>
|
|
296
|
+
/** Commits (a restore) or rolls back (a backup), then lets the connection go. */
|
|
297
|
+
end(commit: boolean): Promise<void>
|
|
298
|
+
/**
|
|
299
|
+
* It holds the host while open: PGlite runs in the host's process, one transaction at a time.
|
|
300
|
+
* Finish quickly, without waiting on a slow download.
|
|
301
|
+
*/
|
|
302
|
+
readonly exclusive: boolean
|
|
303
|
+
}
|
|
304
|
+
|
|
277
305
|
/** Who is asking, as the host's `authorize()` says. */
|
|
278
306
|
export interface Viewer {
|
|
279
307
|
/** Recorded in the audit log, such as a user id or an email. */
|
|
@@ -292,7 +320,7 @@ export interface AuditEvent {
|
|
|
292
320
|
connection: string
|
|
293
321
|
/** The database it ran on, when it wasn't the connection's own. */
|
|
294
322
|
database?: string
|
|
295
|
-
action: 'query' | 'rows' | 'count' | 'apply' | 'export' | 'cancel'
|
|
323
|
+
action: 'query' | 'rows' | 'count' | 'apply' | 'export' | 'cancel' | 'backup' | 'restore'
|
|
296
324
|
/** The SQL run, or for `rows`, the table read. */
|
|
297
325
|
statement: string
|
|
298
326
|
durationMs: number
|