@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 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 Postgres connection strings
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 definitions and validation
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,8BAA8B,EAC9B,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,64 +1,125 @@
1
- import type { AdapterCapabilityOverrides, AdapterExecuteRequest, AdapterResult, DatabaseAdapter, TransactionOptions, TransactionToken } from '@remix-run/data-table';
2
- type Pretty<value> = {
3
- [key in keyof value]: value[key];
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: PostgresDatabasePool, options?: PostgresDatabaseAdapterOptions);
48
- execute(request: AdapterExecuteRequest): Promise<AdapterResult>;
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 Postgres pool or 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: PostgresDatabasePool, options?: PostgresDatabaseAdapterOptions): PostgresDatabaseAdapter;
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,0BAA0B,EAC1B,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAK9B,KAAK,MAAM,CAAC,KAAK,IAAI;KAClB,GAAG,IAAI,MAAM,KAAK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