linkgress-orm 0.0.1
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 +196 -0
- package/dist/database/database-client.interface.d.ts +45 -0
- package/dist/database/database-client.interface.d.ts.map +1 -0
- package/dist/database/database-client.interface.js +20 -0
- package/dist/database/database-client.interface.js.map +1 -0
- package/dist/database/index.d.ts +5 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +10 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/pg-client.d.ts +30 -0
- package/dist/database/pg-client.d.ts.map +1 -0
- package/dist/database/pg-client.js +76 -0
- package/dist/database/pg-client.js.map +1 -0
- package/dist/database/postgres-client.d.ts +44 -0
- package/dist/database/postgres-client.d.ts.map +1 -0
- package/dist/database/postgres-client.js +111 -0
- package/dist/database/postgres-client.js.map +1 -0
- package/dist/database/types.d.ts +200 -0
- package/dist/database/types.d.ts.map +1 -0
- package/dist/database/types.js +8 -0
- package/dist/database/types.js.map +1 -0
- package/dist/entity/base-entity.d.ts +21 -0
- package/dist/entity/base-entity.d.ts.map +1 -0
- package/dist/entity/base-entity.js +27 -0
- package/dist/entity/base-entity.js.map +1 -0
- package/dist/entity/db-column.d.ts +61 -0
- package/dist/entity/db-column.d.ts.map +1 -0
- package/dist/entity/db-column.js +35 -0
- package/dist/entity/db-column.js.map +1 -0
- package/dist/entity/db-context.d.ts +665 -0
- package/dist/entity/db-context.d.ts.map +1 -0
- package/dist/entity/db-context.js +1463 -0
- package/dist/entity/db-context.js.map +1 -0
- package/dist/entity/entity-base.d.ts +76 -0
- package/dist/entity/entity-base.d.ts.map +1 -0
- package/dist/entity/entity-base.js +42 -0
- package/dist/entity/entity-base.js.map +1 -0
- package/dist/entity/entity-builder.d.ts +171 -0
- package/dist/entity/entity-builder.d.ts.map +1 -0
- package/dist/entity/entity-builder.js +376 -0
- package/dist/entity/entity-builder.js.map +1 -0
- package/dist/entity/model-config.d.ts +18 -0
- package/dist/entity/model-config.d.ts.map +1 -0
- package/dist/entity/model-config.js +157 -0
- package/dist/entity/model-config.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +142 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/db-schema-manager.d.ts +228 -0
- package/dist/migration/db-schema-manager.d.ts.map +1 -0
- package/dist/migration/db-schema-manager.js +1055 -0
- package/dist/migration/db-schema-manager.js.map +1 -0
- package/dist/migration/enum-migrator.d.ts +29 -0
- package/dist/migration/enum-migrator.d.ts.map +1 -0
- package/dist/migration/enum-migrator.js +137 -0
- package/dist/migration/enum-migrator.js.map +1 -0
- package/dist/query/collection-strategy.factory.d.ts +16 -0
- package/dist/query/collection-strategy.factory.d.ts.map +1 -0
- package/dist/query/collection-strategy.factory.js +37 -0
- package/dist/query/collection-strategy.factory.js.map +1 -0
- package/dist/query/collection-strategy.interface.d.ts +146 -0
- package/dist/query/collection-strategy.interface.d.ts.map +1 -0
- package/dist/query/collection-strategy.interface.js +3 -0
- package/dist/query/collection-strategy.interface.js.map +1 -0
- package/dist/query/conditions.d.ts +222 -0
- package/dist/query/conditions.d.ts.map +1 -0
- package/dist/query/conditions.js +446 -0
- package/dist/query/conditions.js.map +1 -0
- package/dist/query/cte-builder.d.ts +95 -0
- package/dist/query/cte-builder.d.ts.map +1 -0
- package/dist/query/cte-builder.js +172 -0
- package/dist/query/cte-builder.js.map +1 -0
- package/dist/query/grouped-query.d.ts +186 -0
- package/dist/query/grouped-query.d.ts.map +1 -0
- package/dist/query/grouped-query.js +588 -0
- package/dist/query/grouped-query.js.map +1 -0
- package/dist/query/join-builder.d.ts +106 -0
- package/dist/query/join-builder.d.ts.map +1 -0
- package/dist/query/join-builder.js +275 -0
- package/dist/query/join-builder.js.map +1 -0
- package/dist/query/query-builder.d.ts +543 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +2649 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/strategies/jsonb-collection-strategy.d.ts +51 -0
- package/dist/query/strategies/jsonb-collection-strategy.d.ts.map +1 -0
- package/dist/query/strategies/jsonb-collection-strategy.js +210 -0
- package/dist/query/strategies/jsonb-collection-strategy.js.map +1 -0
- package/dist/query/strategies/temptable-collection-strategy.d.ts +95 -0
- package/dist/query/strategies/temptable-collection-strategy.d.ts.map +1 -0
- package/dist/query/strategies/temptable-collection-strategy.js +456 -0
- package/dist/query/strategies/temptable-collection-strategy.js.map +1 -0
- package/dist/query/subquery.d.ts +152 -0
- package/dist/query/subquery.d.ts.map +1 -0
- package/dist/query/subquery.js +206 -0
- package/dist/query/subquery.js.map +1 -0
- package/dist/schema/column-builder.d.ts +127 -0
- package/dist/schema/column-builder.d.ts.map +1 -0
- package/dist/schema/column-builder.js +184 -0
- package/dist/schema/column-builder.js.map +1 -0
- package/dist/schema/inference.d.ts +26 -0
- package/dist/schema/inference.d.ts.map +1 -0
- package/dist/schema/inference.js +3 -0
- package/dist/schema/inference.js.map +1 -0
- package/dist/schema/navigation.d.ts +215 -0
- package/dist/schema/navigation.d.ts.map +1 -0
- package/dist/schema/navigation.js +233 -0
- package/dist/schema/navigation.js.map +1 -0
- package/dist/schema/row-type.d.ts +26 -0
- package/dist/schema/row-type.d.ts.map +1 -0
- package/dist/schema/row-type.js +3 -0
- package/dist/schema/row-type.js.map +1 -0
- package/dist/schema/sequence-builder.d.ts +87 -0
- package/dist/schema/sequence-builder.d.ts.map +1 -0
- package/dist/schema/sequence-builder.js +123 -0
- package/dist/schema/sequence-builder.js.map +1 -0
- package/dist/schema/table-builder.d.ts +122 -0
- package/dist/schema/table-builder.d.ts.map +1 -0
- package/dist/schema/table-builder.js +132 -0
- package/dist/schema/table-builder.js.map +1 -0
- package/dist/schema/typed-schema.d.ts +22 -0
- package/dist/schema/typed-schema.d.ts.map +1 -0
- package/dist/schema/typed-schema.js +28 -0
- package/dist/schema/typed-schema.js.map +1 -0
- package/dist/types/column-types.d.ts +20 -0
- package/dist/types/column-types.d.ts.map +1 -0
- package/dist/types/column-types.js +14 -0
- package/dist/types/column-types.js.map +1 -0
- package/dist/types/custom-types.d.ts +85 -0
- package/dist/types/custom-types.d.ts.map +1 -0
- package/dist/types/custom-types.js +132 -0
- package/dist/types/custom-types.js.map +1 -0
- package/dist/types/enum-builder.d.ts +31 -0
- package/dist/types/enum-builder.d.ts.map +1 -0
- package/dist/types/enum-builder.js +46 -0
- package/dist/types/enum-builder.js.map +1 -0
- package/dist/types/metadata.d.ts +67 -0
- package/dist/types/metadata.d.ts.map +1 -0
- package/dist/types/metadata.js +57 -0
- package/dist/types/metadata.js.map +1 -0
- package/dist/types/type-mapper.d.ts +49 -0
- package/dist/types/type-mapper.d.ts.map +1 -0
- package/dist/types/type-mapper.js +49 -0
- package/dist/types/type-mapper.js.map +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Linkgress ORM Contributors
|
|
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
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Linkgress ORM
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/linkgress-orm)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://www.postgresql.org/)
|
|
7
|
+
|
|
8
|
+
A type-safe ORM for PostgreSQL and TypeScript with automatic type inference and powerful query capabilities.
|
|
9
|
+
|
|
10
|
+
**LINQ-Inspired Query Syntax:** The query API is designed to feel familiar to developers coming from C# LINQ, with chainable methods like `select()`, `where()`, `orderBy()`, and `groupBy()`. You also get magic SQL string interpolation for when you need raw SQL power without sacrificing type safety.
|
|
11
|
+
|
|
12
|
+
**PostgreSQL-First Philosophy:** While other ORMs aim high and try to support all platforms, Linkgress is built exclusively for PostgreSQL. This allows it to leverage PostgreSQL's advanced features to the maximum—particularly in how collections and aggregations are retrieved using CTEs, JSON aggregations, and native PostgreSQL optimizations.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Entity-First Approach** - Define entities with `DbColumn<T>`, no decorators needed
|
|
17
|
+
- **Fluent Configuration API** - Intuitive `DbContext` pattern with method chaining
|
|
18
|
+
- **Automatic Type Inference** - Full TypeScript support without manual type annotations
|
|
19
|
+
- **Nested Collection Queries** - Query one-to-many relationships with automatic CTE optimization
|
|
20
|
+
- **Type-Safe Aggregations** - `count()`, `sum()`, `max()`, `min()` return proper types
|
|
21
|
+
- **Powerful Filtering** - Type-checked query conditions
|
|
22
|
+
- **Transaction Support** - Safe, type-checked transactions
|
|
23
|
+
- **Multiple Clients** - Works with both `pg` and `postgres` npm packages
|
|
24
|
+
|
|
25
|
+
## Table of Contents
|
|
26
|
+
|
|
27
|
+
- [Quick Start](#quick-start)
|
|
28
|
+
- [Features](#features)
|
|
29
|
+
- [Documentation](#documentation)
|
|
30
|
+
- [Requirements](#requirements)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
- [Support](#support)
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install linkgress-orm postgres
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
See [Installation Guide](./docs/installation.md) for detailed setup.
|
|
44
|
+
|
|
45
|
+
### Define Entities
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { DbEntity, DbColumn } from 'linkgress-orm';
|
|
49
|
+
|
|
50
|
+
export class User extends DbEntity {
|
|
51
|
+
id!: DbColumn<number>;
|
|
52
|
+
username!: DbColumn<string>;
|
|
53
|
+
email!: DbColumn<string>;
|
|
54
|
+
posts?: Post[]; // Navigation property
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class Post extends DbEntity {
|
|
58
|
+
id!: DbColumn<number>;
|
|
59
|
+
title!: DbColumn<string>;
|
|
60
|
+
userId!: DbColumn<number>;
|
|
61
|
+
views!: DbColumn<number>;
|
|
62
|
+
user?: User; // Navigation property
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Create DbContext
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { DbContext, DbEntityTable, DbModelConfig, integer, varchar } from 'linkgress-orm';
|
|
70
|
+
|
|
71
|
+
export class AppDatabase extends DbContext {
|
|
72
|
+
get users(): DbEntityTable<User> {
|
|
73
|
+
return this.table(User);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get posts(): DbEntityTable<Post> {
|
|
77
|
+
return this.table(Post);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected override setupModel(model: DbModelConfig): void {
|
|
81
|
+
model.entity(User, entity => {
|
|
82
|
+
entity.toTable('users');
|
|
83
|
+
entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'users_id_seq' }));
|
|
84
|
+
entity.property(e => e.username).hasType(varchar('username', 100)).isRequired();
|
|
85
|
+
entity.property(e => e.email).hasType(varchar('email', 255)).isRequired();
|
|
86
|
+
|
|
87
|
+
entity.hasMany(e => e.posts, () => Post)
|
|
88
|
+
.withForeignKey(p => p.userId)
|
|
89
|
+
.withPrincipalKey(u => u.id);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
model.entity(Post, entity => {
|
|
93
|
+
entity.toTable('posts');
|
|
94
|
+
entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'posts_id_seq' }));
|
|
95
|
+
entity.property(e => e.title).hasType(varchar('title', 200)).isRequired();
|
|
96
|
+
entity.property(e => e.userId).hasType(integer('user_id')).isRequired();
|
|
97
|
+
entity.property(e => e.views).hasType(integer('views')).hasDefaultValue(0);
|
|
98
|
+
|
|
99
|
+
entity.hasOne(e => e.user, () => User)
|
|
100
|
+
.withForeignKey(p => p.userId)
|
|
101
|
+
.withPrincipalKey(u => u.id);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Query with Type Safety
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { eq, gt } from 'linkgress-orm';
|
|
111
|
+
import { PostgresClient } from 'linkgress-orm';
|
|
112
|
+
|
|
113
|
+
// Create a database client with connection pooling
|
|
114
|
+
const client = new PostgresClient('postgres://user:pass@localhost/db');
|
|
115
|
+
|
|
116
|
+
// Create a DbContext instance - reuse this across your application!
|
|
117
|
+
const db = new AppDatabase(client);
|
|
118
|
+
|
|
119
|
+
// Create schema
|
|
120
|
+
await db.ensureCreated();
|
|
121
|
+
|
|
122
|
+
// Insert
|
|
123
|
+
await db.users.insert({ username: 'alice', email: 'alice@example.com' });
|
|
124
|
+
|
|
125
|
+
// Query with filters
|
|
126
|
+
const activeUsers = await db.users
|
|
127
|
+
.where(u => eq(u.username, 'alice'))
|
|
128
|
+
.toList();
|
|
129
|
+
|
|
130
|
+
// Nested collection query with aggregations
|
|
131
|
+
const usersWithStats = await db.users
|
|
132
|
+
.select(u => ({
|
|
133
|
+
username: u.username,
|
|
134
|
+
postCount: u.posts.count(), // Automatic type inference - no casting!
|
|
135
|
+
maxViews: u.posts.max(p => p.views), // Returns number | null
|
|
136
|
+
posts: u.posts
|
|
137
|
+
.select(p => ({ title: p.title, views: p.views }))
|
|
138
|
+
.where(p => gt(p.views, 10))
|
|
139
|
+
.toList('posts'),
|
|
140
|
+
}))
|
|
141
|
+
.toList();
|
|
142
|
+
|
|
143
|
+
// Note: Only call dispose() when shutting down your application
|
|
144
|
+
// For long-running apps (servers), keep the db instance alive
|
|
145
|
+
// and dispose on process exit (see Connection Lifecycle docs)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Result is fully typed:**
|
|
149
|
+
```typescript
|
|
150
|
+
Array<{
|
|
151
|
+
username: string;
|
|
152
|
+
postCount: number;
|
|
153
|
+
maxViews: number | null;
|
|
154
|
+
posts: Array<{ title: string; views: number }>;
|
|
155
|
+
}>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Documentation
|
|
159
|
+
|
|
160
|
+
### Getting Started
|
|
161
|
+
- **[Getting Started Guide](./docs/getting-started.md)** - Complete walkthrough for beginners
|
|
162
|
+
- **[Installation](./docs/installation.md)** - Setup and installation instructions
|
|
163
|
+
- **[Database Clients](./docs/database-clients.md)** - Choose between `pg` and `postgres`, connection pooling, and lifecycle management
|
|
164
|
+
|
|
165
|
+
### Guides
|
|
166
|
+
- **[Schema Configuration](./docs/guides/schema-configuration.md)** - Entity configuration, relationships, and indexes
|
|
167
|
+
- **[Querying](./docs/guides/querying.md)** - Query data with type-safe filters, joins, aggregations, and more
|
|
168
|
+
- **[Insert/Update/Upsert/BULK](./docs/guides/insert-update-guide.md)** - Insert, update, delete, and bulk operations
|
|
169
|
+
|
|
170
|
+
### Advanced
|
|
171
|
+
- **[Collection Strategies](./docs/collection-strategies.md)** - JSONB vs temp table strategies, performance optimization, and multi-statement execution
|
|
172
|
+
- **[Subqueries](./docs/guides/subquery-guide.md)** - Using subqueries in your queries
|
|
173
|
+
- **[Custom Types](./docs/guides/schema-configuration.md#custom-types)** - Create custom type mappers
|
|
174
|
+
|
|
175
|
+
## Requirements
|
|
176
|
+
|
|
177
|
+
- Node.js 16+
|
|
178
|
+
- TypeScript 5.0+
|
|
179
|
+
- PostgreSQL 12+
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
188
|
+
|
|
189
|
+
## Support
|
|
190
|
+
|
|
191
|
+
- **[GitHub Issues](https://github.com/brunolau/linkgress-orm/issues)** - Report bugs or request features
|
|
192
|
+
- **[Discussions](https://github.com/brunolau/linkgress-orm/discussions)** - Ask questions and share ideas
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
Crafted with ❤️ for developers who love type safety and clean APIs.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database-agnostic query result interface
|
|
3
|
+
*/
|
|
4
|
+
export interface QueryResult<T = any> {
|
|
5
|
+
rows: T[];
|
|
6
|
+
rowCount: number | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Database-agnostic pooled client/connection interface
|
|
10
|
+
* Represents a single connection from the pool for transactions
|
|
11
|
+
*/
|
|
12
|
+
export interface PooledConnection {
|
|
13
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
14
|
+
release(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base database client interface that all drivers must implement
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class DatabaseClient {
|
|
20
|
+
/**
|
|
21
|
+
* Execute a query with optional parameters
|
|
22
|
+
*/
|
|
23
|
+
abstract query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Get a connection from the pool for transactions
|
|
26
|
+
*/
|
|
27
|
+
abstract connect(): Promise<PooledConnection>;
|
|
28
|
+
/**
|
|
29
|
+
* Close the connection pool
|
|
30
|
+
*/
|
|
31
|
+
abstract end(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the driver name (postgres, pg, mysql, etc.)
|
|
34
|
+
*/
|
|
35
|
+
abstract getDriverName(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Check if the driver supports executing multiple SQL statements in a single query
|
|
38
|
+
* and returning multiple result sets.
|
|
39
|
+
*
|
|
40
|
+
* PostgreSQL drivers (pg, postgres) support this feature.
|
|
41
|
+
* Default: false for safety
|
|
42
|
+
*/
|
|
43
|
+
supportsMultiStatementQueries(): boolean;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=database-client.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-client.interface.d.ts","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,8BAAsB,cAAc;IAClC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAE7E;;OAEG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAE7C;;OAEG;IACH,QAAQ,CAAC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,aAAa,IAAI,MAAM;IAEhC;;;;;;OAMG;IACH,6BAA6B,IAAI,OAAO;CAGzC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base database client interface that all drivers must implement
|
|
6
|
+
*/
|
|
7
|
+
class DatabaseClient {
|
|
8
|
+
/**
|
|
9
|
+
* Check if the driver supports executing multiple SQL statements in a single query
|
|
10
|
+
* and returning multiple result sets.
|
|
11
|
+
*
|
|
12
|
+
* PostgreSQL drivers (pg, postgres) support this feature.
|
|
13
|
+
* Default: false for safety
|
|
14
|
+
*/
|
|
15
|
+
supportsMultiStatementQueries() {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DatabaseClient = DatabaseClient;
|
|
20
|
+
//# sourceMappingURL=database-client.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-client.interface.js","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":";;;AAiBA;;GAEG;AACH,MAAsB,cAAc;IAqBlC;;;;;;OAMG;IACH,6BAA6B;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA/BD,wCA+BC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DatabaseClient, PooledConnection, QueryResult } from './database-client.interface';
|
|
2
|
+
export { PostgresClient } from './postgres-client';
|
|
3
|
+
export { PgClient } from './pg-client';
|
|
4
|
+
export type { PoolConfig, PostgresOptions } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PgClient = exports.PostgresClient = exports.DatabaseClient = void 0;
|
|
4
|
+
var database_client_interface_1 = require("./database-client.interface");
|
|
5
|
+
Object.defineProperty(exports, "DatabaseClient", { enumerable: true, get: function () { return database_client_interface_1.DatabaseClient; } });
|
|
6
|
+
var postgres_client_1 = require("./postgres-client");
|
|
7
|
+
Object.defineProperty(exports, "PostgresClient", { enumerable: true, get: function () { return postgres_client_1.PostgresClient; } });
|
|
8
|
+
var pg_client_1 = require("./pg-client");
|
|
9
|
+
Object.defineProperty(exports, "PgClient", { enumerable: true, get: function () { return pg_client_1.PgClient; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;AAAA,yEAA4F;AAAnF,2HAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DatabaseClient, PooledConnection, QueryResult } from './database-client.interface';
|
|
2
|
+
import type { PoolConfig } from './types';
|
|
3
|
+
type Pool = any;
|
|
4
|
+
/**
|
|
5
|
+
* DatabaseClient implementation for the 'pg' library
|
|
6
|
+
* @see https://node-postgres.com/
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This requires the 'pg' package to be installed:
|
|
9
|
+
* npm install pg
|
|
10
|
+
*/
|
|
11
|
+
export declare class PgClient extends DatabaseClient {
|
|
12
|
+
private pool;
|
|
13
|
+
constructor(config: PoolConfig);
|
|
14
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
15
|
+
connect(): Promise<PooledConnection>;
|
|
16
|
+
end(): Promise<void>;
|
|
17
|
+
getDriverName(): string;
|
|
18
|
+
/**
|
|
19
|
+
* pg library does NOT support retrieving ALL result sets from multi-statement queries
|
|
20
|
+
* It only returns the last result, making it unsuitable for the fully optimized approach
|
|
21
|
+
* Use PostgresClient (postgres library) for true single-roundtrip multi-statement support
|
|
22
|
+
*/
|
|
23
|
+
supportsMultiStatementQueries(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get access to the underlying pg Pool for advanced use cases
|
|
26
|
+
*/
|
|
27
|
+
getPool(): Pool;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=pg-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-client.d.ts","sourceRoot":"","sources":["../../src/database/pg-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,KAAK,IAAI,GAAG,GAAG,CAAC;AAuBhB;;;;;;GAMG;AACH,qBAAa,QAAS,SAAQ,cAAc;IAC1C,OAAO,CAAC,IAAI,CAAO;gBAEP,MAAM,EAAE,UAAU;IAcxB,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASpE,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKpC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,aAAa,IAAI,MAAM;IAIvB;;;;OAIG;IACH,6BAA6B,IAAI,OAAO;IAIxC;;OAEG;IACH,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PgClient = void 0;
|
|
4
|
+
const database_client_interface_1 = require("./database-client.interface");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper for the pooled connection from pg library
|
|
7
|
+
*/
|
|
8
|
+
class PgPooledConnection {
|
|
9
|
+
constructor(client) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
async query(sql, params) {
|
|
13
|
+
const result = await this.client.query(sql, params);
|
|
14
|
+
return {
|
|
15
|
+
rows: result.rows,
|
|
16
|
+
rowCount: result.rowCount,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
release() {
|
|
20
|
+
this.client.release();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* DatabaseClient implementation for the 'pg' library
|
|
25
|
+
* @see https://node-postgres.com/
|
|
26
|
+
*
|
|
27
|
+
* NOTE: This requires the 'pg' package to be installed:
|
|
28
|
+
* npm install pg
|
|
29
|
+
*/
|
|
30
|
+
class PgClient extends database_client_interface_1.DatabaseClient {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
super();
|
|
33
|
+
try {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
35
|
+
const { Pool } = require('pg');
|
|
36
|
+
this.pool = new Pool(config);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new Error('PgClient requires the "pg" package to be installed. ' +
|
|
40
|
+
'Install it with: npm install pg');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async query(sql, params) {
|
|
44
|
+
const result = await this.pool.query(sql, params);
|
|
45
|
+
return {
|
|
46
|
+
rows: result.rows,
|
|
47
|
+
rowCount: result.rowCount,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async connect() {
|
|
51
|
+
const client = await this.pool.connect();
|
|
52
|
+
return new PgPooledConnection(client);
|
|
53
|
+
}
|
|
54
|
+
async end() {
|
|
55
|
+
await this.pool.end();
|
|
56
|
+
}
|
|
57
|
+
getDriverName() {
|
|
58
|
+
return 'pg';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* pg library does NOT support retrieving ALL result sets from multi-statement queries
|
|
62
|
+
* It only returns the last result, making it unsuitable for the fully optimized approach
|
|
63
|
+
* Use PostgresClient (postgres library) for true single-roundtrip multi-statement support
|
|
64
|
+
*/
|
|
65
|
+
supportsMultiStatementQueries() {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get access to the underlying pg Pool for advanced use cases
|
|
70
|
+
*/
|
|
71
|
+
getPool() {
|
|
72
|
+
return this.pool;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.PgClient = PgClient;
|
|
76
|
+
//# sourceMappingURL=pg-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg-client.js","sourceRoot":"","sources":["../../src/database/pg-client.ts"],"names":[],"mappings":";;;AAAA,2EAA4F;AAO5F;;GAEG;AAC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AAG;QACP,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACxB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,6BAA6B;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AAtDD,4BAsDC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DatabaseClient, PooledConnection, QueryResult } from './database-client.interface';
|
|
2
|
+
import type { PostgresOptions } from './types';
|
|
3
|
+
type Sql = any;
|
|
4
|
+
/**
|
|
5
|
+
* DatabaseClient implementation for the 'postgres' library
|
|
6
|
+
* @see https://github.com/porsager/postgres
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This requires the 'postgres' package to be installed:
|
|
9
|
+
* npm install postgres
|
|
10
|
+
*/
|
|
11
|
+
export declare class PostgresClient extends DatabaseClient {
|
|
12
|
+
private sql;
|
|
13
|
+
constructor(config: string | PostgresOptions);
|
|
14
|
+
query<T = any>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
15
|
+
connect(): Promise<PooledConnection>;
|
|
16
|
+
end(): Promise<void>;
|
|
17
|
+
getDriverName(): string;
|
|
18
|
+
/**
|
|
19
|
+
* postgres library supports multiple SQL statements using .simple() mode
|
|
20
|
+
* This allows true single round-trip optimization
|
|
21
|
+
*/
|
|
22
|
+
supportsMultiStatementQueries(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Execute a multi-statement query using the simple protocol
|
|
25
|
+
* This bypasses prepared statements and allows multiple statements
|
|
26
|
+
* WARNING: Only use with safe, validated inputs!
|
|
27
|
+
*/
|
|
28
|
+
querySimple<T = any>(sql: string): Promise<QueryResult<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Execute a multi-statement query and return ALL result sets
|
|
31
|
+
* Used for fully optimized single-query execution
|
|
32
|
+
*/
|
|
33
|
+
querySimpleMulti(sql: string): Promise<QueryResult[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Begin a transaction using postgres library's built-in transaction support
|
|
36
|
+
*/
|
|
37
|
+
begin<T>(callback: (sql: Sql) => Promise<T>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Get access to the underlying sql instance for advanced use cases
|
|
40
|
+
*/
|
|
41
|
+
getSql(): Sql;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=postgres-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-client.d.ts","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,KAAK,GAAG,GAAG,GAAG,CAAC;AAuBf;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,cAAc;IAChD,OAAO,CAAC,GAAG,CAAM;gBAEL,MAAM,EAAE,MAAM,GAAG,eAAe;IActC,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASpE,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAOpC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,aAAa,IAAI,MAAM;IAIvB;;;OAGG;IACH,6BAA6B,IAAI,OAAO;IAIxC;;;;OAIG;IACG,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAahE;;;OAGG;IACG,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAU3D;;OAEG;IACG,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI9D;;OAEG;IACH,MAAM,IAAI,GAAG;CAGd"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostgresClient = void 0;
|
|
4
|
+
const database_client_interface_1 = require("./database-client.interface");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper for the pooled connection from postgres library
|
|
7
|
+
*/
|
|
8
|
+
class PostgresPooledConnection {
|
|
9
|
+
constructor(sql) {
|
|
10
|
+
this.sql = sql;
|
|
11
|
+
}
|
|
12
|
+
async query(sql, params) {
|
|
13
|
+
const result = await this.sql.unsafe(sql, params || []);
|
|
14
|
+
return {
|
|
15
|
+
rows: result,
|
|
16
|
+
rowCount: result.count ?? null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
release() {
|
|
20
|
+
// postgres library handles connection pooling automatically
|
|
21
|
+
// No explicit release needed
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* DatabaseClient implementation for the 'postgres' library
|
|
26
|
+
* @see https://github.com/porsager/postgres
|
|
27
|
+
*
|
|
28
|
+
* NOTE: This requires the 'postgres' package to be installed:
|
|
29
|
+
* npm install postgres
|
|
30
|
+
*/
|
|
31
|
+
class PostgresClient extends database_client_interface_1.DatabaseClient {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
super();
|
|
34
|
+
try {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
36
|
+
const postgres = require('postgres');
|
|
37
|
+
this.sql = postgres(config);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error('PostgresClient requires the "postgres" package to be installed. ' +
|
|
41
|
+
'Install it with: npm install postgres');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async query(sql, params) {
|
|
45
|
+
const result = await this.sql.unsafe(sql, params || []);
|
|
46
|
+
return {
|
|
47
|
+
rows: result,
|
|
48
|
+
rowCount: result.count ?? null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async connect() {
|
|
52
|
+
// postgres library doesn't expose individual connections in the same way
|
|
53
|
+
// We'll return a wrapper that uses the same sql instance
|
|
54
|
+
// For transactions, the library handles it through sql.begin()
|
|
55
|
+
return new PostgresPooledConnection(this.sql);
|
|
56
|
+
}
|
|
57
|
+
async end() {
|
|
58
|
+
await this.sql.end();
|
|
59
|
+
}
|
|
60
|
+
getDriverName() {
|
|
61
|
+
return 'postgres';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* postgres library supports multiple SQL statements using .simple() mode
|
|
65
|
+
* This allows true single round-trip optimization
|
|
66
|
+
*/
|
|
67
|
+
supportsMultiStatementQueries() {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Execute a multi-statement query using the simple protocol
|
|
72
|
+
* This bypasses prepared statements and allows multiple statements
|
|
73
|
+
* WARNING: Only use with safe, validated inputs!
|
|
74
|
+
*/
|
|
75
|
+
async querySimple(sql) {
|
|
76
|
+
const results = await this.sql.unsafe(sql).simple();
|
|
77
|
+
// .simple() returns an array of results for each statement
|
|
78
|
+
// Return the last non-empty result (usually the SELECT)
|
|
79
|
+
const lastResult = results[results.length - 1] || [];
|
|
80
|
+
return {
|
|
81
|
+
rows: lastResult,
|
|
82
|
+
rowCount: lastResult.count ?? lastResult.length ?? null,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Execute a multi-statement query and return ALL result sets
|
|
87
|
+
* Used for fully optimized single-query execution
|
|
88
|
+
*/
|
|
89
|
+
async querySimpleMulti(sql) {
|
|
90
|
+
const results = await this.sql.unsafe(sql).simple();
|
|
91
|
+
// Convert each result set to QueryResult format
|
|
92
|
+
return results.map((result) => ({
|
|
93
|
+
rows: result,
|
|
94
|
+
rowCount: result.count ?? result.length ?? null,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Begin a transaction using postgres library's built-in transaction support
|
|
99
|
+
*/
|
|
100
|
+
async begin(callback) {
|
|
101
|
+
return await this.sql.begin(callback);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get access to the underlying sql instance for advanced use cases
|
|
105
|
+
*/
|
|
106
|
+
getSql() {
|
|
107
|
+
return this.sql;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.PostgresClient = PostgresClient;
|
|
111
|
+
//# sourceMappingURL=postgres-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-client.js","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":";;;AAAA,2EAA4F;AAM5F;;GAEG;AACH,MAAM,wBAAwB;IAC5B,YAAoB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;IAAG,CAAC;IAEhC,KAAK,CAAC,KAAK,CAAU,GAAW,EAAE,MAAc;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;QAExD,OAAO;YACL,IAAI,EAAE,MAAa;YACnB,QAAQ,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI;SAC/B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,4DAA4D;QAC5D,6BAA6B;IAC/B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,0CAAc;IAGhD,YAAY,MAAgC;QAC1C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC;YACH,8DAA8D;YAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;YACrC,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,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