Skip to content

Commit ac7df28

Browse files
committed
Added peer dependency to pg and uuid types
Adjusted also README to show proper samples
1 parent 02260b5 commit ac7df28

File tree

5 files changed

+43
-46
lines changed

5 files changed

+43
-46
lines changed

README.md

+17-20
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ type User = { name: string; age: number };
2929
const connectionString =
3030
"postgresql://dbuser:[email protected]:3211/mydb";
3131

32-
const pongoClient = pongoClient(connectionString);
33-
const pongoDb = pongoClient.db();
32+
const pongo = pongoClient(connectionString);
33+
const pongoDb = pongo.db();
3434

3535
const users = pongoDb.collection<User>("users");
3636
const roger = { name: "Roger", age: 30 };
3737
const anita = { name: "Anita", age: 25 };
3838
const cruella = { _id: uuid(), name: "Cruella", age: 40 };
3939

4040
// Inserting
41-
await pongoCollection.insertOne(roger);
42-
await pongoCollection.insertOne(cruella);
41+
await users.insertOne(roger);
42+
await users.insertOne(cruella);
4343

44-
const { insertedId } = await pongoCollection.insertOne(anita);
44+
const { insertedId } = await users.insertOne(anita);
4545
const anitaId = insertedId;
4646

4747
// Updating
4848
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } });
4949

5050
// Deleting
51-
await pongoCollection.deleteOne({ _id: cruella._id });
51+
await users.deleteOne({ _id: cruella._id });
5252

5353
// Finding by Id
54-
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId });
54+
const anitaFromDb = await users.findOne({ _id: anitaId });
5555

5656
// Finding more
57-
const users = await pongoCollection.find({ age: { $lt: 40 } });
57+
users = await users.find({ age: { $lt: 40 } });
5858
```
5959

6060
Or use MongoDB compliant shim:
@@ -77,23 +77,23 @@ const anita = { name: "Anita", age: 25 };
7777
const cruella = { _id: uuid(), name: "Cruella", age: 40 };
7878

7979
// Inserting
80-
await pongoCollection.insertOne(roger);
81-
await pongoCollection.insertOne(cruella);
80+
await users.insertOne(roger);
81+
await users.insertOne(cruella);
8282

83-
const { insertedId } = await pongoCollection.insertOne(anita);
83+
const { insertedId } = await users.insertOne(anita);
8484
const anitaId = insertedId;
8585

8686
// Updating
8787
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } });
8888

8989
// Deleting
90-
await pongoCollection.deleteOne({ _id: cruella._id });
90+
await users.deleteOne({ _id: cruella._id });
9191

9292
// Finding by Id
93-
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId });
93+
const anitaFromDb = await users.findOne({ _id: anitaId });
9494

9595
// Finding more
96-
const users = await pongoCollection.find({ age: { $lt: 40 } }).toArray();
96+
users = await users.find({ age: { $lt: 40 } }).toArray();
9797
```
9898

9999
## How does it work?
@@ -114,12 +114,9 @@ CREATE TABLE IF NOT EXISTS "YourCollectionName" (
114114
**E.g. the MongoDB update syntax:**
115115

116116
```ts
117-
const pongoCollection = pongoDb.collection<User>("users");
117+
const users = pongoDb.collection<User>("users");
118118

119-
await pongoCollection.updateOne(
120-
{ _id: someId },
121-
{ $push: { tags: "character" } }
122-
);
119+
await users.updateOne({ _id: someId }, { $push: { tags: "character" } });
123120
```
124121

125122
will be translated to:
@@ -133,7 +130,7 @@ WHERE _id = '137ef052-e41c-428b-b606-1c8070a47eda';
133130
**Or for query:**
134131

135132
```ts
136-
const result = await pongoCollection
133+
const result = await users
137134
.find({ "address.history": { $elemMatch: { street: "Elm St" } } })
138135
.toArray();
139136
```

src/docs/getting-started.md

+17-20
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,32 @@ type User = { name: string; age: number };
2727
const connectionString =
2828
'postgresql://dbuser:[email protected]:3211/mydb';
2929

30-
const pongoClient = pongoClient(connectionString);
31-
const pongoDb = pongoClient.db();
30+
const pongo = pongoClient(connectionString);
31+
const pongoDb = pongo.db();
3232

3333
const users = pongoDb.collection<User>('users');
3434
const roger = { name: 'Roger', age: 30 };
3535
const anita = { name: 'Anita', age: 25 };
3636
const cruella = { _id: uuid(), name: 'Cruella', age: 40 };
3737

3838
// Inserting
39-
await pongoCollection.insertOne(roger);
40-
await pongoCollection.insertOne(cruella);
39+
await users.insertOne(roger);
40+
await users.insertOne(cruella);
4141

42-
const { insertedId } = await pongoCollection.insertOne(anita);
42+
const { insertedId } = await users.insertOne(anita);
4343
const anitaId = insertedId;
4444

4545
// Updating
4646
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } });
4747

4848
// Deleting
49-
await pongoCollection.deleteOne({ _id: cruella._id });
49+
await users.deleteOne({ _id: cruella._id });
5050

5151
// Finding by Id
52-
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId });
52+
const anitaFromDb = await users.findOne({ _id: anitaId });
5353

5454
// Finding more
55-
const users = await pongoCollection.find({ age: { $lt: 40 } });
55+
const users = await users.find({ age: { $lt: 40 } });
5656
```
5757

5858
Or use MongoDB compliant shim:
@@ -75,23 +75,23 @@ const anita = { name: 'Anita', age: 25 };
7575
const cruella = { _id: uuid(), name: 'Cruella', age: 40 };
7676

7777
// Inserting
78-
await pongoCollection.insertOne(roger);
79-
await pongoCollection.insertOne(cruella);
78+
await users.insertOne(roger);
79+
await users.insertOne(cruella);
8080

81-
const { insertedId } = await pongoCollection.insertOne(anita);
81+
const { insertedId } = await users.insertOne(anita);
8282
const anitaId = insertedId;
8383

8484
// Updating
8585
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } });
8686

8787
// Deleting
88-
await pongoCollection.deleteOne({ _id: cruella._id });
88+
await users.deleteOne({ _id: cruella._id });
8989

9090
// Finding by Id
91-
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId });
91+
const anitaFromDb = await users.findOne({ _id: anitaId });
9292

9393
// Finding more
94-
const users = await pongoCollection.find({ age: { $lt: 40 } }).toArray();
94+
const users = await users.find({ age: { $lt: 40 } }).toArray();
9595
```
9696

9797
## How does it work?
@@ -112,12 +112,9 @@ CREATE TABLE IF NOT EXISTS "YourCollectionName" (
112112
**E.g. the MongoDB update syntax:**
113113

114114
```typescript
115-
const pongoCollection = pongoDb.collection<User>('users');
115+
const users = pongoDb.collection<User>('users');
116116

117-
await pongoCollection.updateOne(
118-
{ _id: someId },
119-
{ $push: { tags: 'character' } },
120-
);
117+
await users.updateOne({ _id: someId }, { $push: { tags: 'character' } });
121118
```
122119

123120
will be translated to:
@@ -131,7 +128,7 @@ WHERE _id = '137ef052-e41c-428b-b606-1c8070a47eda';
131128
**Or for query:**
132129

133130
```typescript
134-
const result = await pongoCollection
131+
const result = await users
135132
.find({ 'address.history': { $elemMatch: { street: 'Elm St' } } })
136133
.toArray();
137134
```

src/packages/pongo/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@
4747
"dist"
4848
],
4949
"peerDependencies": {
50+
"@types/uuid": "^9.0.8",
51+
"@types/pg": "^8.11.6",
52+
"@types/pg-format": "^1.0.5",
53+
"@types/mongodb": "^4.0.7",
5054
"pg": "^8.12.0",
5155
"pg-format": "^1.0.4",
5256
"uuid": "^9.0.1"
5357
},
5458
"devDependencies": {
55-
"@types/uuid": "^9.0.8",
56-
"@types/node": "20.11.30",
57-
"@types/pg": "^8.11.6",
58-
"@types/pg-format": "^1.0.5"
59+
"@types/node": "20.11.30"
5960
}
6061
}

src/packages/pongo/src/main/typing/operations.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export interface PongoCollection<T> {
3030

3131
export type WithId<T> = T & { _id: string };
3232

33+
export type WithoutId<T> = Omit<T, '_id'>;
34+
3335
export type PongoFilter<T> = {
34-
[P in keyof T]?: T[P] | PongoFilterOperator<T[P]>;
36+
[P in keyof T]?: WithId<T[P]> | PongoFilterOperator<T[P]>;
3537
};
3638

3739
export type PongoFilterOperator<T> = {

src/packages/pongo/src/mongo/mongoClient.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class MongoClient {
1818
await this.pongoClient.close();
1919
}
2020

21-
db(dbName: string): Db {
21+
db(dbName?: string): Db {
2222
return new Db(this.pongoClient.db(dbName));
2323
}
2424
}

0 commit comments

Comments
 (0)