fhir-persistence 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/CHANGELOG.md +86 -1
- package/README.md +47 -14
- package/dist/cjs/index.cjs +309 -241
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/cjs/index.d.ts +175 -35
- package/dist/esm/index.d.ts +175 -35
- package/dist/esm/index.mjs +306 -240
- package/dist/esm/index.mjs.map +4 -4
- package/dist/index.d.ts +175 -35
- package/dist/lib/db/adapter.d.ts +4 -4
- package/dist/lib/db/adapter.d.ts.map +1 -1
- package/dist/lib/db/index.d.ts +1 -2
- package/dist/lib/db/index.d.ts.map +1 -1
- package/dist/lib/db/postgres-adapter.d.ts +1 -19
- package/dist/lib/db/postgres-adapter.d.ts.map +1 -1
- package/dist/lib/index.d.ts +4 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/search/search-executor.d.ts +4 -1
- package/dist/lib/search/search-executor.d.ts.map +1 -1
- package/dist/lib/search/search-sql-builder.d.ts +4 -3
- package/dist/lib/search/search-sql-builder.d.ts.map +1 -1
- package/dist/lib/search/where-builder.d.ts +7 -7
- package/dist/lib/search/where-builder.d.ts.map +1 -1
- package/package.json +12 -3
- package/dist/lib/db/sqlite-adapter.d.ts +0 -41
- package/dist/lib/db/sqlite-adapter.d.ts.map +0 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare function buildAllResourceTableSets(sdRegistry: StructureDefinitio
|
|
|
62
62
|
/**
|
|
63
63
|
* v2: Build a COUNT query using ? placeholders.
|
|
64
64
|
*/
|
|
65
|
-
export declare function buildCountSQLv2(request: SearchRequest, registry: SearchParameterRegistry): CountSQL;
|
|
65
|
+
export declare function buildCountSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): CountSQL;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* v2: DELETE all reference rows for a resource (before re-inserting on update).
|
|
@@ -244,7 +244,7 @@ export declare function buildSearchColumns(resource: FhirResource, impls: Search
|
|
|
244
244
|
* v2: Build a complete search SQL query using ? placeholders.
|
|
245
245
|
* No projectId filter. deleted = 0 (INTEGER).
|
|
246
246
|
*/
|
|
247
|
-
export declare function buildSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry): SearchSQL;
|
|
247
|
+
export declare function buildSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): SearchSQL;
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
250
|
* v2: SELECT by ID — no projectId, returns versionId + deleted.
|
|
@@ -288,7 +288,7 @@ export declare function buildSelfLink(ctx: PaginationContext): string;
|
|
|
288
288
|
* @param registry - The SearchParameterRegistry.
|
|
289
289
|
* @returns TwoPhaseSearchSQL with phase1 query and phase2 template.
|
|
290
290
|
*/
|
|
291
|
-
export declare function buildTwoPhaseSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry): TwoPhaseSearchSQL;
|
|
291
|
+
export declare function buildTwoPhaseSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): TwoPhaseSearchSQL;
|
|
292
292
|
|
|
293
293
|
/**
|
|
294
294
|
* v2: Type-level history SELECT.
|
|
@@ -315,17 +315,16 @@ export declare function buildUpdateMainSQLv2(tableName: string, columns: Record<
|
|
|
315
315
|
/**
|
|
316
316
|
* v2: Build a complete WHERE clause from parsed search params using ? placeholders.
|
|
317
317
|
*/
|
|
318
|
-
export declare function buildWhereClauseV2(params: ParsedSearchParam[], registry: SearchParameterRegistry, resourceType: string): WhereFragment | null;
|
|
318
|
+
export declare function buildWhereClauseV2(params: ParsedSearchParam[], registry: SearchParameterRegistry, resourceType: string, dialect?: SqlDialect): WhereFragment | null;
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
|
-
* v2: Build a WHERE clause fragment using ? placeholders
|
|
321
|
+
* v2: Build a WHERE clause fragment using ? placeholders.
|
|
322
322
|
*
|
|
323
|
-
* Dispatches to type-specific v2 builders.
|
|
324
|
-
* -
|
|
325
|
-
* -
|
|
326
|
-
* - Array columns use `json_each()` instead of PG array operators
|
|
323
|
+
* Dispatches to type-specific v2 builders. Dialect-aware:
|
|
324
|
+
* - SQLite: json_each() for array columns
|
|
325
|
+
* - PostgreSQL: native ARRAY operators
|
|
327
326
|
*/
|
|
328
|
-
export declare function buildWhereFragmentV2(impl: SearchParameterImpl, param: ParsedSearchParam): WhereFragment | null;
|
|
327
|
+
export declare function buildWhereFragmentV2(impl: SearchParameterImpl, param: ParsedSearchParam, dialect?: SqlDialect): WhereFragment | null;
|
|
329
328
|
|
|
330
329
|
declare interface BundleLink {
|
|
331
330
|
relation: string;
|
|
@@ -557,7 +556,9 @@ declare type EvictionPolicy = 'lru' | 'fifo' | 'ttl-only';
|
|
|
557
556
|
* - `deleted` is number (0/1), not boolean
|
|
558
557
|
* - No `_include` / `_revinclude` in this MVP (can be added)
|
|
559
558
|
*/
|
|
560
|
-
export declare function executeSearch(adapter: StorageAdapter, request: SearchRequest, registry: SearchParameterRegistry, options?: SearchOptions_2
|
|
559
|
+
export declare function executeSearch(adapter: StorageAdapter, request: SearchRequest, registry: SearchParameterRegistry, options?: SearchOptions_2 & {
|
|
560
|
+
dialect?: SqlDialect;
|
|
561
|
+
}): Promise<SearchResult_2>;
|
|
561
562
|
|
|
562
563
|
/**
|
|
563
564
|
* A reference extracted from a FHIR resource.
|
|
@@ -1656,6 +1657,30 @@ export declare interface PersistedResource extends FhirResource {
|
|
|
1656
1657
|
};
|
|
1657
1658
|
}
|
|
1658
1659
|
|
|
1660
|
+
/**
|
|
1661
|
+
* Minimal interface that pg.PoolClient satisfies.
|
|
1662
|
+
*/
|
|
1663
|
+
declare interface PgClientLike {
|
|
1664
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1665
|
+
rows: Record<string, unknown>[];
|
|
1666
|
+
rowCount: number | null;
|
|
1667
|
+
}>;
|
|
1668
|
+
release(): void;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* Minimal interface that pg.Pool satisfies.
|
|
1673
|
+
* Allows PostgresAdapter to work without importing `pg`.
|
|
1674
|
+
*/
|
|
1675
|
+
declare interface PgPoolLike {
|
|
1676
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1677
|
+
rows: Record<string, unknown>[];
|
|
1678
|
+
rowCount: number | null;
|
|
1679
|
+
}>;
|
|
1680
|
+
connect(): Promise<PgClientLike>;
|
|
1681
|
+
end(): Promise<void>;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1659
1684
|
/**
|
|
1660
1685
|
* Plan and optimize a search request.
|
|
1661
1686
|
*
|
|
@@ -1680,6 +1705,41 @@ export declare const PLATFORM_RESOURCE_TYPES: ReadonlySet<string>;
|
|
|
1680
1705
|
|
|
1681
1706
|
export declare const PLATFORM_SEARCH_PARAMETERS: SearchParameterResource[];
|
|
1682
1707
|
|
|
1708
|
+
export declare class PostgresAdapter implements StorageAdapter {
|
|
1709
|
+
private readonly pool;
|
|
1710
|
+
private closed;
|
|
1711
|
+
constructor(pool: PgPoolLike);
|
|
1712
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
1713
|
+
changes: number;
|
|
1714
|
+
}>;
|
|
1715
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
1716
|
+
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
1717
|
+
queryStream<T = Record<string, unknown>>(sql: string, params?: unknown[]): AsyncIterable<T>;
|
|
1718
|
+
prepare<T = Record<string, unknown>>(_sql: string): PreparedStatement<T>;
|
|
1719
|
+
transaction<R>(fn: (tx: TransactionContext) => R | Promise<R>): Promise<R>;
|
|
1720
|
+
close(): Promise<void>;
|
|
1721
|
+
private ensureNotClosed;
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
export declare class PostgresDialect implements SqlDialect {
|
|
1725
|
+
readonly name: "postgres";
|
|
1726
|
+
placeholder(index: number): string;
|
|
1727
|
+
textArrayContains(column: string, paramCount: number, paramStartIndex: number): {
|
|
1728
|
+
sql: string;
|
|
1729
|
+
values: unknown[];
|
|
1730
|
+
};
|
|
1731
|
+
like(column: string, paramIndex: number): string;
|
|
1732
|
+
limitOffset(paramStartIndex: number): {
|
|
1733
|
+
sql: string;
|
|
1734
|
+
};
|
|
1735
|
+
arrayLiteral(values: string[]): string;
|
|
1736
|
+
timestampType(): string;
|
|
1737
|
+
booleanType(): string;
|
|
1738
|
+
textArrayType(): string;
|
|
1739
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
1740
|
+
autoIncrementPK(): string;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1683
1743
|
/**
|
|
1684
1744
|
* FHIR search parameter types that support prefixes.
|
|
1685
1745
|
*/
|
|
@@ -2745,30 +2805,110 @@ export declare function splitSearchValues(value: string): string[];
|
|
|
2745
2805
|
*/
|
|
2746
2806
|
export declare type SqlColumnType = 'TEXT' | 'TEXT[]' | 'BOOLEAN' | 'INTEGER' | 'BIGINT' | 'TIMESTAMPTZ' | 'TIMESTAMPTZ[]' | 'DATE' | 'DATE[]' | 'NUMERIC' | 'DOUBLE PRECISION' | 'DOUBLE PRECISION[]' | 'REAL';
|
|
2747
2807
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2808
|
+
/**
|
|
2809
|
+
* SqlDialect — Database-Specific SQL Generation Strategy
|
|
2810
|
+
*
|
|
2811
|
+
* Encapsulates syntax differences between SQLite and PostgreSQL.
|
|
2812
|
+
* Injected into query builders (WhereBuilder, SearchSQLBuilder)
|
|
2813
|
+
* so business logic remains dialect-agnostic.
|
|
2814
|
+
*
|
|
2815
|
+
* v2 upgrade: New file. v1 hardcoded PostgreSQL syntax everywhere.
|
|
2816
|
+
*
|
|
2817
|
+
* @module fhir-persistence/db
|
|
2818
|
+
*/
|
|
2819
|
+
/**
|
|
2820
|
+
* Strategy object for generating database-specific SQL fragments.
|
|
2821
|
+
*
|
|
2822
|
+
* Each adapter implementation provides a matching dialect instance.
|
|
2823
|
+
*/
|
|
2824
|
+
export declare interface SqlDialect {
|
|
2825
|
+
/** Dialect identifier for branching where needed. */
|
|
2826
|
+
readonly name: 'sqlite' | 'postgres';
|
|
2752
2827
|
/**
|
|
2753
|
-
*
|
|
2754
|
-
*
|
|
2828
|
+
* Positional parameter placeholder.
|
|
2829
|
+
* - SQLite: always `?` (index ignored)
|
|
2830
|
+
* - PostgreSQL: `$1`, `$2`, ... (1-based index)
|
|
2755
2831
|
*/
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2832
|
+
placeholder(index: number): string;
|
|
2833
|
+
/**
|
|
2834
|
+
* Generate a TEXT[] array-contains check.
|
|
2835
|
+
*
|
|
2836
|
+
* Checks if any element of a TEXT[] column matches any of the given values.
|
|
2837
|
+
* - SQLite: `EXISTS (SELECT 1 FROM json_each("col") WHERE value IN (?,?))`
|
|
2838
|
+
* - PostgreSQL: `"col" && ARRAY[$1,$2]::text[]`
|
|
2839
|
+
*/
|
|
2840
|
+
textArrayContains(column: string, paramCount: number, paramStartIndex: number): {
|
|
2841
|
+
sql: string;
|
|
2842
|
+
values: unknown[];
|
|
2843
|
+
};
|
|
2844
|
+
/**
|
|
2845
|
+
* LIKE expression for string prefix / contains search.
|
|
2846
|
+
* - SQLite: `"col" LIKE ? ESCAPE '\'`
|
|
2847
|
+
* - PostgreSQL: `"col" LIKE $1`
|
|
2848
|
+
*/
|
|
2849
|
+
like(column: string, paramIndex: number): string;
|
|
2850
|
+
/**
|
|
2851
|
+
* LIMIT / OFFSET clause.
|
|
2852
|
+
* - SQLite: `LIMIT ? OFFSET ?`
|
|
2853
|
+
* - PostgreSQL: `LIMIT $1 OFFSET $2`
|
|
2854
|
+
*/
|
|
2855
|
+
limitOffset(paramStartIndex: number): {
|
|
2856
|
+
sql: string;
|
|
2857
|
+
};
|
|
2858
|
+
/**
|
|
2859
|
+
* TEXT[] array literal for INSERT/UPDATE values.
|
|
2860
|
+
* - SQLite: JSON array string, e.g. `'["system|code","|code"]'`
|
|
2861
|
+
* - PostgreSQL: `ARRAY['system|code','|code']::text[]`
|
|
2862
|
+
*/
|
|
2863
|
+
arrayLiteral(values: string[]): string;
|
|
2864
|
+
/**
|
|
2865
|
+
* Timestamp column type.
|
|
2866
|
+
* - SQLite: `TEXT` (ISO 8601 strings)
|
|
2867
|
+
* - PostgreSQL: `TIMESTAMPTZ`
|
|
2868
|
+
*/
|
|
2869
|
+
timestampType(): string;
|
|
2870
|
+
/**
|
|
2871
|
+
* Boolean column type.
|
|
2872
|
+
* - SQLite: `INTEGER` (0/1)
|
|
2873
|
+
* - PostgreSQL: `BOOLEAN`
|
|
2874
|
+
*/
|
|
2875
|
+
booleanType(): string;
|
|
2876
|
+
/**
|
|
2877
|
+
* Array column type for TEXT arrays.
|
|
2878
|
+
* - SQLite: `TEXT` (JSON serialized)
|
|
2879
|
+
* - PostgreSQL: `TEXT[]` (native)
|
|
2880
|
+
*/
|
|
2881
|
+
textArrayType(): string;
|
|
2882
|
+
/**
|
|
2883
|
+
* UPSERT suffix for ON CONFLICT handling.
|
|
2884
|
+
* Both dialects support `ON CONFLICT ... DO UPDATE SET ...`
|
|
2885
|
+
*/
|
|
2886
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
2768
2887
|
/**
|
|
2769
|
-
*
|
|
2888
|
+
* Auto-increment primary key type.
|
|
2889
|
+
* - SQLite: `INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT`
|
|
2890
|
+
* - PostgreSQL: `SERIAL PRIMARY KEY` or `INTEGER GENERATED ALWAYS AS IDENTITY`
|
|
2770
2891
|
*/
|
|
2771
|
-
|
|
2892
|
+
autoIncrementPK(): string;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
export declare class SQLiteDialect implements SqlDialect {
|
|
2896
|
+
readonly name: "sqlite";
|
|
2897
|
+
placeholder(_index: number): string;
|
|
2898
|
+
textArrayContains(column: string, paramCount: number, _paramStartIndex: number): {
|
|
2899
|
+
sql: string;
|
|
2900
|
+
values: unknown[];
|
|
2901
|
+
};
|
|
2902
|
+
like(column: string, _paramIndex: number): string;
|
|
2903
|
+
limitOffset(_paramStartIndex: number): {
|
|
2904
|
+
sql: string;
|
|
2905
|
+
};
|
|
2906
|
+
arrayLiteral(values: string[]): string;
|
|
2907
|
+
timestampType(): string;
|
|
2908
|
+
booleanType(): string;
|
|
2909
|
+
textArrayType(): string;
|
|
2910
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
2911
|
+
autoIncrementPK(): string;
|
|
2772
2912
|
}
|
|
2773
2913
|
|
|
2774
2914
|
/**
|
|
@@ -2977,13 +3117,13 @@ export declare class TerminologyCodeRepo {
|
|
|
2977
3117
|
*/
|
|
2978
3118
|
export declare interface TransactionContext {
|
|
2979
3119
|
/** Execute a write operation within the transaction. */
|
|
2980
|
-
execute(sql: string, params?: unknown[]): {
|
|
3120
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
2981
3121
|
changes: number;
|
|
2982
|
-
}
|
|
3122
|
+
}>;
|
|
2983
3123
|
/** Execute a read query within the transaction. */
|
|
2984
|
-
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[]
|
|
3124
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
2985
3125
|
/** Execute a read query returning the first row or undefined. */
|
|
2986
|
-
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | undefined
|
|
3126
|
+
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
2987
3127
|
}
|
|
2988
3128
|
|
|
2989
3129
|
/**
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare function buildAllResourceTableSets(sdRegistry: StructureDefinitio
|
|
|
62
62
|
/**
|
|
63
63
|
* v2: Build a COUNT query using ? placeholders.
|
|
64
64
|
*/
|
|
65
|
-
export declare function buildCountSQLv2(request: SearchRequest, registry: SearchParameterRegistry): CountSQL;
|
|
65
|
+
export declare function buildCountSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): CountSQL;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* v2: DELETE all reference rows for a resource (before re-inserting on update).
|
|
@@ -244,7 +244,7 @@ export declare function buildSearchColumns(resource: FhirResource, impls: Search
|
|
|
244
244
|
* v2: Build a complete search SQL query using ? placeholders.
|
|
245
245
|
* No projectId filter. deleted = 0 (INTEGER).
|
|
246
246
|
*/
|
|
247
|
-
export declare function buildSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry): SearchSQL;
|
|
247
|
+
export declare function buildSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): SearchSQL;
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
250
|
* v2: SELECT by ID — no projectId, returns versionId + deleted.
|
|
@@ -288,7 +288,7 @@ export declare function buildSelfLink(ctx: PaginationContext): string;
|
|
|
288
288
|
* @param registry - The SearchParameterRegistry.
|
|
289
289
|
* @returns TwoPhaseSearchSQL with phase1 query and phase2 template.
|
|
290
290
|
*/
|
|
291
|
-
export declare function buildTwoPhaseSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry): TwoPhaseSearchSQL;
|
|
291
|
+
export declare function buildTwoPhaseSearchSQLv2(request: SearchRequest, registry: SearchParameterRegistry, dialect?: SqlDialect): TwoPhaseSearchSQL;
|
|
292
292
|
|
|
293
293
|
/**
|
|
294
294
|
* v2: Type-level history SELECT.
|
|
@@ -315,17 +315,16 @@ export declare function buildUpdateMainSQLv2(tableName: string, columns: Record<
|
|
|
315
315
|
/**
|
|
316
316
|
* v2: Build a complete WHERE clause from parsed search params using ? placeholders.
|
|
317
317
|
*/
|
|
318
|
-
export declare function buildWhereClauseV2(params: ParsedSearchParam[], registry: SearchParameterRegistry, resourceType: string): WhereFragment | null;
|
|
318
|
+
export declare function buildWhereClauseV2(params: ParsedSearchParam[], registry: SearchParameterRegistry, resourceType: string, dialect?: SqlDialect): WhereFragment | null;
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
|
-
* v2: Build a WHERE clause fragment using ? placeholders
|
|
321
|
+
* v2: Build a WHERE clause fragment using ? placeholders.
|
|
322
322
|
*
|
|
323
|
-
* Dispatches to type-specific v2 builders.
|
|
324
|
-
* -
|
|
325
|
-
* -
|
|
326
|
-
* - Array columns use `json_each()` instead of PG array operators
|
|
323
|
+
* Dispatches to type-specific v2 builders. Dialect-aware:
|
|
324
|
+
* - SQLite: json_each() for array columns
|
|
325
|
+
* - PostgreSQL: native ARRAY operators
|
|
327
326
|
*/
|
|
328
|
-
export declare function buildWhereFragmentV2(impl: SearchParameterImpl, param: ParsedSearchParam): WhereFragment | null;
|
|
327
|
+
export declare function buildWhereFragmentV2(impl: SearchParameterImpl, param: ParsedSearchParam, dialect?: SqlDialect): WhereFragment | null;
|
|
329
328
|
|
|
330
329
|
declare interface BundleLink {
|
|
331
330
|
relation: string;
|
|
@@ -557,7 +556,9 @@ declare type EvictionPolicy = 'lru' | 'fifo' | 'ttl-only';
|
|
|
557
556
|
* - `deleted` is number (0/1), not boolean
|
|
558
557
|
* - No `_include` / `_revinclude` in this MVP (can be added)
|
|
559
558
|
*/
|
|
560
|
-
export declare function executeSearch(adapter: StorageAdapter, request: SearchRequest, registry: SearchParameterRegistry, options?: SearchOptions_2
|
|
559
|
+
export declare function executeSearch(adapter: StorageAdapter, request: SearchRequest, registry: SearchParameterRegistry, options?: SearchOptions_2 & {
|
|
560
|
+
dialect?: SqlDialect;
|
|
561
|
+
}): Promise<SearchResult_2>;
|
|
561
562
|
|
|
562
563
|
/**
|
|
563
564
|
* A reference extracted from a FHIR resource.
|
|
@@ -1656,6 +1657,30 @@ export declare interface PersistedResource extends FhirResource {
|
|
|
1656
1657
|
};
|
|
1657
1658
|
}
|
|
1658
1659
|
|
|
1660
|
+
/**
|
|
1661
|
+
* Minimal interface that pg.PoolClient satisfies.
|
|
1662
|
+
*/
|
|
1663
|
+
declare interface PgClientLike {
|
|
1664
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1665
|
+
rows: Record<string, unknown>[];
|
|
1666
|
+
rowCount: number | null;
|
|
1667
|
+
}>;
|
|
1668
|
+
release(): void;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* Minimal interface that pg.Pool satisfies.
|
|
1673
|
+
* Allows PostgresAdapter to work without importing `pg`.
|
|
1674
|
+
*/
|
|
1675
|
+
declare interface PgPoolLike {
|
|
1676
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1677
|
+
rows: Record<string, unknown>[];
|
|
1678
|
+
rowCount: number | null;
|
|
1679
|
+
}>;
|
|
1680
|
+
connect(): Promise<PgClientLike>;
|
|
1681
|
+
end(): Promise<void>;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1659
1684
|
/**
|
|
1660
1685
|
* Plan and optimize a search request.
|
|
1661
1686
|
*
|
|
@@ -1680,6 +1705,41 @@ export declare const PLATFORM_RESOURCE_TYPES: ReadonlySet<string>;
|
|
|
1680
1705
|
|
|
1681
1706
|
export declare const PLATFORM_SEARCH_PARAMETERS: SearchParameterResource[];
|
|
1682
1707
|
|
|
1708
|
+
export declare class PostgresAdapter implements StorageAdapter {
|
|
1709
|
+
private readonly pool;
|
|
1710
|
+
private closed;
|
|
1711
|
+
constructor(pool: PgPoolLike);
|
|
1712
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
1713
|
+
changes: number;
|
|
1714
|
+
}>;
|
|
1715
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
1716
|
+
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
1717
|
+
queryStream<T = Record<string, unknown>>(sql: string, params?: unknown[]): AsyncIterable<T>;
|
|
1718
|
+
prepare<T = Record<string, unknown>>(_sql: string): PreparedStatement<T>;
|
|
1719
|
+
transaction<R>(fn: (tx: TransactionContext) => R | Promise<R>): Promise<R>;
|
|
1720
|
+
close(): Promise<void>;
|
|
1721
|
+
private ensureNotClosed;
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
export declare class PostgresDialect implements SqlDialect {
|
|
1725
|
+
readonly name: "postgres";
|
|
1726
|
+
placeholder(index: number): string;
|
|
1727
|
+
textArrayContains(column: string, paramCount: number, paramStartIndex: number): {
|
|
1728
|
+
sql: string;
|
|
1729
|
+
values: unknown[];
|
|
1730
|
+
};
|
|
1731
|
+
like(column: string, paramIndex: number): string;
|
|
1732
|
+
limitOffset(paramStartIndex: number): {
|
|
1733
|
+
sql: string;
|
|
1734
|
+
};
|
|
1735
|
+
arrayLiteral(values: string[]): string;
|
|
1736
|
+
timestampType(): string;
|
|
1737
|
+
booleanType(): string;
|
|
1738
|
+
textArrayType(): string;
|
|
1739
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
1740
|
+
autoIncrementPK(): string;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1683
1743
|
/**
|
|
1684
1744
|
* FHIR search parameter types that support prefixes.
|
|
1685
1745
|
*/
|
|
@@ -2745,30 +2805,110 @@ export declare function splitSearchValues(value: string): string[];
|
|
|
2745
2805
|
*/
|
|
2746
2806
|
export declare type SqlColumnType = 'TEXT' | 'TEXT[]' | 'BOOLEAN' | 'INTEGER' | 'BIGINT' | 'TIMESTAMPTZ' | 'TIMESTAMPTZ[]' | 'DATE' | 'DATE[]' | 'NUMERIC' | 'DOUBLE PRECISION' | 'DOUBLE PRECISION[]' | 'REAL';
|
|
2747
2807
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2808
|
+
/**
|
|
2809
|
+
* SqlDialect — Database-Specific SQL Generation Strategy
|
|
2810
|
+
*
|
|
2811
|
+
* Encapsulates syntax differences between SQLite and PostgreSQL.
|
|
2812
|
+
* Injected into query builders (WhereBuilder, SearchSQLBuilder)
|
|
2813
|
+
* so business logic remains dialect-agnostic.
|
|
2814
|
+
*
|
|
2815
|
+
* v2 upgrade: New file. v1 hardcoded PostgreSQL syntax everywhere.
|
|
2816
|
+
*
|
|
2817
|
+
* @module fhir-persistence/db
|
|
2818
|
+
*/
|
|
2819
|
+
/**
|
|
2820
|
+
* Strategy object for generating database-specific SQL fragments.
|
|
2821
|
+
*
|
|
2822
|
+
* Each adapter implementation provides a matching dialect instance.
|
|
2823
|
+
*/
|
|
2824
|
+
export declare interface SqlDialect {
|
|
2825
|
+
/** Dialect identifier for branching where needed. */
|
|
2826
|
+
readonly name: 'sqlite' | 'postgres';
|
|
2752
2827
|
/**
|
|
2753
|
-
*
|
|
2754
|
-
*
|
|
2828
|
+
* Positional parameter placeholder.
|
|
2829
|
+
* - SQLite: always `?` (index ignored)
|
|
2830
|
+
* - PostgreSQL: `$1`, `$2`, ... (1-based index)
|
|
2755
2831
|
*/
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2832
|
+
placeholder(index: number): string;
|
|
2833
|
+
/**
|
|
2834
|
+
* Generate a TEXT[] array-contains check.
|
|
2835
|
+
*
|
|
2836
|
+
* Checks if any element of a TEXT[] column matches any of the given values.
|
|
2837
|
+
* - SQLite: `EXISTS (SELECT 1 FROM json_each("col") WHERE value IN (?,?))`
|
|
2838
|
+
* - PostgreSQL: `"col" && ARRAY[$1,$2]::text[]`
|
|
2839
|
+
*/
|
|
2840
|
+
textArrayContains(column: string, paramCount: number, paramStartIndex: number): {
|
|
2841
|
+
sql: string;
|
|
2842
|
+
values: unknown[];
|
|
2843
|
+
};
|
|
2844
|
+
/**
|
|
2845
|
+
* LIKE expression for string prefix / contains search.
|
|
2846
|
+
* - SQLite: `"col" LIKE ? ESCAPE '\'`
|
|
2847
|
+
* - PostgreSQL: `"col" LIKE $1`
|
|
2848
|
+
*/
|
|
2849
|
+
like(column: string, paramIndex: number): string;
|
|
2850
|
+
/**
|
|
2851
|
+
* LIMIT / OFFSET clause.
|
|
2852
|
+
* - SQLite: `LIMIT ? OFFSET ?`
|
|
2853
|
+
* - PostgreSQL: `LIMIT $1 OFFSET $2`
|
|
2854
|
+
*/
|
|
2855
|
+
limitOffset(paramStartIndex: number): {
|
|
2856
|
+
sql: string;
|
|
2857
|
+
};
|
|
2858
|
+
/**
|
|
2859
|
+
* TEXT[] array literal for INSERT/UPDATE values.
|
|
2860
|
+
* - SQLite: JSON array string, e.g. `'["system|code","|code"]'`
|
|
2861
|
+
* - PostgreSQL: `ARRAY['system|code','|code']::text[]`
|
|
2862
|
+
*/
|
|
2863
|
+
arrayLiteral(values: string[]): string;
|
|
2864
|
+
/**
|
|
2865
|
+
* Timestamp column type.
|
|
2866
|
+
* - SQLite: `TEXT` (ISO 8601 strings)
|
|
2867
|
+
* - PostgreSQL: `TIMESTAMPTZ`
|
|
2868
|
+
*/
|
|
2869
|
+
timestampType(): string;
|
|
2870
|
+
/**
|
|
2871
|
+
* Boolean column type.
|
|
2872
|
+
* - SQLite: `INTEGER` (0/1)
|
|
2873
|
+
* - PostgreSQL: `BOOLEAN`
|
|
2874
|
+
*/
|
|
2875
|
+
booleanType(): string;
|
|
2876
|
+
/**
|
|
2877
|
+
* Array column type for TEXT arrays.
|
|
2878
|
+
* - SQLite: `TEXT` (JSON serialized)
|
|
2879
|
+
* - PostgreSQL: `TEXT[]` (native)
|
|
2880
|
+
*/
|
|
2881
|
+
textArrayType(): string;
|
|
2882
|
+
/**
|
|
2883
|
+
* UPSERT suffix for ON CONFLICT handling.
|
|
2884
|
+
* Both dialects support `ON CONFLICT ... DO UPDATE SET ...`
|
|
2885
|
+
*/
|
|
2886
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
2768
2887
|
/**
|
|
2769
|
-
*
|
|
2888
|
+
* Auto-increment primary key type.
|
|
2889
|
+
* - SQLite: `INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT`
|
|
2890
|
+
* - PostgreSQL: `SERIAL PRIMARY KEY` or `INTEGER GENERATED ALWAYS AS IDENTITY`
|
|
2770
2891
|
*/
|
|
2771
|
-
|
|
2892
|
+
autoIncrementPK(): string;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
export declare class SQLiteDialect implements SqlDialect {
|
|
2896
|
+
readonly name: "sqlite";
|
|
2897
|
+
placeholder(_index: number): string;
|
|
2898
|
+
textArrayContains(column: string, paramCount: number, _paramStartIndex: number): {
|
|
2899
|
+
sql: string;
|
|
2900
|
+
values: unknown[];
|
|
2901
|
+
};
|
|
2902
|
+
like(column: string, _paramIndex: number): string;
|
|
2903
|
+
limitOffset(_paramStartIndex: number): {
|
|
2904
|
+
sql: string;
|
|
2905
|
+
};
|
|
2906
|
+
arrayLiteral(values: string[]): string;
|
|
2907
|
+
timestampType(): string;
|
|
2908
|
+
booleanType(): string;
|
|
2909
|
+
textArrayType(): string;
|
|
2910
|
+
upsertSuffix(conflictColumn: string, updateColumns: string[]): string;
|
|
2911
|
+
autoIncrementPK(): string;
|
|
2772
2912
|
}
|
|
2773
2913
|
|
|
2774
2914
|
/**
|
|
@@ -2977,13 +3117,13 @@ export declare class TerminologyCodeRepo {
|
|
|
2977
3117
|
*/
|
|
2978
3118
|
export declare interface TransactionContext {
|
|
2979
3119
|
/** Execute a write operation within the transaction. */
|
|
2980
|
-
execute(sql: string, params?: unknown[]): {
|
|
3120
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
2981
3121
|
changes: number;
|
|
2982
|
-
}
|
|
3122
|
+
}>;
|
|
2983
3123
|
/** Execute a read query within the transaction. */
|
|
2984
|
-
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): T[]
|
|
3124
|
+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
2985
3125
|
/** Execute a read query returning the first row or undefined. */
|
|
2986
|
-
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): T | undefined
|
|
3126
|
+
queryOne<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | undefined>;
|
|
2987
3127
|
}
|
|
2988
3128
|
|
|
2989
3129
|
/**
|