-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added peer dependency to pg and uuid types
Adjusted also README to show proper samples
- Loading branch information
1 parent
02260b5
commit ac7df28
Showing
5 changed files
with
43 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,32 +29,32 @@ type User = { name: string; age: number }; | |
const connectionString = | ||
"postgresql://dbuser:[email protected]:3211/mydb"; | ||
|
||
const pongoClient = pongoClient(connectionString); | ||
const pongoDb = pongoClient.db(); | ||
const pongo = pongoClient(connectionString); | ||
const pongoDb = pongo.db(); | ||
|
||
const users = pongoDb.collection<User>("users"); | ||
const roger = { name: "Roger", age: 30 }; | ||
const anita = { name: "Anita", age: 25 }; | ||
const cruella = { _id: uuid(), name: "Cruella", age: 40 }; | ||
|
||
// Inserting | ||
await pongoCollection.insertOne(roger); | ||
await pongoCollection.insertOne(cruella); | ||
await users.insertOne(roger); | ||
await users.insertOne(cruella); | ||
|
||
const { insertedId } = await pongoCollection.insertOne(anita); | ||
const { insertedId } = await users.insertOne(anita); | ||
const anitaId = insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
await users.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
const anitaFromDb = await users.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }); | ||
users = await users.find({ age: { $lt: 40 } }); | ||
``` | ||
|
||
Or use MongoDB compliant shim: | ||
|
@@ -77,23 +77,23 @@ const anita = { name: "Anita", age: 25 }; | |
const cruella = { _id: uuid(), name: "Cruella", age: 40 }; | ||
|
||
// Inserting | ||
await pongoCollection.insertOne(roger); | ||
await pongoCollection.insertOne(cruella); | ||
await users.insertOne(roger); | ||
await users.insertOne(cruella); | ||
|
||
const { insertedId } = await pongoCollection.insertOne(anita); | ||
const { insertedId } = await users.insertOne(anita); | ||
const anitaId = insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
await users.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
const anitaFromDb = await users.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }).toArray(); | ||
users = await users.find({ age: { $lt: 40 } }).toArray(); | ||
``` | ||
|
||
## How does it work? | ||
|
@@ -114,12 +114,9 @@ CREATE TABLE IF NOT EXISTS "YourCollectionName" ( | |
**E.g. the MongoDB update syntax:** | ||
|
||
```ts | ||
const pongoCollection = pongoDb.collection<User>("users"); | ||
const users = pongoDb.collection<User>("users"); | ||
|
||
await pongoCollection.updateOne( | ||
{ _id: someId }, | ||
{ $push: { tags: "character" } } | ||
); | ||
await users.updateOne({ _id: someId }, { $push: { tags: "character" } }); | ||
``` | ||
|
||
will be translated to: | ||
|
@@ -133,7 +130,7 @@ WHERE _id = '137ef052-e41c-428b-b606-1c8070a47eda'; | |
**Or for query:** | ||
|
||
```ts | ||
const result = await pongoCollection | ||
const result = await users | ||
.find({ "address.history": { $elemMatch: { street: "Elm St" } } }) | ||
.toArray(); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,32 +27,32 @@ type User = { name: string; age: number }; | |
const connectionString = | ||
'postgresql://dbuser:[email protected]:3211/mydb'; | ||
|
||
const pongoClient = pongoClient(connectionString); | ||
const pongoDb = pongoClient.db(); | ||
const pongo = pongoClient(connectionString); | ||
const pongoDb = pongo.db(); | ||
|
||
const users = pongoDb.collection<User>('users'); | ||
const roger = { name: 'Roger', age: 30 }; | ||
const anita = { name: 'Anita', age: 25 }; | ||
const cruella = { _id: uuid(), name: 'Cruella', age: 40 }; | ||
|
||
// Inserting | ||
await pongoCollection.insertOne(roger); | ||
await pongoCollection.insertOne(cruella); | ||
await users.insertOne(roger); | ||
await users.insertOne(cruella); | ||
|
||
const { insertedId } = await pongoCollection.insertOne(anita); | ||
const { insertedId } = await users.insertOne(anita); | ||
const anitaId = insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
await users.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
const anitaFromDb = await users.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }); | ||
const users = await users.find({ age: { $lt: 40 } }); | ||
``` | ||
|
||
Or use MongoDB compliant shim: | ||
|
@@ -75,23 +75,23 @@ const anita = { name: 'Anita', age: 25 }; | |
const cruella = { _id: uuid(), name: 'Cruella', age: 40 }; | ||
|
||
// Inserting | ||
await pongoCollection.insertOne(roger); | ||
await pongoCollection.insertOne(cruella); | ||
await users.insertOne(roger); | ||
await users.insertOne(cruella); | ||
|
||
const { insertedId } = await pongoCollection.insertOne(anita); | ||
const { insertedId } = await users.insertOne(anita); | ||
const anitaId = insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
await users.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
const anitaFromDb = await users.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }).toArray(); | ||
const users = await users.find({ age: { $lt: 40 } }).toArray(); | ||
``` | ||
|
||
## How does it work? | ||
|
@@ -112,12 +112,9 @@ CREATE TABLE IF NOT EXISTS "YourCollectionName" ( | |
**E.g. the MongoDB update syntax:** | ||
|
||
```typescript | ||
const pongoCollection = pongoDb.collection<User>('users'); | ||
const users = pongoDb.collection<User>('users'); | ||
|
||
await pongoCollection.updateOne( | ||
{ _id: someId }, | ||
{ $push: { tags: 'character' } }, | ||
); | ||
await users.updateOne({ _id: someId }, { $push: { tags: 'character' } }); | ||
``` | ||
|
||
will be translated to: | ||
|
@@ -131,7 +128,7 @@ WHERE _id = '137ef052-e41c-428b-b606-1c8070a47eda'; | |
**Or for query:** | ||
|
||
```typescript | ||
const result = await pongoCollection | ||
const result = await users | ||
.find({ 'address.history': { $elemMatch: { street: 'Elm St' } } }) | ||
.toArray(); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters