@remix-run/data-table-postgres 0.1.0 → 0.3.0
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/README.md +9 -16
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/adapter.d.ts +100 -39
- package/dist/lib/adapter.d.ts.map +1 -1
- package/dist/lib/adapter.js +559 -23
- package/dist/lib/sql-compiler.d.ts +2 -7
- package/dist/lib/sql-compiler.d.ts.map +1 -1
- package/dist/lib/sql-compiler.js +50 -80
- package/package.json +6 -7
- package/src/index.ts +0 -7
- package/src/lib/adapter.ts +683 -84
- package/src/lib/sql-compiler.ts +66 -106
package/README.md
CHANGED
|
@@ -5,12 +5,16 @@ Use this package when you want `data-table` APIs backed by `pg`.
|
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
|
-
- **Native `pg` Integration**: Works with `Pool` and
|
|
8
|
+
- **Native `pg` Integration**: Works with `pg` `Pool` and `PoolClient` instances
|
|
9
9
|
- **Full `data-table` API Support**: Queries, relations, writes, and transactions
|
|
10
|
+
- **Adapter-Owned Compiler**: SQL compilation lives in this adapter, with optional shared pure helpers from `data-table`
|
|
11
|
+
- **Migration DDL Support**: Compiles and executes `DataMigrationOperation` operations for `remix/data-table/migrations`
|
|
10
12
|
- **Postgres Capabilities Enabled By Default**:
|
|
11
13
|
- `returning: true`
|
|
12
14
|
- `savepoints: true`
|
|
13
15
|
- `upsert: true`
|
|
16
|
+
- `transactionalDdl: true`
|
|
17
|
+
- `migrationLock: true`
|
|
14
18
|
|
|
15
19
|
## Installation
|
|
16
20
|
|
|
@@ -33,6 +37,7 @@ let db = createDatabase(createPostgresDatabaseAdapter(pool))
|
|
|
33
37
|
```
|
|
34
38
|
|
|
35
39
|
Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
|
|
40
|
+
Import any driver-specific types you need directly from `pg`.
|
|
36
41
|
|
|
37
42
|
## Adapter Capabilities
|
|
38
43
|
|
|
@@ -41,6 +46,8 @@ Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
|
|
|
41
46
|
- `returning: true`
|
|
42
47
|
- `savepoints: true`
|
|
43
48
|
- `upsert: true`
|
|
49
|
+
- `transactionalDdl: true`
|
|
50
|
+
- `migrationLock: true`
|
|
44
51
|
|
|
45
52
|
## Advanced Usage
|
|
46
53
|
|
|
@@ -55,24 +62,10 @@ await db.transaction(async (txDb) => txDb.exec('select 1'), {
|
|
|
55
62
|
})
|
|
56
63
|
```
|
|
57
64
|
|
|
58
|
-
### Capability Overrides For Testing
|
|
59
|
-
|
|
60
|
-
You can override capabilities to verify fallback paths in tests.
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import { createPostgresDatabaseAdapter } from 'remix/data-table-postgres'
|
|
64
|
-
|
|
65
|
-
let adapter = createPostgresDatabaseAdapter(pool, {
|
|
66
|
-
capabilities: {
|
|
67
|
-
returning: false,
|
|
68
|
-
},
|
|
69
|
-
})
|
|
70
|
-
```
|
|
71
|
-
|
|
72
65
|
## Related Packages
|
|
73
66
|
|
|
74
67
|
- [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
|
|
75
|
-
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema
|
|
68
|
+
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
|
|
76
69
|
- [`data-table-mysql`](https://github.com/remix-run/remix/tree/main/packages/data-table-mysql) - MySQL adapter
|
|
77
70
|
- [`data-table-sqlite`](https://github.com/remix-run/remix/tree/main/packages/data-table-sqlite) - SQLite adapter
|
|
78
71
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export type { PostgresDatabaseAdapterOptions, PostgresDatabaseClient, PostgresDatabasePool, PostgresQueryResult, PostgresTransactionClient, } from './lib/adapter.ts';
|
|
2
1
|
export { createPostgresDatabaseAdapter, PostgresDatabaseAdapter } from './lib/adapter.ts';
|
|
3
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/lib/adapter.d.ts
CHANGED
|
@@ -1,64 +1,125 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
} & {};
|
|
5
|
-
/**
|
|
6
|
-
* Result shape returned by postgres client `query()` calls.
|
|
7
|
-
*/
|
|
8
|
-
export type PostgresQueryResult = {
|
|
9
|
-
rows: unknown[];
|
|
10
|
-
rowCount: number | null;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Minimal postgres client contract used by this adapter.
|
|
14
|
-
*/
|
|
15
|
-
export type PostgresDatabaseClient = {
|
|
16
|
-
query(text: string, values?: unknown[]): Promise<PostgresQueryResult>;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Postgres transaction client with optional connection release support.
|
|
20
|
-
*/
|
|
21
|
-
export type PostgresTransactionClient = Pretty<PostgresDatabaseClient & {
|
|
22
|
-
release?: () => void;
|
|
23
|
-
}>;
|
|
24
|
-
/**
|
|
25
|
-
* Postgres pool-like client contract used by this adapter.
|
|
26
|
-
*/
|
|
27
|
-
export type PostgresDatabasePool = Pretty<PostgresDatabaseClient & {
|
|
28
|
-
connect?: () => Promise<PostgresTransactionClient>;
|
|
29
|
-
}>;
|
|
30
|
-
/**
|
|
31
|
-
* Postgres adapter configuration.
|
|
32
|
-
*/
|
|
33
|
-
export type PostgresDatabaseAdapterOptions = {
|
|
34
|
-
capabilities?: AdapterCapabilityOverrides;
|
|
35
|
-
};
|
|
1
|
+
import type { DataMigrationRequest, DataManipulationRequest, DataMigrationResult, DataMigrationOperation, DataManipulationResult, DataManipulationOperation, DatabaseAdapter, SqlStatement, TableRef, TransactionOptions, TransactionToken } from '@remix-run/data-table';
|
|
2
|
+
import type { Client as PostgresClient, Pool as PostgresPool, PoolClient as PostgresPoolClient } from 'pg';
|
|
3
|
+
type PostgresQueryable = PostgresClient | PostgresPool | PostgresPoolClient;
|
|
36
4
|
/**
|
|
37
5
|
* `DatabaseAdapter` implementation for postgres-compatible clients.
|
|
38
6
|
*/
|
|
39
7
|
export declare class PostgresDatabaseAdapter implements DatabaseAdapter {
|
|
40
8
|
#private;
|
|
9
|
+
/**
|
|
10
|
+
* The SQL dialect identifier reported by this adapter.
|
|
11
|
+
*/
|
|
41
12
|
dialect: string;
|
|
13
|
+
/**
|
|
14
|
+
* Feature flags describing the postgres behaviors supported by this adapter.
|
|
15
|
+
*/
|
|
42
16
|
capabilities: {
|
|
43
17
|
returning: boolean;
|
|
44
18
|
savepoints: boolean;
|
|
45
19
|
upsert: boolean;
|
|
20
|
+
transactionalDdl: boolean;
|
|
21
|
+
migrationLock: boolean;
|
|
46
22
|
};
|
|
47
|
-
constructor(client:
|
|
48
|
-
|
|
23
|
+
constructor(client: PostgresQueryable);
|
|
24
|
+
/**
|
|
25
|
+
* Compiles a data or migration operation to postgres SQL statements.
|
|
26
|
+
* @param operation Operation to compile.
|
|
27
|
+
* @returns Compiled SQL statements.
|
|
28
|
+
*/
|
|
29
|
+
compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[];
|
|
30
|
+
/**
|
|
31
|
+
* Executes a postgres data-manipulation request.
|
|
32
|
+
* @param request Request to execute.
|
|
33
|
+
* @returns Execution result.
|
|
34
|
+
*/
|
|
35
|
+
execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Executes postgres migration operations.
|
|
38
|
+
* @param request Migration request to execute.
|
|
39
|
+
* @returns Migration result.
|
|
40
|
+
*/
|
|
41
|
+
migrate(request: DataMigrationRequest): Promise<DataMigrationResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks whether a table exists in postgres.
|
|
44
|
+
* @param table Table reference to inspect.
|
|
45
|
+
* @param transaction Optional transaction token.
|
|
46
|
+
* @returns `true` when the table exists.
|
|
47
|
+
*/
|
|
48
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Checks whether a column exists in postgres.
|
|
51
|
+
* @param table Table reference to inspect.
|
|
52
|
+
* @param column Column name to look up.
|
|
53
|
+
* @param transaction Optional transaction token.
|
|
54
|
+
* @returns `true` when the column exists.
|
|
55
|
+
*/
|
|
56
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Starts a postgres transaction.
|
|
59
|
+
* @param options Transaction options.
|
|
60
|
+
* @returns Transaction token.
|
|
61
|
+
*/
|
|
49
62
|
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
|
|
63
|
+
/**
|
|
64
|
+
* Commits an open postgres transaction.
|
|
65
|
+
* @param token Transaction token to commit.
|
|
66
|
+
* @returns A promise that resolves when the transaction is committed.
|
|
67
|
+
*/
|
|
50
68
|
commitTransaction(token: TransactionToken): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Rolls back an open postgres transaction.
|
|
71
|
+
* @param token Transaction token to roll back.
|
|
72
|
+
* @returns A promise that resolves when the transaction is rolled back.
|
|
73
|
+
*/
|
|
51
74
|
rollbackTransaction(token: TransactionToken): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a savepoint in an open postgres transaction.
|
|
77
|
+
* @param token Transaction token to use.
|
|
78
|
+
* @param name Savepoint name.
|
|
79
|
+
* @returns A promise that resolves when the savepoint is created.
|
|
80
|
+
*/
|
|
52
81
|
createSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Rolls back to a savepoint in an open postgres transaction.
|
|
84
|
+
* @param token Transaction token to use.
|
|
85
|
+
* @param name Savepoint name.
|
|
86
|
+
* @returns A promise that resolves when the rollback completes.
|
|
87
|
+
*/
|
|
53
88
|
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Releases a savepoint in an open postgres transaction.
|
|
91
|
+
* @param token Transaction token to use.
|
|
92
|
+
* @param name Savepoint name.
|
|
93
|
+
* @returns A promise that resolves when the savepoint is released.
|
|
94
|
+
*/
|
|
54
95
|
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Acquires the postgres migration lock.
|
|
98
|
+
* @returns A promise that resolves when the lock is acquired.
|
|
99
|
+
*/
|
|
100
|
+
acquireMigrationLock(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Releases the postgres migration lock.
|
|
103
|
+
* @returns A promise that resolves when the lock is released.
|
|
104
|
+
*/
|
|
105
|
+
releaseMigrationLock(): Promise<void>;
|
|
55
106
|
}
|
|
56
107
|
/**
|
|
57
108
|
* Creates a postgres `DatabaseAdapter`.
|
|
58
|
-
* @param client
|
|
109
|
+
* @param client `pg` pool or pool client.
|
|
59
110
|
* @param options Optional adapter capability overrides.
|
|
60
111
|
* @returns A configured postgres adapter.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { Pool } from 'pg'
|
|
115
|
+
* import { createDatabase } from 'remix/data-table'
|
|
116
|
+
* import { createPostgresDatabaseAdapter } from 'remix/data-table-postgres'
|
|
117
|
+
*
|
|
118
|
+
* let pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
119
|
+
* let adapter = createPostgresDatabaseAdapter(pool)
|
|
120
|
+
* let db = createDatabase(adapter)
|
|
121
|
+
* ```
|
|
61
122
|
*/
|
|
62
|
-
export declare function createPostgresDatabaseAdapter(client:
|
|
123
|
+
export declare function createPostgresDatabaseAdapter(client: PostgresQueryable): PostgresDatabaseAdapter;
|
|
63
124
|
export {};
|
|
64
125
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,eAAe,EAEf,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,EACV,MAAM,IAAI,cAAc,EACxB,IAAI,IAAI,YAAY,EACpB,UAAU,IAAI,kBAAkB,EACjC,MAAM,IAAI,CAAA;AASX,KAAK,iBAAiB,GAAG,cAAc,GAAG,YAAY,GAAG,kBAAkB,CAAA;AAE3E;;GAEG;AACH,qBAAa,uBAAwB,YAAW,eAAe;;IAC7D;;OAEG;IACH,OAAO,SAAa;IAEpB;;OAEG;IACH,YAAY;;;;;;MAAA;IAMZ,YAAY,MAAM,EAAE,iBAAiB,EASpC;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,yBAAyB,GAAG,sBAAsB,GAAG,YAAY,EAAE,CAOxF;IAED;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAuB/E;IAED;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAWzE;IAED;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAMhF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