Pongo - Mongo but on Postgres and with strong consistency benefits
MIT License
Bot releases are hidden (Show)
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.3...0.14.4
Published by oskardudycz about 1 month ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.2...0.14.3
Published by oskardudycz about 1 month ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.1...0.14.2
Published by oskardudycz about 1 month ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.0...0.14.1
Published by oskardudycz about 1 month ago
You can either install it globally through:
npm install -g @event-driven-io/pongo
And run it with:
pongo
or without installing it globally by using npx
npx @event-driven-io/pongo
by @oskardudycz in 78
Now, if youdefine schema like:
type User = {
_id?: string;
name: string;
age: number;
address?: Address;
tags?: string[];
};
const schema = pongoSchema.client({
database: pongoSchema.db({
users: pongoSchema.collection<User>('users'),
customers: pongoSchema.collection<Customer>('customers'),
}),
});
And pass it to the client, getting the typed version.
const typedClient = pongoClient(postgresConnectionString, {
schema: { definition: schema },
});
// 👇 client have the same database as we defined above, and the collection
const users = typedClient.database.users;
const doc: User = {
_id: randomUUUID(),
name: 'Anita',
age: 25,
};
const inserted = await users.insertOne(doc);
// 👇 yup, the collection is fully typed!
const pongoDoc = await users.findOne({
name: 'Anita'
});
You can generate the sample config by calling:
npx @event-driven-io/pongo config sample --generate --file ./dist/pongoConfig.js --collection users --collection orders
Or just print it with:
npx @event-driven-io/pongo config sample --print --collection users --collection customers
Then, you can use existing or adjust generated typing and import it to your application.
by @oskardudycz in 73
You can run it based on your config file with:
npx @event-driven-io/pongo migrate run --config ./pongoConfig.ts \
--connectionString postgresql://postgres:postgres@localhost:5432/postgres
It'll automatically run the migrations based on the defined collections. Running multiple times is safe, as migration will be only run once.
Instead of passing the connection string as param, you can also set DB_CONNECTION_STRING
environment variable and run it as
npx @event-driven-io/pongo migrate run --config ./pongoConfig.ts
You can also run it by providing a collections list:
npx @event-driven-io/pongo migrate run --collection users --collection customers \
--connectionString postgresql://postgres:postgres@localhost:5432/postgres
If you want to try it, first add the --dryRun
param, and it'll run the migration in the transaction and roll it back without making changes.
You can also see what will be generated by calling:
npx @event-driven-io/pongo migrate sql --print --collection users --collection customers
If you run migrations manually, you can ignore the automated migration in Pongo client and get the performance boost:
const typedClient = pongoClient(postgresConnectionString, {
schema: { autoMigration: 'CreateOrUpdate', definition: schema },
});
Schema components define the database schema as a tree structure. They're used for database collection, allowing migration through code. They're exposed in schema
property. In the longer term it'll be possible to add your own like indexes, migrations etc.
Now you can use it also in your application; you can use them through:
import { dumbo, AdvisoryLock } from '@event-driven-io/dumbo';
const pool = dumbo({ connectionString });
const carName = await AdvisoryLock.withAcquire(
pool.execute,
() => single(pool.execute.query<{name:string}>(rawSql(`SELECT name FROM cars LIMIT 1;`))),
{ lockId: 1023 },
);
Internally they're used to ensure that there are no parallel migrations being run.
by @oskardudycz in 74
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.13.1...0.14.0
Published by oskardudycz about 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.13.0...0.13.1
Published by oskardudycz about 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.5...0.13.0
Published by oskardudycz about 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.4...0.12.5
Published by oskardudycz 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.3...0.12.4
Published by oskardudycz 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.2...0.12.3
Published by oskardudycz 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.1...0.12.2
Published by oskardudycz 2 months ago
findOne
, countDocuments
and other queries that don't have a filter by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/58
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.0...0.12.1
Published by oskardudycz 2 months ago
pg-format
directly into dumbo It's working but is not maintained and is causing compatibility issues in Cloudflare Workers. Eventually, we'll need something smarter and modern, e.g. like PostgreSQL SQL template literal. by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/57
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.11.0...0.12.0
Published by oskardudycz 2 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.10.0...0.11.0
Published by oskardudycz 2 months ago
Refactored pooling, connection, transaction setup. Most of the work was made in Dumbo to enable future use of other databases or PostgreSQL drivers.
Now Dumbo should be usable even as a standalone package. You can do the following:
import { dumbo, rawSql } from '@event-driven-io/dumbo';
const pool = dumbo({ connectionString });
const result = await pool.execute.query<User>(rawSql('SELECT * from users'));
or with transactions:
import { dumbo, sql } from '@event-driven-io/dumbo';
const userId = 32;
const userName = "[email protected]";
const pool = dumbo({ connectionString });
await pool.withTransaction(async ({ execute }) => {
await execute.command(sql('INSERT INTO users VALUES(%s, %L)', userId, userName));
await execute.command(sql('INSERT INTO user_roles VALUES(%s, %L)', userId, 'admin') );
})
You can now also share the connection and transaction between your tool and Pongo, e.g. by doing:
import { dumbo, sql } from '@event-driven-io/dumbo';
const userId = 32;
const userName = "[email protected]";
const pool = dumbo({ connectionString });
await pool.withTransaction(async ({ execute }) => {
// sharing transaction connection with pongo
const pongo = pongoClient(connectionString, { connection });
const users = pongo.db().collection<User>('users');
await users.insertOne({ name: randomUUID() });
await users.insertOne({ name: randomUUID() });
// doing also insert outside of pongo
await execute.command(sql('INSERT INTO user_roles VALUES(%s, %L)', userId, 'admin') );
})
That will be a basis for extended integration between Pongo and Emmett. A new projection type will be easier to add (e.g. for doing custom SQL based on events).
by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/54
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.9.0...0.10.0
Published by oskardudycz 3 months ago
{ pooled: false }
options to Pongo Client creation. Now, for database hostings with internal pooling (e.g. Cloudflare HyperDriver, Supabase, Neon), you can just disable default pooling by this simple setting. by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/40
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.8.0...0.9.0
Published by oskardudycz 3 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.7.0...0.8.0
Published by oskardudycz 3 months ago
pg.PoolClient
I made mishap earlier and not exposed it fully. by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/34
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.6.1...0.7.0
Published by oskardudycz 3 months ago
Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.6.0...0.6.1
Published by oskardudycz 3 months ago
Something went wrong with 0.5.0
publishing, had to republish again 🤦♂️