@remix-run/data-table-postgres 0.0.0 → 0.2.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/LICENSE +21 -0
- package/README.md +87 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/adapter.d.ts +131 -0
- package/dist/lib/adapter.d.ts.map +1 -0
- package/dist/lib/adapter.js +735 -0
- package/dist/lib/sql-compiler.d.ts +3 -0
- package/dist/lib/sql-compiler.d.ts.map +1 -0
- package/dist/lib/sql-compiler.js +362 -0
- package/package.json +48 -7
- package/src/index.ts +2 -0
- package/src/lib/adapter.ts +932 -0
- package/src/lib/sql-compiler.ts +501 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shopify Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# data-table-postgres
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PostgreSQL adapter for [`remix/data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table).
|
|
4
|
+
Use this package when you want `data-table` APIs backed by `pg`.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **Native `pg` Integration**: Works with `pg` `Pool` and `PoolClient` instances
|
|
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`
|
|
12
|
+
- **Postgres Capabilities Enabled By Default**:
|
|
13
|
+
- `returning: true`
|
|
14
|
+
- `savepoints: true`
|
|
15
|
+
- `upsert: true`
|
|
16
|
+
- `transactionalDdl: true`
|
|
17
|
+
- `migrationLock: true`
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm i remix pg
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Pool } from 'pg'
|
|
29
|
+
import { createDatabase } from 'remix/data-table'
|
|
30
|
+
import { createPostgresDatabaseAdapter } from 'remix/data-table-postgres'
|
|
31
|
+
|
|
32
|
+
let pool = new Pool({
|
|
33
|
+
connectionString: process.env.DATABASE_URL,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let db = createDatabase(createPostgresDatabaseAdapter(pool))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Use `db.query(...)`, relation loading, and transactions from `remix/data-table`.
|
|
40
|
+
Import any driver-specific types you need directly from `pg`.
|
|
41
|
+
|
|
42
|
+
## Adapter Capabilities
|
|
43
|
+
|
|
44
|
+
`data-table-postgres` reports this capability set by default:
|
|
45
|
+
|
|
46
|
+
- `returning: true`
|
|
47
|
+
- `savepoints: true`
|
|
48
|
+
- `upsert: true`
|
|
49
|
+
- `transactionalDdl: true`
|
|
50
|
+
- `migrationLock: true`
|
|
51
|
+
|
|
52
|
+
## Advanced Usage
|
|
53
|
+
|
|
54
|
+
### Transaction Options
|
|
55
|
+
|
|
56
|
+
Transaction options are passed through to the adapter as hints.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await db.transaction(async (txDb) => txDb.exec('select 1'), {
|
|
60
|
+
isolationLevel: 'serializable',
|
|
61
|
+
readOnly: false,
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Capability Overrides For Testing
|
|
66
|
+
|
|
67
|
+
You can override capabilities to verify fallback paths in tests.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { createPostgresDatabaseAdapter } from 'remix/data-table-postgres'
|
|
71
|
+
|
|
72
|
+
let adapter = createPostgresDatabaseAdapter(pool, {
|
|
73
|
+
capabilities: {
|
|
74
|
+
returning: false,
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Related Packages
|
|
80
|
+
|
|
81
|
+
- [`data-table`](https://github.com/remix-run/remix/tree/main/packages/data-table) - Core query/relations API
|
|
82
|
+
- [`data-schema`](https://github.com/remix-run/remix/tree/main/packages/data-schema) - Schema parsing and validation
|
|
83
|
+
- [`data-table-mysql`](https://github.com/remix-run/remix/tree/main/packages/data-table-mysql) - MySQL adapter
|
|
84
|
+
- [`data-table-sqlite`](https://github.com/remix-run/remix/tree/main/packages/data-table-sqlite) - SQLite adapter
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
See [LICENSE](https://github.com/remix-run/remix/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createPostgresDatabaseAdapter, PostgresDatabaseAdapter } from "./lib/adapter.js";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { AdapterCapabilityOverrides, DataMigrationRequest, DataManipulationRequest, DataMigrationResult, DataMigrationOperation, DataManipulationResult, DataManipulationOperation, DatabaseAdapter, SqlStatement, TableRef, TransactionOptions, TransactionToken } from '@remix-run/data-table';
|
|
2
|
+
import type { Pool as PostgresPool, PoolClient as PostgresPoolClient } from 'pg';
|
|
3
|
+
/**
|
|
4
|
+
* Postgres adapter configuration.
|
|
5
|
+
*/
|
|
6
|
+
export type PostgresDatabaseAdapterOptions = {
|
|
7
|
+
capabilities?: AdapterCapabilityOverrides;
|
|
8
|
+
};
|
|
9
|
+
type PostgresQueryable = PostgresPool | PostgresPoolClient;
|
|
10
|
+
/**
|
|
11
|
+
* `DatabaseAdapter` implementation for postgres-compatible clients.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PostgresDatabaseAdapter implements DatabaseAdapter {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* The SQL dialect identifier reported by this adapter.
|
|
17
|
+
*/
|
|
18
|
+
dialect: string;
|
|
19
|
+
/**
|
|
20
|
+
* Feature flags describing the postgres behaviors supported by this adapter.
|
|
21
|
+
*/
|
|
22
|
+
capabilities: {
|
|
23
|
+
returning: boolean;
|
|
24
|
+
savepoints: boolean;
|
|
25
|
+
upsert: boolean;
|
|
26
|
+
transactionalDdl: boolean;
|
|
27
|
+
migrationLock: boolean;
|
|
28
|
+
};
|
|
29
|
+
constructor(client: PostgresQueryable, options?: PostgresDatabaseAdapterOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Compiles a data or migration operation to postgres SQL statements.
|
|
32
|
+
* @param operation Operation to compile.
|
|
33
|
+
* @returns Compiled SQL statements.
|
|
34
|
+
*/
|
|
35
|
+
compileSql(operation: DataManipulationOperation | DataMigrationOperation): SqlStatement[];
|
|
36
|
+
/**
|
|
37
|
+
* Executes a postgres data-manipulation request.
|
|
38
|
+
* @param request Request to execute.
|
|
39
|
+
* @returns Execution result.
|
|
40
|
+
*/
|
|
41
|
+
execute(request: DataManipulationRequest): Promise<DataManipulationResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Executes postgres migration operations.
|
|
44
|
+
* @param request Migration request to execute.
|
|
45
|
+
* @returns Migration result.
|
|
46
|
+
*/
|
|
47
|
+
migrate(request: DataMigrationRequest): Promise<DataMigrationResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether a table exists in postgres.
|
|
50
|
+
* @param table Table reference to inspect.
|
|
51
|
+
* @param transaction Optional transaction token.
|
|
52
|
+
* @returns `true` when the table exists.
|
|
53
|
+
*/
|
|
54
|
+
hasTable(table: TableRef, transaction?: TransactionToken): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether a column exists in postgres.
|
|
57
|
+
* @param table Table reference to inspect.
|
|
58
|
+
* @param column Column name to look up.
|
|
59
|
+
* @param transaction Optional transaction token.
|
|
60
|
+
* @returns `true` when the column exists.
|
|
61
|
+
*/
|
|
62
|
+
hasColumn(table: TableRef, column: string, transaction?: TransactionToken): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Starts a postgres transaction.
|
|
65
|
+
* @param options Transaction options.
|
|
66
|
+
* @returns Transaction token.
|
|
67
|
+
*/
|
|
68
|
+
beginTransaction(options?: TransactionOptions): Promise<TransactionToken>;
|
|
69
|
+
/**
|
|
70
|
+
* Commits an open postgres transaction.
|
|
71
|
+
* @param token Transaction token to commit.
|
|
72
|
+
* @returns A promise that resolves when the transaction is committed.
|
|
73
|
+
*/
|
|
74
|
+
commitTransaction(token: TransactionToken): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Rolls back an open postgres transaction.
|
|
77
|
+
* @param token Transaction token to roll back.
|
|
78
|
+
* @returns A promise that resolves when the transaction is rolled back.
|
|
79
|
+
*/
|
|
80
|
+
rollbackTransaction(token: TransactionToken): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a savepoint in an open postgres transaction.
|
|
83
|
+
* @param token Transaction token to use.
|
|
84
|
+
* @param name Savepoint name.
|
|
85
|
+
* @returns A promise that resolves when the savepoint is created.
|
|
86
|
+
*/
|
|
87
|
+
createSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Rolls back to a savepoint in an open postgres transaction.
|
|
90
|
+
* @param token Transaction token to use.
|
|
91
|
+
* @param name Savepoint name.
|
|
92
|
+
* @returns A promise that resolves when the rollback completes.
|
|
93
|
+
*/
|
|
94
|
+
rollbackToSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Releases a savepoint in an open postgres transaction.
|
|
97
|
+
* @param token Transaction token to use.
|
|
98
|
+
* @param name Savepoint name.
|
|
99
|
+
* @returns A promise that resolves when the savepoint is released.
|
|
100
|
+
*/
|
|
101
|
+
releaseSavepoint(token: TransactionToken, name: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Acquires the postgres migration lock.
|
|
104
|
+
* @returns A promise that resolves when the lock is acquired.
|
|
105
|
+
*/
|
|
106
|
+
acquireMigrationLock(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Releases the postgres migration lock.
|
|
109
|
+
* @returns A promise that resolves when the lock is released.
|
|
110
|
+
*/
|
|
111
|
+
releaseMigrationLock(): Promise<void>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Creates a postgres `DatabaseAdapter`.
|
|
115
|
+
* @param client `pg` pool or pool client.
|
|
116
|
+
* @param options Optional adapter capability overrides.
|
|
117
|
+
* @returns A configured postgres adapter.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { Pool } from 'pg'
|
|
121
|
+
* import { createDatabase } from 'remix/data-table'
|
|
122
|
+
* import { createPostgresDatabaseAdapter } from 'remix/data-table-postgres'
|
|
123
|
+
*
|
|
124
|
+
* let pool = new Pool({ connectionString: process.env.DATABASE_URL })
|
|
125
|
+
* let adapter = createPostgresDatabaseAdapter(pool)
|
|
126
|
+
* let db = createDatabase(adapter)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function createPostgresDatabaseAdapter(client: PostgresQueryable, options?: PostgresDatabaseAdapterOptions): PostgresDatabaseAdapter;
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/lib/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,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,EAAE,IAAI,IAAI,YAAY,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,IAAI,CAAA;AAIhF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,YAAY,CAAC,EAAE,0BAA0B,CAAA;CAC1C,CAAA;AAOD,KAAK,iBAAiB,GAAG,YAAY,GAAG,kBAAkB,CAAA;AAE1D;;GAEG;AACH,qBAAa,uBAAwB,YAAW,eAA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