-
-
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
b3eaf10
commit 568cb5f
Showing
4 changed files
with
91 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { pongoSchema } from '@event-driven-io/pongo'; | ||
|
||
export type User = { _id?: string; name: string; age: number }; | ||
|
||
export default { | ||
schema: pongoSchema.client({ | ||
database: pongoSchema.db({ | ||
users: pongoSchema.collection<User>('users'), | ||
}), | ||
}), | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { pongoClient } from '@event-driven-io/pongo'; | ||
import { v4 as uuid } from 'uuid'; | ||
import config from './pongo.config'; | ||
|
||
const connectionString = | ||
'postgresql://postgres:postgres@localhost:5432/postgres'; | ||
|
||
const pongo = pongoClient(connectionString, { | ||
schema: { definition: config.schema }, | ||
}); | ||
const pongoDb = pongo.database; | ||
|
||
const users = pongoDb.users; | ||
const roger = { name: 'Roger', age: 30 }; | ||
const anita = { name: 'Anita', age: 25 }; | ||
const cruella = { _id: uuid(), name: 'Cruella', age: 40 }; | ||
|
||
// Inserting | ||
await users.insertOne(roger); | ||
await users.insertOne(cruella); | ||
|
||
const { insertedId } = await users.insertOne(anita); | ||
const anitaId = insertedId!; | ||
|
||
// Updating | ||
await users.updateOne({ _id: anitaId }, { $set: { age: 31 } }); | ||
|
||
// Deleting | ||
await users.deleteOne({ _id: cruella._id }); | ||
|
||
// Finding by Id | ||
const anitaFromDb = await users.findOne({ _id: anitaId }); | ||
console.log(JSON.stringify(anitaFromDb)); | ||
|
||
// Finding more | ||
const usersFromDB = await users.find({ age: { $lt: 40 } }); | ||
console.log(JSON.stringify(usersFromDB)); | ||
|
||
await pongo.close(); |