@memberjunction/postgresql-dataprovider 0.0.1 → 5.6.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 +218 -28
- package/dist/PostgreSQLDataProvider.d.ts +138 -0
- package/dist/PostgreSQLDataProvider.d.ts.map +1 -0
- package/dist/PostgreSQLDataProvider.js +626 -0
- package/dist/PostgreSQLDataProvider.js.map +1 -0
- package/dist/PostgreSQLTransactionGroup.d.ts +26 -0
- package/dist/PostgreSQLTransactionGroup.d.ts.map +1 -0
- package/dist/PostgreSQLTransactionGroup.js +117 -0
- package/dist/PostgreSQLTransactionGroup.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/pgConnectionManager.d.ts +78 -0
- package/dist/pgConnectionManager.d.ts.map +1 -0
- package/dist/pgConnectionManager.js +101 -0
- package/dist/pgConnectionManager.js.map +1 -0
- package/dist/queryParameterProcessor.d.ts +24 -0
- package/dist/queryParameterProcessor.d.ts.map +1 -0
- package/dist/queryParameterProcessor.js +54 -0
- package/dist/queryParameterProcessor.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/package.json +33 -7
package/README.md
CHANGED
|
@@ -1,45 +1,235 @@
|
|
|
1
1
|
# @memberjunction/postgresql-dataprovider
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Full-featured PostgreSQL data provider for MemberJunction. This package implements `DatabaseProviderBase` from `@memberjunction/core` to provide a complete PostgreSQL backend for MemberJunction applications. It also includes a CodeGen provider for generating PostgreSQL-native database objects (views, PL/pgSQL functions, triggers, indexes, full-text search, and more).
|
|
6
|
+
|
|
7
|
+
Key capabilities:
|
|
8
|
+
|
|
9
|
+
- Connection pooling via `pg.Pool` with configurable min/max connections
|
|
10
|
+
- Transaction support with BEGIN/COMMIT/ROLLBACK and variable dependencies between items
|
|
11
|
+
- Parameterized queries using PostgreSQL `$1, $2, ...` positional parameters
|
|
12
|
+
- Full CRUD operations through generated PL/pgSQL functions
|
|
13
|
+
- CodeGen provider that produces PostgreSQL-native DDL from MemberJunction metadata
|
|
14
|
+
- Type conversion for booleans, dates, UUIDs, numbers, and binary data
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
### Class Hierarchy
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
DatabaseProviderBase (@memberjunction/core)
|
|
22
|
+
└── PostgreSQLDataProvider
|
|
23
|
+
├── PGConnectionManager (connection pooling)
|
|
24
|
+
├── PGQueryParameterProcessor (type conversion)
|
|
25
|
+
└── PostgreSQLTransactionGroup (transaction support)
|
|
26
|
+
|
|
27
|
+
CodeGenDatabaseProvider (@memberjunction/codegen-lib)
|
|
28
|
+
└── PostgreSQLCodeGenProvider (DDL generation)
|
|
29
|
+
└── PostgreSQLCodeGenConnection (query execution)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Source Files
|
|
33
|
+
|
|
34
|
+
| File | Purpose |
|
|
35
|
+
|------|---------|
|
|
36
|
+
| `PostgreSQLDataProvider.ts` | Main provider: CRUD, queries, view execution, dataset handling, caching |
|
|
37
|
+
| `pgConnectionManager.ts` | Connection pool lifecycle with `pg.Pool`, shared pool support |
|
|
38
|
+
| `queryParameterProcessor.ts` | Boolean, date, UUID, number, and binary type conversion |
|
|
39
|
+
| `types.ts` | `PostgreSQLProviderConfigData` and `PostgreSQLProviderConfigOptions` interfaces |
|
|
40
|
+
| `PostgreSQLTransactionGroup.ts` | BEGIN/COMMIT/ROLLBACK with variable dependencies between transaction items |
|
|
41
|
+
| `codegen/PostgreSQLCodeGenProvider.ts` | CodeGen: views, CRUD functions, triggers, indexes, FTS, permissions |
|
|
42
|
+
| `codegen/PostgreSQLCodeGenConnection.ts` | Translates `@ParamName` notation to `$N` positional parameters |
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
### Connection Configuration
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface PGConnectionConfig {
|
|
50
|
+
Host: string;
|
|
51
|
+
Port?: number; // Default: 5432
|
|
52
|
+
Database: string;
|
|
53
|
+
User: string;
|
|
54
|
+
Password: string;
|
|
55
|
+
SSL?: boolean | pg.ConnectionConfig['ssl'];
|
|
56
|
+
MaxConnections?: number; // Default: 20
|
|
57
|
+
MinConnections?: number; // Default: 2
|
|
58
|
+
IdleTimeoutMillis?: number; // Default: 30000
|
|
59
|
+
ConnectionTimeoutMillis?: number; // Default: 30000
|
|
60
|
+
MJCoreSchemaName?: string; // Default: '__mj'
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Provider Configuration
|
|
65
|
+
|
|
66
|
+
The `PostgreSQLProviderConfigData` class wraps the connection config and adds MemberJunction-specific options:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
const configData = new PostgreSQLProviderConfigData(
|
|
70
|
+
connectionConfig, // PGConnectionConfig
|
|
71
|
+
'__mj', // MJCoreSchemaName (default: '__mj')
|
|
72
|
+
0, // CheckRefreshIntervalSeconds (0 = disabled)
|
|
73
|
+
['public', '__mj'], // includeSchemas (optional)
|
|
74
|
+
[], // excludeSchemas (optional)
|
|
75
|
+
true // ignoreExistingMetadata (default: true)
|
|
76
|
+
);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Environment Variables
|
|
80
|
+
|
|
81
|
+
For CodeGen shell execution (psql):
|
|
82
|
+
|
|
83
|
+
- `PGHOST` -- PostgreSQL server host
|
|
84
|
+
- `PGPORT` -- PostgreSQL server port
|
|
85
|
+
- `PGDATABASE` -- Database name
|
|
86
|
+
- `PGUSER` -- Username
|
|
87
|
+
- `PGPASSWORD` -- Password (or use `.pgpass` file)
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Basic Setup
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { PostgreSQLDataProvider } from '@memberjunction/postgresql-dataprovider';
|
|
95
|
+
|
|
96
|
+
const provider = new PostgreSQLDataProvider();
|
|
97
|
+
await provider.Config(new PostgreSQLProviderConfigData(
|
|
98
|
+
{
|
|
99
|
+
Host: 'localhost',
|
|
100
|
+
Port: 5432,
|
|
101
|
+
Database: 'memberjunction',
|
|
102
|
+
User: 'mj_user',
|
|
103
|
+
Password: 'secret',
|
|
104
|
+
MJCoreSchemaName: '__mj'
|
|
105
|
+
},
|
|
106
|
+
'__mj'
|
|
107
|
+
));
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Running Queries
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// Execute raw SQL with positional parameters
|
|
114
|
+
const result = await provider.ExecuteSQL<MyType>(
|
|
115
|
+
'SELECT * FROM __mj."User" WHERE "ID" = $1',
|
|
116
|
+
[$userId]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// Run views (MJ pattern)
|
|
120
|
+
const results = await provider.InternalRunView<UserEntity>({
|
|
121
|
+
EntityName: 'Users',
|
|
122
|
+
ExtraFilter: "Status='Active'",
|
|
123
|
+
OrderBy: 'Name',
|
|
124
|
+
MaxRows: 100
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Transactions
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const txGroup = await provider.CreateTransactionGroup();
|
|
132
|
+
// Add operations to the transaction group...
|
|
133
|
+
await txGroup.Submit(); // Executes all items in a single BEGIN/COMMIT block
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `PostgreSQLTransactionGroup` supports variable dependencies between transaction items, allowing later items to reference values produced by earlier items in the same transaction.
|
|
137
|
+
|
|
138
|
+
### Connection Pool Sharing
|
|
139
|
+
|
|
140
|
+
The `PGConnectionManager` supports shared pools for scenarios where multiple provider instances need to share a single connection pool (e.g., per-request providers):
|
|
4
141
|
|
|
5
|
-
|
|
142
|
+
```typescript
|
|
143
|
+
// Primary provider creates the pool
|
|
144
|
+
const primary = new PGConnectionManager();
|
|
145
|
+
await primary.Initialize(config);
|
|
146
|
+
|
|
147
|
+
// Per-request providers share the pool (won't close it on Close())
|
|
148
|
+
const perRequest = new PGConnectionManager();
|
|
149
|
+
perRequest.InitializeWithExistingPool(primary.Pool, config);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## CodeGen Provider
|
|
6
153
|
|
|
7
|
-
|
|
154
|
+
### What It Generates
|
|
8
155
|
|
|
9
|
-
|
|
156
|
+
The `PostgreSQLCodeGenProvider` generates PostgreSQL-native database objects during the MemberJunction code generation process:
|
|
10
157
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
158
|
+
- **Base Views** -- `CREATE OR REPLACE VIEW` with joins and soft-delete filtering
|
|
159
|
+
- **CRUD Functions** -- PL/pgSQL functions (not stored procedures) with `RETURNING` clause
|
|
160
|
+
- **Timestamp Triggers** -- PL/pgSQL trigger functions for automatic `__mj_UpdatedAt` maintenance
|
|
161
|
+
- **Foreign Key Indexes** -- `CREATE INDEX IF NOT EXISTS` with 63-character name limit enforcement
|
|
162
|
+
- **Full-Text Search** -- tsvector columns, GIN indexes, PL/pgSQL trigger for auto-update, and search functions
|
|
163
|
+
- **Cascade Deletes** -- Recursive delete/update-to-NULL operations for related records
|
|
164
|
+
- **Permissions** -- GRANT statements per entity role
|
|
165
|
+
- **Drop Guards** -- `DROP ... IF EXISTS ... CASCADE` statements before object creation
|
|
15
166
|
|
|
16
|
-
|
|
167
|
+
### Key PostgreSQL-Specific Patterns
|
|
17
168
|
|
|
18
|
-
|
|
169
|
+
- Uses PL/pgSQL `CREATE OR REPLACE FUNCTION` instead of SQL Server stored procedures
|
|
170
|
+
- Functions return query results via `RETURNS TABLE(...)` or `RETURNS SETOF`
|
|
171
|
+
- Uses dollar-quoted strings (`$$...$$`) for function bodies
|
|
172
|
+
- Implements `LATERAL` joins instead of SQL Server's `OUTER APPLY`
|
|
173
|
+
- Full-text search uses `tsvector`/`tsquery` with GIN indexes (not `CONTAINSTABLE`)
|
|
174
|
+
- Index names are truncated to 63 characters to respect the PostgreSQL identifier limit
|
|
175
|
+
- Boolean columns use native `true`/`false` instead of SQL Server's `1`/`0`
|
|
176
|
+
- Uses `LIMIT`/`OFFSET` for pagination instead of `TOP`/`OFFSET-FETCH`
|
|
177
|
+
- Identifier quoting uses `"double quotes"` instead of SQL Server's `[brackets]`
|
|
19
178
|
|
|
20
|
-
|
|
179
|
+
### Registration
|
|
21
180
|
|
|
22
|
-
|
|
181
|
+
The CodeGen provider is registered via the MemberJunction class factory:
|
|
23
182
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
183
|
+
```typescript
|
|
184
|
+
@RegisterClass(CodeGenDatabaseProvider, 'PostgreSQLCodeGenProvider')
|
|
185
|
+
export class PostgreSQLCodeGenProvider extends CodeGenDatabaseProvider { ... }
|
|
186
|
+
```
|
|
28
187
|
|
|
29
|
-
##
|
|
188
|
+
## Relationship to Other Packages
|
|
30
189
|
|
|
31
|
-
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
190
|
+
### @memberjunction/sql-dialect
|
|
36
191
|
|
|
37
|
-
|
|
192
|
+
- Provides `PostgreSQLDialect` for identifier quoting, pagination syntax, and type mapping
|
|
193
|
+
- Used by both `PostgreSQLDataProvider` and `PostgreSQLCodeGenProvider`
|
|
194
|
+
- Zero-dependency abstraction layer shared across all database-specific code
|
|
38
195
|
|
|
39
|
-
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
196
|
+
### @memberjunction/codegen-lib
|
|
42
197
|
|
|
43
|
-
|
|
198
|
+
- Provides `CodeGenDatabaseProvider` abstract base class with ~55 methods
|
|
199
|
+
- `PostgreSQLCodeGenProvider` implements all abstract methods with PostgreSQL-native SQL
|
|
200
|
+
- The CodeGen orchestration layer calls these methods to generate DDL during code generation runs
|
|
44
201
|
|
|
45
|
-
|
|
202
|
+
### @memberjunction/core
|
|
203
|
+
|
|
204
|
+
- Provides `DatabaseProviderBase` abstract class defining the full MJ data provider contract
|
|
205
|
+
- `PostgreSQLDataProvider` implements CRUD, view execution, dataset operations, and metadata access
|
|
206
|
+
|
|
207
|
+
### @memberjunction/global
|
|
208
|
+
|
|
209
|
+
- Provides `@RegisterClass` for class factory registration
|
|
210
|
+
- `PostgreSQLCodeGenProvider` registers itself so the CodeGen system can discover it at runtime
|
|
211
|
+
|
|
212
|
+
## Dependencies
|
|
213
|
+
|
|
214
|
+
| Package | Purpose |
|
|
215
|
+
|---------|---------|
|
|
216
|
+
| `@memberjunction/core` | Base provider interfaces and entity framework |
|
|
217
|
+
| `@memberjunction/codegen-lib` | CodeGen base class and orchestration types |
|
|
218
|
+
| `@memberjunction/sql-dialect` | SQL dialect abstraction (quoting, pagination, types) |
|
|
219
|
+
| `@memberjunction/global` | Class registration via `@RegisterClass` |
|
|
220
|
+
| `pg` | PostgreSQL Node.js driver (connection pooling, queries) |
|
|
221
|
+
|
|
222
|
+
## Testing
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
cd packages/PostgreSQLDataProvider
|
|
226
|
+
npm run test # Run all tests
|
|
227
|
+
npm run test:watch # Watch mode
|
|
228
|
+
npm run test:coverage # Coverage report
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Tests use Vitest with mocked database connections (no live database required).
|
|
232
|
+
|
|
233
|
+
## Platform Key
|
|
234
|
+
|
|
235
|
+
The provider identifies itself with `PlatformKey: 'postgresql'`, which is used throughout MemberJunction to select the correct SQL dialect, CodeGen templates, and runtime behavior for PostgreSQL deployments.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
import { DatabasePlatform, ExecuteSQLOptions, RunQueryResult, RunQueryParams, UserInfo, EntityInfo, ProviderType, CompositeKey, EntityDependency, BaseEntity, SaveSQLResult, DeleteSQLResult, TransactionGroupBase, ILocalStorageProvider, IMetadataProvider } from '@memberjunction/core';
|
|
3
|
+
import { GenericDatabaseProvider } from '@memberjunction/generic-database-provider';
|
|
4
|
+
import { PostgreSQLDialect } from '@memberjunction/sql-dialect';
|
|
5
|
+
import { PostgreSQLProviderConfigData } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* PostgreSQL data provider for MemberJunction.
|
|
8
|
+
*
|
|
9
|
+
* Implements the full DatabaseProviderBase interface using the `pg` driver.
|
|
10
|
+
* Key differences from SQL Server:
|
|
11
|
+
* - Uses LIMIT/OFFSET instead of TOP/OFFSET-FETCH
|
|
12
|
+
* - Uses $1, $2 positional parameters instead of @p0, @p1
|
|
13
|
+
* - Calls functions (SELECT * FROM fn_name()) instead of EXEC sp_name
|
|
14
|
+
* - Boolean columns use true/false instead of 1/0
|
|
15
|
+
* - Identifier quoting uses "double quotes" instead of [brackets]
|
|
16
|
+
*/
|
|
17
|
+
export declare class PostgreSQLDataProvider extends GenericDatabaseProvider {
|
|
18
|
+
private _connectionManager;
|
|
19
|
+
private _configData;
|
|
20
|
+
private _schemaName;
|
|
21
|
+
private _transaction;
|
|
22
|
+
private _localStorageProvider;
|
|
23
|
+
get PlatformKey(): DatabasePlatform;
|
|
24
|
+
/**************************************************************************/
|
|
25
|
+
/**************************************************************************/
|
|
26
|
+
QuoteIdentifier(name: string): string;
|
|
27
|
+
QuoteSchemaAndView(schemaName: string, objectName: string): string;
|
|
28
|
+
private static readonly _pgUUIDPattern;
|
|
29
|
+
private static readonly _pgDefaultPattern;
|
|
30
|
+
protected get UUIDFunctionPattern(): RegExp;
|
|
31
|
+
protected get DBDefaultFunctionPattern(): RegExp;
|
|
32
|
+
protected BuildChildDiscoverySQL(childEntities: EntityInfo[], recordPKValue: string): string;
|
|
33
|
+
protected BuildHardLinkDependencySQL(entityDependencies: EntityDependency[], compositeKey: CompositeKey): string;
|
|
34
|
+
protected BuildSoftLinkDependencySQL(entityName: string, compositeKey: CompositeKey): string;
|
|
35
|
+
get Dialect(): PostgreSQLDialect;
|
|
36
|
+
get ConfigData(): PostgreSQLProviderConfigData;
|
|
37
|
+
get DatabaseConnection(): pg.Pool;
|
|
38
|
+
get InstanceConnectionString(): string;
|
|
39
|
+
protected get AllowRefresh(): boolean;
|
|
40
|
+
get ProviderType(): ProviderType;
|
|
41
|
+
get MJCoreSchemaName(): string;
|
|
42
|
+
get LocalStorageProvider(): ILocalStorageProvider;
|
|
43
|
+
protected get Metadata(): IMetadataProvider;
|
|
44
|
+
Config(configData: PostgreSQLProviderConfigData): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Configures this provider to share an existing pool from another PostgreSQLDataProvider.
|
|
47
|
+
* Used for per-request providers that should reuse the primary provider's connection pool.
|
|
48
|
+
*/
|
|
49
|
+
ConfigWithSharedPool(configData: PostgreSQLProviderConfigData, existingPool: pg.Pool): Promise<boolean>;
|
|
50
|
+
Dispose(): Promise<void>;
|
|
51
|
+
protected GetTransactionExtraData(_entity: BaseEntity): Record<string, unknown>;
|
|
52
|
+
ExecuteSQL<T>(query: string, parameters?: unknown[], options?: ExecuteSQLOptions, _contextUser?: UserInfo): Promise<Array<T>>;
|
|
53
|
+
BeginTransaction(): Promise<void>;
|
|
54
|
+
CommitTransaction(): Promise<void>;
|
|
55
|
+
RollbackTransaction(): Promise<void>;
|
|
56
|
+
CreateTransactionGroup(): Promise<TransactionGroupBase>;
|
|
57
|
+
protected BuildPaginationSQL(maxRows: number, startRow: number): string;
|
|
58
|
+
protected BuildNonPaginatedLimitSQL(maxRows: number): string;
|
|
59
|
+
/**
|
|
60
|
+
* Transforms user-provided SQL clauses (ExtraFilter, OrderBy) to quote
|
|
61
|
+
* mixed-case identifiers and convert [bracket] notation for PostgreSQL.
|
|
62
|
+
*/
|
|
63
|
+
protected TransformExternalSQLClause(clause: string, entityInfo: EntityInfo): string;
|
|
64
|
+
protected InternalRunQuery(params: RunQueryParams, contextUser?: UserInfo): Promise<RunQueryResult>;
|
|
65
|
+
protected InternalRunQueries(params: RunQueryParams[], contextUser?: UserInfo): Promise<RunQueryResult[]>;
|
|
66
|
+
protected GetCurrentUser(): Promise<UserInfo>;
|
|
67
|
+
/**
|
|
68
|
+
* Public wrapper for GenerateSaveSQL used by PostgreSQLTransactionGroup
|
|
69
|
+
* when transaction variables require regenerating the SQL instruction.
|
|
70
|
+
*/
|
|
71
|
+
GetSaveSQL(entity: BaseEntity, isNew: boolean, user: UserInfo): Promise<SaveSQLResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Generates PostgreSQL function-call SQL for Save (Create/Update).
|
|
74
|
+
* Returns parameterized SQL with $1, $2, ... placeholders.
|
|
75
|
+
*/
|
|
76
|
+
protected GenerateSaveSQL(entity: BaseEntity, isNew: boolean, user: UserInfo): Promise<SaveSQLResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Generates PostgreSQL function-call SQL for Delete.
|
|
79
|
+
* Returns parameterized SQL with $1, $2, ... placeholders.
|
|
80
|
+
*/
|
|
81
|
+
protected GenerateDeleteSQL(entity: BaseEntity, user: UserInfo): DeleteSQLResult;
|
|
82
|
+
/**
|
|
83
|
+
* Quotes bare column identifiers in a SQL fragment (e.g. ExtraFilter) so that
|
|
84
|
+
* mixed-case column names work on PostgreSQL. Already-quoted identifiers
|
|
85
|
+
* (surrounded by double-quotes) and values inside single-quoted strings are
|
|
86
|
+
* left untouched.
|
|
87
|
+
*/
|
|
88
|
+
private quoteIdentifiersInSQL;
|
|
89
|
+
/**
|
|
90
|
+
* Replaces bare field names in a token fragment with double-quoted identifiers.
|
|
91
|
+
* Uses word-boundary matching so that callers who write 'userid' still find 'UserID'.
|
|
92
|
+
*/
|
|
93
|
+
private quoteFieldNamesInToken;
|
|
94
|
+
/**
|
|
95
|
+
* Checks if record change tracking should be applied for the given entity.
|
|
96
|
+
* Excludes the Record Changes entity itself to prevent recursion.
|
|
97
|
+
*/
|
|
98
|
+
private shouldTrackRecordChanges;
|
|
99
|
+
/**
|
|
100
|
+
* Computes the diff between old and new entity values for record change logging.
|
|
101
|
+
* Returns null if there are no changes to log.
|
|
102
|
+
*/
|
|
103
|
+
private computeSaveRecordChangeParams;
|
|
104
|
+
/**
|
|
105
|
+
* Builds a SQL expression that constructs the RecordID string from primary key columns
|
|
106
|
+
* in a CTE result. Format: "FieldName|Value" for single PK, "F1|V1||F2|V2" for composite.
|
|
107
|
+
*/
|
|
108
|
+
private buildRecordIDFromCTE;
|
|
109
|
+
/**
|
|
110
|
+
* Builds a RecordID string from the entity's current primary key values.
|
|
111
|
+
* Used for delete operations where PK values are known.
|
|
112
|
+
*/
|
|
113
|
+
private buildRecordIDFromEntity;
|
|
114
|
+
private getCRUDFunctionName;
|
|
115
|
+
private buildCRUDParams;
|
|
116
|
+
/**
|
|
117
|
+
* Resolves a field value that may contain a database function string.
|
|
118
|
+
* - For UUID generation functions (gen_random_uuid, NEWID, etc.): generates a UUID via GenerateNewID()
|
|
119
|
+
* - For other known DB default functions (GETUTCDATE, NOW, etc.): returns null so the DB uses its default
|
|
120
|
+
* - For all other values: returns as-is
|
|
121
|
+
*/
|
|
122
|
+
private resolveFieldValue;
|
|
123
|
+
private getWritableFields;
|
|
124
|
+
/**
|
|
125
|
+
* Builds PostgreSQL INSERT INTO "RecordChange" SQL for record change logging.
|
|
126
|
+
* Uses parameterized queries with $N placeholders.
|
|
127
|
+
*/
|
|
128
|
+
protected BuildRecordChangeSQL(newData: Record<string, unknown> | null, oldData: Record<string, unknown> | null, entityName: string, recordID: string, entityInfo: EntityInfo, type: 'Create' | 'Update' | 'Delete', user: UserInfo): {
|
|
129
|
+
sql: string;
|
|
130
|
+
parameters?: unknown[];
|
|
131
|
+
} | null;
|
|
132
|
+
/**
|
|
133
|
+
* Builds PostgreSQL SQL for a single sibling entity in the Record Change propagation batch.
|
|
134
|
+
* Uses row_to_json to get the full record JSON, then conditionally inserts a Record Change entry.
|
|
135
|
+
*/
|
|
136
|
+
protected BuildSiblingRecordChangeSQL(_varName: string, entityInfo: EntityInfo, safeChangesJSON: string, safeChangesDesc: string, safePKValue: string, safeUserId: string): string;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=PostgreSQLDataProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PostgreSQLDataProvider.d.ts","sourceRoot":"","sources":["../src/PostgreSQLDataProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACH,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,QAAQ,EACR,UAAU,EAEV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,eAAe,EAEf,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EAGpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAK1D;;;;;;;;;;GAUG;AACH,qBAAa,sBAAuB,SAAQ,uBAAuB;IAC/D,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,OAAO,CAAC,WAAW,CAA6C;IAChE,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,qBAAqB,CAA6D;IAI1F,IAAa,WAAW,IAAI,gBAAgB,CAE3C;IAED,4EAA4E;IAE5E,4EAA4E;IAE5D,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIrC,kB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