@event-driven-io/pongo 0.1.1 → 0.2.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/README.md +214 -0
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -22
- package/dist/index.d.ts +87 -22
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Document, Collection as Collection$1, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId, FindOptions, FindCursor as FindCursor$1, OperationOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, CommandOperationOptions, AbstractCursorOptions, ListIndexesCursor, IndexInformationOptions, IndexDescriptionInfo, IndexDescriptionCompact, EstimatedDocumentCountOptions, CountDocumentsOptions, EnhancedOmit, Flatten, FindOneAndDeleteOptions, ModifyResult, FindOneAndReplaceOptions, FindOneAndUpdateOptions, AggregateOptions, AggregationCursor, ChangeStreamDocument, ChangeStreamOptions, ChangeStream, UnorderedBulkOperation, OrderedBulkOperation, CountOptions, ListSearchIndexesOptions, ListSearchIndexesCursor, SearchIndexDescription } from 'mongodb';
|
|
1
|
+
import { Document, Collection as Collection$1, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId as WithId$1, FindOptions, FindCursor as FindCursor$1, OperationOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, CommandOperationOptions, AbstractCursorOptions, ListIndexesCursor, IndexInformationOptions, IndexDescriptionInfo, IndexDescriptionCompact, EstimatedDocumentCountOptions, CountDocumentsOptions, EnhancedOmit, Flatten, FindOneAndDeleteOptions, ModifyResult, FindOneAndReplaceOptions, FindOneAndUpdateOptions, AggregateOptions, AggregationCursor, ChangeStreamDocument, ChangeStreamOptions, ChangeStream, UnorderedBulkOperation, OrderedBulkOperation, CountOptions, ListSearchIndexesOptions, ListSearchIndexesCursor, SearchIndexDescription } from 'mongodb';
|
|
2
2
|
import pg from 'pg';
|
|
3
3
|
|
|
4
4
|
interface PongoClient {
|
|
@@ -12,11 +12,17 @@ interface PongoDb {
|
|
|
12
12
|
interface PongoCollection<T> {
|
|
13
13
|
createCollection(): Promise<void>;
|
|
14
14
|
insertOne(document: T): Promise<PongoInsertOneResult>;
|
|
15
|
+
insertMany(documents: T[]): Promise<PongoInsertManyResult>;
|
|
15
16
|
updateOne(filter: PongoFilter<T>, update: PongoUpdate<T>): Promise<PongoUpdateResult>;
|
|
17
|
+
updateMany(filter: PongoFilter<T>, update: PongoUpdate<T>): Promise<PongoUpdateResult>;
|
|
16
18
|
deleteOne(filter: PongoFilter<T>): Promise<PongoDeleteResult>;
|
|
19
|
+
deleteMany(filter: PongoFilter<T>): Promise<PongoDeleteResult>;
|
|
17
20
|
findOne(filter: PongoFilter<T>): Promise<T | null>;
|
|
18
21
|
find(filter: PongoFilter<T>): Promise<T[]>;
|
|
19
22
|
}
|
|
23
|
+
type WithId<T> = T & {
|
|
24
|
+
_id: string;
|
|
25
|
+
};
|
|
20
26
|
type PongoFilter<T> = {
|
|
21
27
|
[P in keyof T]?: T[P] | PongoFilterOperator<T[P]>;
|
|
22
28
|
};
|
|
@@ -50,14 +56,27 @@ interface PongoInsertOneResult {
|
|
|
50
56
|
insertedId: string | null;
|
|
51
57
|
acknowledged: boolean;
|
|
52
58
|
}
|
|
59
|
+
interface PongoInsertManyResult {
|
|
60
|
+
acknowledged: boolean;
|
|
61
|
+
insertedIds: string[];
|
|
62
|
+
insertedCount: number;
|
|
63
|
+
}
|
|
53
64
|
interface PongoUpdateResult {
|
|
54
65
|
acknowledged: boolean;
|
|
55
66
|
modifiedCount: number;
|
|
56
67
|
}
|
|
68
|
+
interface PongoUpdateManyResult {
|
|
69
|
+
acknowledged: boolean;
|
|
70
|
+
modifiedCount: number;
|
|
71
|
+
}
|
|
57
72
|
interface PongoDeleteResult {
|
|
58
73
|
acknowledged: boolean;
|
|
59
74
|
deletedCount: number;
|
|
60
75
|
}
|
|
76
|
+
interface PongoDeleteManyResult {
|
|
77
|
+
acknowledged: boolean;
|
|
78
|
+
deletedCount: number;
|
|
79
|
+
}
|
|
61
80
|
|
|
62
81
|
declare const pongoClient: (connectionString: string) => PongoClient;
|
|
63
82
|
|
|
@@ -68,6 +87,17 @@ interface DbClient {
|
|
|
68
87
|
}
|
|
69
88
|
declare const getDbClient: (connectionString: string, database?: string) => DbClient;
|
|
70
89
|
|
|
90
|
+
type Entry<T> = {
|
|
91
|
+
[K in keyof Required<T>]: [K, Required<T>[K]];
|
|
92
|
+
}[keyof Required<T>];
|
|
93
|
+
type IterableEntry<T> = Entry<T> & {
|
|
94
|
+
[Symbol.iterator](): Iterator<Entry<T>>;
|
|
95
|
+
};
|
|
96
|
+
declare const entries: <T extends object>(obj: T) => IterableEntry<T>[];
|
|
97
|
+
type NonPartial<T> = {
|
|
98
|
+
[K in keyof Required<T>]: T[K];
|
|
99
|
+
};
|
|
100
|
+
|
|
71
101
|
declare class FindCursor<T> {
|
|
72
102
|
private findDocumentsPromise;
|
|
73
103
|
private documents;
|
|
@@ -107,23 +137,23 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
107
137
|
get hint(): Hint | undefined;
|
|
108
138
|
set hint(v: Hint | undefined);
|
|
109
139
|
insertOne(doc: OptionalUnlessRequiredId<T>, _options?: InsertOneOptions | undefined): Promise<InsertOneResult<T>>;
|
|
110
|
-
insertMany(
|
|
140
|
+
insertMany(docs: OptionalUnlessRequiredId<T>[], _options?: BulkWriteOptions | undefined): Promise<InsertManyResult<T>>;
|
|
111
141
|
bulkWrite(_operations: AnyBulkWriteOperation<T>[], _options?: BulkWriteOptions | undefined): Promise<BulkWriteResult>;
|
|
112
142
|
updateOne(filter: Filter<T>, update: Document[] | UpdateFilter<T>, _options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
113
143
|
replaceOne(_filter: Filter<T>, _: WithoutId<T>, _options?: ReplaceOptions | undefined): Promise<Document | UpdateResult<T>>;
|
|
114
|
-
updateMany(
|
|
144
|
+
updateMany(filter: Filter<T>, update: Document[] | UpdateFilter<T>, _options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
115
145
|
deleteOne(filter?: Filter<T> | undefined, _options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
116
|
-
deleteMany(
|
|
146
|
+
deleteMany(filter?: Filter<T> | undefined, _options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
117
147
|
rename(_newName: string, _options?: RenameOptions | undefined): Promise<Collection<Document>>;
|
|
118
148
|
drop(_options?: DropCollectionOptions | undefined): Promise<boolean>;
|
|
119
|
-
findOne(): Promise<WithId<T> | null>;
|
|
120
|
-
findOne(filter: Filter<T>): Promise<WithId<T> | null>;
|
|
121
|
-
findOne(filter: Filter<T>, options: FindOptions<Document>): Promise<WithId<T> | null>;
|
|
149
|
+
findOne(): Promise<WithId$1<T> | null>;
|
|
150
|
+
findOne(filter: Filter<T>): Promise<WithId$1<T> | null>;
|
|
151
|
+
findOne(filter: Filter<T>, options: FindOptions<Document>): Promise<WithId$1<T> | null>;
|
|
122
152
|
findOne<TS = T>(): Promise<TS | null>;
|
|
123
153
|
findOne<TS = T>(filter: Filter<TS>): Promise<TS | null>;
|
|
124
154
|
findOne<TS = T>(filter: Filter<TS>, options?: FindOptions<Document> | undefined): Promise<TS | null>;
|
|
125
|
-
find(): FindCursor$1<WithId<T>>;
|
|
126
|
-
find(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<WithId<T>>;
|
|
155
|
+
find(): FindCursor$1<WithId$1<T>>;
|
|
156
|
+
find(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<WithId$1<T>>;
|
|
127
157
|
find<T extends Document>(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<T>;
|
|
128
158
|
options(_options?: OperationOptions | undefined): Promise<Document>;
|
|
129
159
|
isCapped(_options?: OperationOptions | undefined): Promise<boolean>;
|
|
@@ -143,9 +173,9 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
143
173
|
indexInformation(): Promise<IndexDescriptionCompact>;
|
|
144
174
|
estimatedDocumentCount(_options?: EstimatedDocumentCountOptions | undefined): Promise<number>;
|
|
145
175
|
countDocuments(_filter?: Filter<T> | undefined, _options?: CountDocumentsOptions | undefined): Promise<number>;
|
|
146
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
147
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
148
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>, options: CommandOperationOptions): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
176
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
177
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
178
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>, options: CommandOperationOptions): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
149
179
|
distinct(key: string): Promise<any[]>;
|
|
150
180
|
distinct(key: string, filter: Filter<T>): Promise<any[]>;
|
|
151
181
|
distinct(key: string, filter: Filter<T>, options: CommandOperationOptions): Promise<any[]>;
|
|
@@ -162,25 +192,25 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
162
192
|
}): Promise<ModifyResult<T>>;
|
|
163
193
|
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions & {
|
|
164
194
|
includeResultMetadata: false;
|
|
165
|
-
}): Promise<WithId<T> | null>;
|
|
166
|
-
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions): Promise<WithId<T> | null>;
|
|
167
|
-
findOneAndDelete(filter: Filter<T>): Promise<WithId<T> | null>;
|
|
195
|
+
}): Promise<WithId$1<T> | null>;
|
|
196
|
+
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions): Promise<WithId$1<T> | null>;
|
|
197
|
+
findOneAndDelete(filter: Filter<T>): Promise<WithId$1<T> | null>;
|
|
168
198
|
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions & {
|
|
169
199
|
includeResultMetadata: true;
|
|
170
200
|
}): Promise<ModifyResult<T>>;
|
|
171
201
|
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions & {
|
|
172
202
|
includeResultMetadata: false;
|
|
173
|
-
}): Promise<WithId<T> | null>;
|
|
174
|
-
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions): Promise<WithId<T> | null>;
|
|
175
|
-
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>): Promise<WithId<T> | null>;
|
|
203
|
+
}): Promise<WithId$1<T> | null>;
|
|
204
|
+
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions): Promise<WithId$1<T> | null>;
|
|
205
|
+
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>): Promise<WithId$1<T> | null>;
|
|
176
206
|
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions & {
|
|
177
207
|
includeResultMetadata: true;
|
|
178
208
|
}): Promise<ModifyResult<T>>;
|
|
179
209
|
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions & {
|
|
180
210
|
includeResultMetadata: false;
|
|
181
|
-
}): Promise<WithId<T> | null>;
|
|
182
|
-
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions): Promise<WithId<T> | null>;
|
|
183
|
-
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>): Promise<WithId<T> | null>;
|
|
211
|
+
}): Promise<WithId$1<T> | null>;
|
|
212
|
+
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions): Promise<WithId$1<T> | null>;
|
|
213
|
+
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>): Promise<WithId$1<T> | null>;
|
|
184
214
|
aggregate<T extends Document = Document>(_pipeline?: Document[] | undefined, _options?: AggregateOptions | undefined): AggregationCursor<T>;
|
|
185
215
|
watch<TLocal extends Document = T, TChange extends Document = ChangeStreamDocument<TLocal>>(_pipeline?: Document[] | undefined, _options?: ChangeStreamOptions | undefined): ChangeStream<TLocal, TChange>;
|
|
186
216
|
initializeUnorderedBulkOp(_options?: BulkWriteOptions | undefined): UnorderedBulkOperation;
|
|
@@ -195,25 +225,60 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
195
225
|
createCollection(): Promise<void>;
|
|
196
226
|
}
|
|
197
227
|
|
|
228
|
+
type ObjectId = string & {
|
|
229
|
+
__brandId: 'ObjectId';
|
|
230
|
+
};
|
|
231
|
+
|
|
198
232
|
declare const postgresClient: (connectionString: string, database?: string) => DbClient;
|
|
199
233
|
|
|
200
234
|
type SQL = string & {
|
|
201
235
|
__brand: 'sql';
|
|
202
236
|
};
|
|
237
|
+
declare const sql: (sqlQuery: string, ...params: unknown[]) => SQL;
|
|
203
238
|
|
|
204
239
|
declare const execute: <Result = void>(pool: pg.Pool, handle: (client: pg.PoolClient) => Promise<Result>) => Promise<Result>;
|
|
205
240
|
declare const executeSQL: <Result extends pg.QueryResultRow = pg.QueryResultRow>(pool: pg.Pool, sql: SQL) => Promise<pg.QueryResult<Result>>;
|
|
206
241
|
|
|
242
|
+
declare const Operators: {
|
|
243
|
+
$eq: string;
|
|
244
|
+
$gt: string;
|
|
245
|
+
$gte: string;
|
|
246
|
+
$lt: string;
|
|
247
|
+
$lte: string;
|
|
248
|
+
$ne: string;
|
|
249
|
+
$in: string;
|
|
250
|
+
$nin: string;
|
|
251
|
+
$elemMatch: string;
|
|
252
|
+
$all: string;
|
|
253
|
+
$size: string;
|
|
254
|
+
};
|
|
255
|
+
declare const isOperator: (key: string) => boolean;
|
|
256
|
+
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
257
|
+
declare const handleOperator: (path: string, operator: string, value: unknown) => string;
|
|
258
|
+
|
|
207
259
|
declare const constructFilterQuery: <T>(filter: PongoFilter<T>) => string;
|
|
208
260
|
|
|
209
261
|
declare const getPool: (connectionStringOrOptions: string | pg.PoolConfig) => pg.Pool;
|
|
210
262
|
declare const endPool: (connectionString: string) => Promise<void>;
|
|
211
263
|
declare const endAllPools: () => Promise<void[]>;
|
|
212
264
|
|
|
265
|
+
declare const postgresCollection: <T>(collectionName: string, pool: pg.Pool) => PongoCollection<T>;
|
|
266
|
+
declare const collectionSQLBuilder: (collectionName: string) => {
|
|
267
|
+
createCollection: () => SQL;
|
|
268
|
+
insertOne: <T>(document: WithId<T>) => SQL;
|
|
269
|
+
insertMany: <T_1>(documents: WithId<T_1>[]) => SQL;
|
|
270
|
+
updateOne: <T_2>(filter: PongoFilter<T_2>, update: PongoUpdate<T_2>) => SQL;
|
|
271
|
+
updateMany: <T_3>(filter: PongoFilter<T_3>, update: PongoUpdate<T_3>) => SQL;
|
|
272
|
+
deleteOne: <T_4>(filter: PongoFilter<T_4>) => SQL;
|
|
273
|
+
deleteMany: <T_5>(filter: PongoFilter<T_5>) => SQL;
|
|
274
|
+
findOne: <T_6>(filter: PongoFilter<T_6>) => SQL;
|
|
275
|
+
find: <T_7>(filter: PongoFilter<T_7>) => SQL;
|
|
276
|
+
};
|
|
277
|
+
|
|
213
278
|
declare const buildUpdateQuery: <T>(update: PongoUpdate<T>) => SQL;
|
|
214
279
|
declare const buildSetQuery: <T>(set: $set<T>, currentUpdateQuery: SQL) => SQL;
|
|
215
280
|
declare const buildUnsetQuery: <T>(unset: $unset<T>, currentUpdateQuery: SQL) => SQL;
|
|
216
281
|
declare const buildIncQuery: <T>(inc: $inc<T>, currentUpdateQuery: SQL) => SQL;
|
|
217
282
|
declare const buildPushQuery: <T>(push: $push<T>, currentUpdateQuery: SQL) => SQL;
|
|
218
283
|
|
|
219
|
-
export { type $inc, type $push, type $set, type $unset, Collection, Db, type DbClient, FindCursor, MongoClient, type PongoClient, type PongoCollection, type PongoDb, type PongoDeleteResult, type PongoFilter, type PongoFilterOperator, type PongoInsertOneResult, type PongoUpdate, type PongoUpdateResult, buildIncQuery, buildPushQuery, buildSetQuery, buildUnsetQuery, buildUpdateQuery, constructFilterQuery, endAllPools, endPool, execute, executeSQL, getDbClient, getPool, pongoClient, postgresClient };
|
|
284
|
+
export { type $inc, type $push, type $set, type $unset, Collection, Db, type DbClient, FindCursor, MongoClient, type NonPartial, type ObjectId, Operators, type PongoClient, type PongoCollection, type PongoDb, type PongoDeleteManyResult, type PongoDeleteResult, type PongoFilter, type PongoFilterOperator, type PongoInsertManyResult, type PongoInsertOneResult, type PongoUpdate, type PongoUpdateManyResult, type PongoUpdateResult, type SQL, type WithId, buildIncQuery, buildPushQuery, buildSetQuery, buildUnsetQuery, buildUpdateQuery, collectionSQLBuilder, constructFilterQuery, endAllPools, endPool, entries, execute, executeSQL, getDbClient, getPool, handleOperator, hasOperators, isOperator, pongoClient, postgresClient, postgresCollection, sql };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Document, Collection as Collection$1, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId, FindOptions, FindCursor as FindCursor$1, OperationOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, CommandOperationOptions, AbstractCursorOptions, ListIndexesCursor, IndexInformationOptions, IndexDescriptionInfo, IndexDescriptionCompact, EstimatedDocumentCountOptions, CountDocumentsOptions, EnhancedOmit, Flatten, FindOneAndDeleteOptions, ModifyResult, FindOneAndReplaceOptions, FindOneAndUpdateOptions, AggregateOptions, AggregationCursor, ChangeStreamDocument, ChangeStreamOptions, ChangeStream, UnorderedBulkOperation, OrderedBulkOperation, CountOptions, ListSearchIndexesOptions, ListSearchIndexesCursor, SearchIndexDescription } from 'mongodb';
|
|
1
|
+
import { Document, Collection as Collection$1, ReadConcern, ReadPreference, BSONSerializeOptions, WriteConcern, Hint, OptionalUnlessRequiredId, InsertOneOptions, InsertOneResult, BulkWriteOptions, InsertManyResult, AnyBulkWriteOperation, BulkWriteResult, Filter, UpdateFilter, UpdateOptions, UpdateResult, WithoutId, ReplaceOptions, DeleteOptions, DeleteResult, RenameOptions, DropCollectionOptions, WithId as WithId$1, FindOptions, FindCursor as FindCursor$1, OperationOptions, IndexSpecification, CreateIndexesOptions, IndexDescription, CommandOperationOptions, AbstractCursorOptions, ListIndexesCursor, IndexInformationOptions, IndexDescriptionInfo, IndexDescriptionCompact, EstimatedDocumentCountOptions, CountDocumentsOptions, EnhancedOmit, Flatten, FindOneAndDeleteOptions, ModifyResult, FindOneAndReplaceOptions, FindOneAndUpdateOptions, AggregateOptions, AggregationCursor, ChangeStreamDocument, ChangeStreamOptions, ChangeStream, UnorderedBulkOperation, OrderedBulkOperation, CountOptions, ListSearchIndexesOptions, ListSearchIndexesCursor, SearchIndexDescription } from 'mongodb';
|
|
2
2
|
import pg from 'pg';
|
|
3
3
|
|
|
4
4
|
interface PongoClient {
|
|
@@ -12,11 +12,17 @@ interface PongoDb {
|
|
|
12
12
|
interface PongoCollection<T> {
|
|
13
13
|
createCollection(): Promise<void>;
|
|
14
14
|
insertOne(document: T): Promise<PongoInsertOneResult>;
|
|
15
|
+
insertMany(documents: T[]): Promise<PongoInsertManyResult>;
|
|
15
16
|
updateOne(filter: PongoFilter<T>, update: PongoUpdate<T>): Promise<PongoUpdateResult>;
|
|
17
|
+
updateMany(filter: PongoFilter<T>, update: PongoUpdate<T>): Promise<PongoUpdateResult>;
|
|
16
18
|
deleteOne(filter: PongoFilter<T>): Promise<PongoDeleteResult>;
|
|
19
|
+
deleteMany(filter: PongoFilter<T>): Promise<PongoDeleteResult>;
|
|
17
20
|
findOne(filter: PongoFilter<T>): Promise<T | null>;
|
|
18
21
|
find(filter: PongoFilter<T>): Promise<T[]>;
|
|
19
22
|
}
|
|
23
|
+
type WithId<T> = T & {
|
|
24
|
+
_id: string;
|
|
25
|
+
};
|
|
20
26
|
type PongoFilter<T> = {
|
|
21
27
|
[P in keyof T]?: T[P] | PongoFilterOperator<T[P]>;
|
|
22
28
|
};
|
|
@@ -50,14 +56,27 @@ interface PongoInsertOneResult {
|
|
|
50
56
|
insertedId: string | null;
|
|
51
57
|
acknowledged: boolean;
|
|
52
58
|
}
|
|
59
|
+
interface PongoInsertManyResult {
|
|
60
|
+
acknowledged: boolean;
|
|
61
|
+
insertedIds: string[];
|
|
62
|
+
insertedCount: number;
|
|
63
|
+
}
|
|
53
64
|
interface PongoUpdateResult {
|
|
54
65
|
acknowledged: boolean;
|
|
55
66
|
modifiedCount: number;
|
|
56
67
|
}
|
|
68
|
+
interface PongoUpdateManyResult {
|
|
69
|
+
acknowledged: boolean;
|
|
70
|
+
modifiedCount: number;
|
|
71
|
+
}
|
|
57
72
|
interface PongoDeleteResult {
|
|
58
73
|
acknowledged: boolean;
|
|
59
74
|
deletedCount: number;
|
|
60
75
|
}
|
|
76
|
+
interface PongoDeleteManyResult {
|
|
77
|
+
acknowledged: boolean;
|
|
78
|
+
deletedCount: number;
|
|
79
|
+
}
|
|
61
80
|
|
|
62
81
|
declare const pongoClient: (connectionString: string) => PongoClient;
|
|
63
82
|
|
|
@@ -68,6 +87,17 @@ interface DbClient {
|
|
|
68
87
|
}
|
|
69
88
|
declare const getDbClient: (connectionString: string, database?: string) => DbClient;
|
|
70
89
|
|
|
90
|
+
type Entry<T> = {
|
|
91
|
+
[K in keyof Required<T>]: [K, Required<T>[K]];
|
|
92
|
+
}[keyof Required<T>];
|
|
93
|
+
type IterableEntry<T> = Entry<T> & {
|
|
94
|
+
[Symbol.iterator](): Iterator<Entry<T>>;
|
|
95
|
+
};
|
|
96
|
+
declare const entries: <T extends object>(obj: T) => IterableEntry<T>[];
|
|
97
|
+
type NonPartial<T> = {
|
|
98
|
+
[K in keyof Required<T>]: T[K];
|
|
99
|
+
};
|
|
100
|
+
|
|
71
101
|
declare class FindCursor<T> {
|
|
72
102
|
private findDocumentsPromise;
|
|
73
103
|
private documents;
|
|
@@ -107,23 +137,23 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
107
137
|
get hint(): Hint | undefined;
|
|
108
138
|
set hint(v: Hint | undefined);
|
|
109
139
|
insertOne(doc: OptionalUnlessRequiredId<T>, _options?: InsertOneOptions | undefined): Promise<InsertOneResult<T>>;
|
|
110
|
-
insertMany(
|
|
140
|
+
insertMany(docs: OptionalUnlessRequiredId<T>[], _options?: BulkWriteOptions | undefined): Promise<InsertManyResult<T>>;
|
|
111
141
|
bulkWrite(_operations: AnyBulkWriteOperation<T>[], _options?: BulkWriteOptions | undefined): Promise<BulkWriteResult>;
|
|
112
142
|
updateOne(filter: Filter<T>, update: Document[] | UpdateFilter<T>, _options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
113
143
|
replaceOne(_filter: Filter<T>, _: WithoutId<T>, _options?: ReplaceOptions | undefined): Promise<Document | UpdateResult<T>>;
|
|
114
|
-
updateMany(
|
|
144
|
+
updateMany(filter: Filter<T>, update: Document[] | UpdateFilter<T>, _options?: UpdateOptions | undefined): Promise<UpdateResult<T>>;
|
|
115
145
|
deleteOne(filter?: Filter<T> | undefined, _options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
116
|
-
deleteMany(
|
|
146
|
+
deleteMany(filter?: Filter<T> | undefined, _options?: DeleteOptions | undefined): Promise<DeleteResult>;
|
|
117
147
|
rename(_newName: string, _options?: RenameOptions | undefined): Promise<Collection<Document>>;
|
|
118
148
|
drop(_options?: DropCollectionOptions | undefined): Promise<boolean>;
|
|
119
|
-
findOne(): Promise<WithId<T> | null>;
|
|
120
|
-
findOne(filter: Filter<T>): Promise<WithId<T> | null>;
|
|
121
|
-
findOne(filter: Filter<T>, options: FindOptions<Document>): Promise<WithId<T> | null>;
|
|
149
|
+
findOne(): Promise<WithId$1<T> | null>;
|
|
150
|
+
findOne(filter: Filter<T>): Promise<WithId$1<T> | null>;
|
|
151
|
+
findOne(filter: Filter<T>, options: FindOptions<Document>): Promise<WithId$1<T> | null>;
|
|
122
152
|
findOne<TS = T>(): Promise<TS | null>;
|
|
123
153
|
findOne<TS = T>(filter: Filter<TS>): Promise<TS | null>;
|
|
124
154
|
findOne<TS = T>(filter: Filter<TS>, options?: FindOptions<Document> | undefined): Promise<TS | null>;
|
|
125
|
-
find(): FindCursor$1<WithId<T>>;
|
|
126
|
-
find(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<WithId<T>>;
|
|
155
|
+
find(): FindCursor$1<WithId$1<T>>;
|
|
156
|
+
find(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<WithId$1<T>>;
|
|
127
157
|
find<T extends Document>(filter: Filter<T>, options?: FindOptions<Document> | undefined): FindCursor$1<T>;
|
|
128
158
|
options(_options?: OperationOptions | undefined): Promise<Document>;
|
|
129
159
|
isCapped(_options?: OperationOptions | undefined): Promise<boolean>;
|
|
@@ -143,9 +173,9 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
143
173
|
indexInformation(): Promise<IndexDescriptionCompact>;
|
|
144
174
|
estimatedDocumentCount(_options?: EstimatedDocumentCountOptions | undefined): Promise<number>;
|
|
145
175
|
countDocuments(_filter?: Filter<T> | undefined, _options?: CountDocumentsOptions | undefined): Promise<number>;
|
|
146
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
147
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
148
|
-
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>, options: CommandOperationOptions): Promise<Flatten<WithId<T>[Key]>[]>;
|
|
176
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
177
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
178
|
+
distinct<Key extends '_id' | keyof EnhancedOmit<T, '_id'>>(key: Key, filter: Filter<T>, options: CommandOperationOptions): Promise<Flatten<WithId$1<T>[Key]>[]>;
|
|
149
179
|
distinct(key: string): Promise<any[]>;
|
|
150
180
|
distinct(key: string, filter: Filter<T>): Promise<any[]>;
|
|
151
181
|
distinct(key: string, filter: Filter<T>, options: CommandOperationOptions): Promise<any[]>;
|
|
@@ -162,25 +192,25 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
162
192
|
}): Promise<ModifyResult<T>>;
|
|
163
193
|
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions & {
|
|
164
194
|
includeResultMetadata: false;
|
|
165
|
-
}): Promise<WithId<T> | null>;
|
|
166
|
-
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions): Promise<WithId<T> | null>;
|
|
167
|
-
findOneAndDelete(filter: Filter<T>): Promise<WithId<T> | null>;
|
|
195
|
+
}): Promise<WithId$1<T> | null>;
|
|
196
|
+
findOneAndDelete(filter: Filter<T>, options: FindOneAndDeleteOptions): Promise<WithId$1<T> | null>;
|
|
197
|
+
findOneAndDelete(filter: Filter<T>): Promise<WithId$1<T> | null>;
|
|
168
198
|
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions & {
|
|
169
199
|
includeResultMetadata: true;
|
|
170
200
|
}): Promise<ModifyResult<T>>;
|
|
171
201
|
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions & {
|
|
172
202
|
includeResultMetadata: false;
|
|
173
|
-
}): Promise<WithId<T> | null>;
|
|
174
|
-
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions): Promise<WithId<T> | null>;
|
|
175
|
-
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>): Promise<WithId<T> | null>;
|
|
203
|
+
}): Promise<WithId$1<T> | null>;
|
|
204
|
+
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>, options: FindOneAndReplaceOptions): Promise<WithId$1<T> | null>;
|
|
205
|
+
findOneAndReplace(filter: Filter<T>, replacement: WithoutId<T>): Promise<WithId$1<T> | null>;
|
|
176
206
|
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions & {
|
|
177
207
|
includeResultMetadata: true;
|
|
178
208
|
}): Promise<ModifyResult<T>>;
|
|
179
209
|
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions & {
|
|
180
210
|
includeResultMetadata: false;
|
|
181
|
-
}): Promise<WithId<T> | null>;
|
|
182
|
-
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions): Promise<WithId<T> | null>;
|
|
183
|
-
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>): Promise<WithId<T> | null>;
|
|
211
|
+
}): Promise<WithId$1<T> | null>;
|
|
212
|
+
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>, options: FindOneAndUpdateOptions): Promise<WithId$1<T> | null>;
|
|
213
|
+
findOneAndUpdate(filter: Filter<T>, update: UpdateFilter<T>): Promise<WithId$1<T> | null>;
|
|
184
214
|
aggregate<T extends Document = Document>(_pipeline?: Document[] | undefined, _options?: AggregateOptions | undefined): AggregationCursor<T>;
|
|
185
215
|
watch<TLocal extends Document = T, TChange extends Document = ChangeStreamDocument<TLocal>>(_pipeline?: Document[] | undefined, _options?: ChangeStreamOptions | undefined): ChangeStream<TLocal, TChange>;
|
|
186
216
|
initializeUnorderedBulkOp(_options?: BulkWriteOptions | undefined): UnorderedBulkOperation;
|
|
@@ -195,25 +225,60 @@ declare class Collection<T extends Document> implements Collection$1<T> {
|
|
|
195
225
|
createCollection(): Promise<void>;
|
|
196
226
|
}
|
|
197
227
|
|
|
228
|
+
type ObjectId = string & {
|
|
229
|
+
__brandId: 'ObjectId';
|
|
230
|
+
};
|
|
231
|
+
|
|
198
232
|
declare const postgresClient: (connectionString: string, database?: string) => DbClient;
|
|
199
233
|
|
|
200
234
|
type SQL = string & {
|
|
201
235
|
__brand: 'sql';
|
|
202
236
|
};
|
|
237
|
+
declare const sql: (sqlQuery: string, ...params: unknown[]) => SQL;
|
|
203
238
|
|
|
204
239
|
declare const execute: <Result = void>(pool: pg.Pool, handle: (client: pg.PoolClient) => Promise<Result>) => Promise<Result>;
|
|
205
240
|
declare const executeSQL: <Result extends pg.QueryResultRow = pg.QueryResultRow>(pool: pg.Pool, sql: SQL) => Promise<pg.QueryResult<Result>>;
|
|
206
241
|
|
|
242
|
+
declare const Operators: {
|
|
243
|
+
$eq: string;
|
|
244
|
+
$gt: string;
|
|
245
|
+
$gte: string;
|
|
246
|
+
$lt: string;
|
|
247
|
+
$lte: string;
|
|
248
|
+
$ne: string;
|
|
249
|
+
$in: string;
|
|
250
|
+
$nin: string;
|
|
251
|
+
$elemMatch: string;
|
|
252
|
+
$all: string;
|
|
253
|
+
$size: string;
|
|
254
|
+
};
|
|
255
|
+
declare const isOperator: (key: string) => boolean;
|
|
256
|
+
declare const hasOperators: (value: Record<string, unknown>) => boolean;
|
|
257
|
+
declare const handleOperator: (path: string, operator: string, value: unknown) => string;
|
|
258
|
+
|
|
207
259
|
declare const constructFilterQuery: <T>(filter: PongoFilter<T>) => string;
|
|
208
260
|
|
|
209
261
|
declare const getPool: (connectionStringOrOptions: string | pg.PoolConfig) => pg.Pool;
|
|
210
262
|
declare const endPool: (connectionString: string) => Promise<void>;
|
|
211
263
|
declare const endAllPools: () => Promise<void[]>;
|
|
212
264
|
|
|
265
|
+
declare const postgresCollection: <T>(collectionName: string, pool: pg.Pool) => PongoCollection<T>;
|
|
266
|
+
declare const collectionSQLBuilder: (collectionName: string) => {
|
|
267
|
+
createCollection: () => SQL;
|
|
268
|
+
insertOne: <T>(document: WithId<T>) => SQL;
|
|
269
|
+
insertMany: <T_1>(documents: WithId<T_1>[]) => SQL;
|
|
270
|
+
updateOne: <T_2>(filter: PongoFilter<T_2>, update: PongoUpdate<T_2>) => SQL;
|
|
271
|
+
updateMany: <T_3>(filter: PongoFilter<T_3>, update: PongoUpdate<T_3>) => SQL;
|
|
272
|
+
deleteOne: <T_4>(filter: PongoFilter<T_4>) => SQL;
|
|
273
|
+
deleteMany: <T_5>(filter: PongoFilter<T_5>) => SQL;
|
|
274
|
+
findOne: <T_6>(filter: PongoFilter<T_6>) => SQL;
|
|
275
|
+
find: <T_7>(filter: PongoFilter<T_7>) => SQL;
|
|
276
|
+
};
|
|
277
|
+
|
|
213
278
|
declare const buildUpdateQuery: <T>(update: PongoUpdate<T>) => SQL;
|
|
214
279
|
declare const buildSetQuery: <T>(set: $set<T>, currentUpdateQuery: SQL) => SQL;
|
|
215
280
|
declare const buildUnsetQuery: <T>(unset: $unset<T>, currentUpdateQuery: SQL) => SQL;
|
|
216
281
|
declare const buildIncQuery: <T>(inc: $inc<T>, currentUpdateQuery: SQL) => SQL;
|
|
217
282
|
declare const buildPushQuery: <T>(push: $push<T>, currentUpdateQuery: SQL) => SQL;
|
|
218
283
|
|
|
219
|
-
export { type $inc, type $push, type $set, type $unset, Collection, Db, type DbClient, FindCursor, MongoClient, type PongoClient, type PongoCollection, type PongoDb, type PongoDeleteResult, type PongoFilter, type PongoFilterOperator, type PongoInsertOneResult, type PongoUpdate, type PongoUpdateResult, buildIncQuery, buildPushQuery, buildSetQuery, buildUnsetQuery, buildUpdateQuery, constructFilterQuery, endAllPools, endPool, execute, executeSQL, getDbClient, getPool, pongoClient, postgresClient };
|
|
284
|
+
export { type $inc, type $push, type $set, type $unset, Collection, Db, type DbClient, FindCursor, MongoClient, type NonPartial, type ObjectId, Operators, type PongoClient, type PongoCollection, type PongoDb, type PongoDeleteManyResult, type PongoDeleteResult, type PongoFilter, type PongoFilterOperator, type PongoInsertManyResult, type PongoInsertOneResult, type PongoUpdate, type PongoUpdateManyResult, type PongoUpdateResult, type SQL, type WithId, buildIncQuery, buildPushQuery, buildSetQuery, buildUnsetQuery, buildUpdateQuery, collectionSQLBuilder, constructFilterQuery, endAllPools, endPool, entries, execute, executeSQL, getDbClient, getPool, handleOperator, hasOperators, isOperator, pongoClient, postgresClient, postgresCollection, sql };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import b from"pg";var m=new Map,
|
|
1
|
+
import b from"pg";var m=new Map,I=t=>{let e=typeof t=="string"?t:t.connectionString,n=typeof t=="string"?{connectionString:e}:t;return m.get(e)??m.set(e,new b.Pool(n)).get(e)},h=async t=>{let e=m.get(t);e&&(await e.end(),m.delete(t))},z=()=>Promise.all([...m.keys()].map(t=>h(t)));import"pg";import K from"pg-format";import{v4 as E}from"uuid";var $=async(t,e)=>{let n=await t.connect();try{return await e(n)}finally{n.release()}},y=async(t,e)=>$(t,n=>n.query(e));var u=t=>Object.entries(t).map(([e,n])=>[e,n]);import d from"pg-format";var x={$eq:"$eq",$gt:"$gt",$gte:"$gte",$lt:"$lt",$lte:"$lte",$ne:"$ne",$in:"$in",$nin:"$nin",$elemMatch:"$elemMatch",$all:"$all",$size:"$size"},D={$gt:">",$gte:">=",$lt:"<",$lte:"<=",$ne:"!="},L=t=>t.startsWith("$"),F=t=>Object.keys(t).some(L),c=(t,e,n)=>{if(t==="_id")return W(e,n);switch(e){case"$eq":return d("(data @> %L::jsonb OR jsonb_path_exists(data, '$.%s[*] ? (@ == %s)'))",JSON.stringify(C(t,n)),t,JSON.stringify(n));case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return d(`data #>> %L ${D[e]} %L`,`{${t.split(".").join(",")}}`,n);case"$in":return d("data #>> %L IN (%s)",`{${t.split(".").join(",")}}`,n.map(o=>d("%L",o)).join(", "));case"$nin":return d("data #>> %L NOT IN (%s)",`{${t.split(".").join(",")}}`,n.map(o=>d("%L",o)).join(", "));case"$elemMatch":{let o=u(n).map(([i,r])=>d('@."%s" == %s',i,JSON.stringify(r))).join(" && ");return d("jsonb_path_exists(data, '$.%s[*] ? (%s)')",t,o)}case"$all":return d("data @> %L::jsonb",JSON.stringify(C(t,n)));case"$size":return d("jsonb_array_length(data #> %L) = %L",`{${t.split(".").join(",")}}`,n);default:throw new Error(`Unsupported operator: ${e}`)}},W=(t,e)=>{switch(t){case"$eq":return d("_id = %L",e);case"$gt":case"$gte":case"$lt":case"$lte":case"$ne":return d(`_id ${D[t]} %L`,e);case"$in":return d("_id IN (%s)",e.map(n=>d("%L",n)).join(", "));case"$nin":return d("_id NOT IN (%s)",e.map(n=>d("%L",n)).join(", "));default:throw new Error(`Unsupported operator: ${t}`)}},C=(t,e)=>t.split(".").reverse().reduce((n,o)=>({[o]:n}),e);var k="AND",p=t=>Object.entries(t).map(([e,n])=>U(n)?A(e,n):c(e,"$eq",n)).join(` ${k} `),A=(t,e)=>{let n=!F(e);return u(e).map(([o,i])=>n?c(`${t}.${o}`,x.$eq,i):c(t,o,i)).join(` ${k} `)},U=t=>t!==null&&typeof t=="object"&&!Array.isArray(t);import Q from"pg-format";var l=(t,...e)=>Q(t,...e);var O=t=>u(t).reduce((e,[n,o])=>{switch(n){case"$set":return j(o,e);case"$unset":return q(o,e);case"$inc":return N(o,e);case"$push":return B(o,e);default:return e}},l("data")),j=(t,e)=>l("jsonb_set(%s, %L, data || %L)",e,"{}",JSON.stringify(t)),q=(t,e)=>l("%s - %L",e,Object.keys(t).join(", ")),N=(t,e)=>{for(let[n,o]of Object.entries(t))e=l("jsonb_set(%s, '{%s}', to_jsonb((data->>'%s')::numeric + %L))",e,n,n,o);return e},B=(t,e)=>{for(let[n,o]of Object.entries(t))e=l("jsonb_set(%s, '{%s}', (COALESCE(data->'%s', '[]'::jsonb) || '[%s]'::jsonb))",e,n,n,JSON.stringify(o));return e};var M=(t,e)=>{let n=r=>y(e,r),o=H(t),i=n(o.createCollection());return{createCollection:async()=>{await i},insertOne:async r=>{await i;let s=E();return(await n(o.insertOne({_id:s,...r}))).rowCount?{insertedId:s,acknowledged:!0}:{insertedId:null,acknowledged:!1}},insertMany:async r=>{await i;let s=r.map(w=>({_id:E(),...w})),a=await n(o.insertMany(s));return{acknowledged:a.rowCount===s.length,insertedCount:a.rowCount??0,insertedIds:s.map(w=>w._id)}},updateOne:async(r,s)=>{await i;let a=await n(o.updateOne(r,s));return a.rowCount?{acknowledged:!0,modifiedCount:a.rowCount}:{acknowledged:!1,modifiedCount:0}},updateMany:async(r,s)=>{await i;let a=await n(o.updateMany(r,s));return a.rowCount?{acknowledged:!0,modifiedCount:a.rowCount}:{acknowledged:!1,modifiedCount:0}},deleteOne:async r=>{await i;let s=await n(o.deleteOne(r));return s.rowCount?{acknowledged:!0,deletedCount:s.rowCount}:{acknowledged:!1,deletedCount:0}},deleteMany:async r=>{await i;let s=await n(o.deleteMany(r));return s.rowCount?{acknowledged:!0,deletedCount:s.rowCount}:{acknowledged:!1,deletedCount:0}},findOne:async r=>(await i,(await n(o.findOne(r))).rows[0]?.data??null),find:async r=>(await i,(await n(o.find(r))).rows.map(a=>a.data))}},H=t=>({createCollection:()=>l("CREATE TABLE IF NOT EXISTS %I (_id UUID PRIMARY KEY, data JSONB)",t),insertOne:e=>l("INSERT INTO %I (_id, data) VALUES (%L, %L)",t,e._id,JSON.stringify(e)),insertMany:e=>{let n=e.map(o=>K("(%L, %L)",o._id,JSON.stringify(o))).join(", ");return l("INSERT INTO %I (_id, data) VALUES %s",t,n)},updateOne:(e,n)=>{let o=p(e),i=O(n);return l(`WITH cte AS (
|
|
2
|
+
SELECT _id FROM %I WHERE %s LIMIT 1
|
|
3
|
+
)
|
|
4
|
+
UPDATE %I SET data = %s FROM cte WHERE %I._id = cte._id`,t,o,t,i,t)},updateMany:(e,n)=>{let o=p(e),i=O(n);return l("UPDATE %I SET data = %s WHERE %s",t,i,o)},deleteOne:e=>{let n=p(e);return l("DELETE FROM %I WHERE %s",t,n)},deleteMany:e=>{let n=p(e);return l("DELETE FROM %I WHERE %s",t,n)},findOne:e=>{let n=p(e);return l("SELECT data FROM %I WHERE %s LIMIT 1",t,n)},find:e=>{let n=p(e);return l("SELECT data FROM %I WHERE %s",t,n)}});var R=(t,e)=>{let n=I({connectionString:t,database:e});return{connect:()=>Promise.resolve(),close:()=>h(t),collection:o=>M(o,n)}};var P=(t,e)=>R(t,e);var _=t=>{let e=P(t),n={connect:async()=>(await e.connect(),n),close:()=>e.close(),db:o=>o?P(t,o):e};return n};var f=class{findDocumentsPromise;documents=null;index=0;constructor(e){this.findDocumentsPromise=e}async toArray(){return this.findDocuments()}async forEach(e){let n=await this.findDocuments();for(let o of n)e(o);return Promise.resolve()}hasNext(){if(this.documents===null)throw Error("Error while fetching documents");return this.index<this.documents.length}async next(){let e=await this.findDocuments();return this.hasNext()?e[this.index++]??null:null}async findDocuments(){return this.documents=await this.findDocumentsPromise,this.documents}};import"mongodb";var g=class{collection;constructor(e){this.collection=e}get dbName(){throw new Error("Method not implemented.")}get collectionName(){throw new Error("Method not implemented.")}get namespace(){throw new Error("Method not implemented.")}get readConcern(){throw new Error("Method not implemented.")}get readPreference(){throw new Error("Method not implemented.")}get bsonOptions(){throw new Error("Method not implemented.")}get writeConcern(){throw new Error("Method not implemented.")}get hint(){throw new Error("Method not implemented.")}set hint(e){throw new Error("Method not implemented.")}async insertOne(e,n){let o=await this.collection.insertOne(e);return{acknowledged:o.acknowledged,insertedId:o.insertedId}}async insertMany(e,n){let o=await this.collection.insertMany(e);return{acknowledged:o.acknowledged,insertedIds:o.insertedIds,insertedCount:o.insertedCount}}bulkWrite(e,n){throw new Error("Method not implemented.")}async updateOne(e,n,o){let i=await this.collection.updateOne(e,n);return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}replaceOne(e,n,o){throw new Error("Method not implemented.")}async updateMany(e,n,o){let i=await this.collection.updateMany(e,n);return{acknowledged:i.acknowledged,matchedCount:i.modifiedCount,modifiedCount:i.modifiedCount,upsertedCount:i.modifiedCount,upsertedId:null}}async deleteOne(e,n){let o=await this.collection.deleteOne(e);return{acknowledged:o.acknowledged,deletedCount:o.deletedCount}}async deleteMany(e,n){let o=await this.collection.deleteMany(e);return{acknowledged:o.acknowledged,deletedCount:o.deletedCount}}rename(e,n){throw new Error("Method not implemented.")}drop(e){throw new Error("Method not implemented.")}async findOne(e,n){return this.collection.findOne(e)}find(e,n){return new f(this.collection.find(e))}options(e){throw new Error("Method not implemented.")}isCapped(e){throw new Error("Method not implemented.")}createIndex(e,n){throw new Error("Method not implemented.")}createIndexes(e,n){throw new Error("Method not implemented.")}dropIndex(e,n){throw new Error("Method not implemented.")}dropIndexes(e){throw new Error("Method not implemented.")}listIndexes(e){throw new Error("Method not implemented.")}indexExists(e,n){throw new Error("Method not implemented.")}indexInformation(e){throw new Error("Method not implemented.")}estimatedDocumentCount(e){throw new Error("Method not implemented.")}countDocuments(e,n){throw new Error("Method not implemented.")}distinct(e,n,o){throw new Error("Method not implemented.")}indexes(e){throw new Error("Method not implemented.")}findOneAndDelete(e,n){throw new Error("Method not implemented.")}findOneAndReplace(e,n,o){throw new Error("Method not implemented.")}findOneAndUpdate(e,n,o){throw new Error("Method not implemented.")}aggregate(e,n){throw new Error("Method not implemented.")}watch(e,n){throw new Error("Method not implemented.")}initializeUnorderedBulkOp(e){throw new Error("Method not implemented.")}initializeOrderedBulkOp(e){throw new Error("Method not implemented.")}count(e,n){throw new Error("Method not implemented.")}listSearchIndexes(e,n){throw new Error("Method not implemented.")}createSearchIndex(e){throw new Error("Method not implemented.")}createSearchIndexes(e){throw new Error("Method not implemented.")}dropSearchIndex(e){throw new Error("Method not implemented.")}updateSearchIndex(e,n){throw new Error("Method not implemented.")}async createCollection(){await this.collection.createCollection()}};var T=class{constructor(e){this.pongoDb=e}collection(e){return new g(this.pongoDb.collection(e))}};var S=class{pongoClient;constructor(e){this.pongoClient=_(e)}async connect(){return await this.pongoClient.connect(),this}async close(){await this.pongoClient.close()}db(e){return new T(this.pongoClient.db(e))}};export{g as Collection,T as Db,f as FindCursor,S as MongoClient,x as Operators,N as buildIncQuery,B as buildPushQuery,j as buildSetQuery,q as buildUnsetQuery,O as buildUpdateQuery,H as collectionSQLBuilder,p as constructFilterQuery,z as endAllPools,h as endPool,u as entries,$ as execute,y as executeSQL,P as getDbClient,I as getPool,c as handleOperator,F as hasOperators,L as isOperator,_ as pongoClient,R as postgresClient,M as postgresCollection,l as sql};
|
|
2
5
|
//# sourceMappingURL=index.js.map
|