-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2acddeb
commit 1fe557b
Showing
8 changed files
with
106 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,94 @@ | |
|
||
![](/logo.png) | ||
|
||
TODO | ||
Pongo is a MongoDB on Postgres with all strong consistency benefits. | ||
|
||
Install Pongo as an npm module and save it to your package.json | ||
|
||
```bash | ||
npm install @event-driven-io/pongo | ||
``` | ||
|
||
## Example | ||
|
||
You can use Pongo syntax with explicit typing about supported syntax: | ||
|
||
```ts | ||
import { pongoClient } from '@event-driven-io/pongo'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
type User = { name: string; age: number }; | ||
|
||
const connectionString = | ||
'postgresql://dbuser:[email protected]:3211/mydb'; | ||
|
||
const pongoClient = pongoClient(postgresConnectionString); | ||
const pongoDb = pongoClient.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); | ||
|
||
let inserted = await pongoCollection.insertOne(alice); | ||
const anitaId = inserted.insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }); | ||
``` | ||
|
||
Or use MongoDB compliant shim: | ||
|
||
```ts | ||
import { MongoClient } from '@event-driven-io/pongo'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
type User = { name: string; age: number }; | ||
|
||
const connectionString = | ||
'postgresql://dbuser:[email protected]:3211/mydb'; | ||
|
||
const pongoClient = new MongoClient(postgresConnectionString); | ||
const pongoDb = pongoClient.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); | ||
|
||
let inserted = await pongoCollection.insertOne(alice); | ||
const anitaId = inserted.insertedId; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await pongoCollection.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await pongoCollection.findOne({ _id: anitaId }); | ||
|
||
// Finding more | ||
const users = await pongoCollection.find({ age: { $lt: 40 } }).toArray(); | ||
``` | ||
|
||
## Is it production ready? | ||
|
||
What's there it's safe to use, but it's far from being 100% compliant with MongoDB. |
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.