Pongo

Pongo - Mongo but on Postgres and with strong consistency benefits

MIT License

Downloads
2K
Stars
1.2K

Bot releases are visible (Hide)

Pongo - 0.14.4 Latest Release

Published by oskardudycz about 1 month ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.3...0.14.4

Pongo - 0.14.3

Published by oskardudycz about 1 month ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.2...0.14.3

Pongo - 0.14.2

Published by oskardudycz about 1 month ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.1...0.14.2

Pongo - 0.14.1

Published by oskardudycz about 1 month ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.14.0...0.14.1

Pongo - 0.14.0

Published by oskardudycz about 1 month ago

🚀 What's New

1. Added pongo CLI tool.

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

2. Added strongly-typed client.

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

3. Added capability to run database migrations

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

4. Added possibility to disable generating Pongo schema upfront

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 },
});

by @oskardudycz in 71, 72

5. Added option to define Schema Components

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.

by @oskardudycz in 75, 77

6. Added PostgreSQL AdvisoryLocks in Dumbo

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

Pongo - 0.13.1

Published by oskardudycz about 2 months ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.13.0...0.13.1

Pongo - 0.13.0

Published by oskardudycz about 2 months ago

🚀 What's New

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.5...0.13.0

Pongo - 0.12.5

Published by oskardudycz about 2 months ago

📝 What's Changed

  • Fixed pool with ambient connection when pooled is set to false Previously, it wasn't using dumbo connection but falling back to non-pooled mode recreating pg connection on each request by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/64

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.4...0.12.5

Pongo - 0.12.4

Published by oskardudycz 2 months ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.3...0.12.4

Pongo - 0.12.3

Published by oskardudycz 2 months ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.2...0.12.3

Pongo - 0.12.2

Published by oskardudycz 2 months ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.1...0.12.2

Pongo - 0.12.1

Published by oskardudycz 2 months ago

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.12.0...0.12.1

Pongo - 0.12.0

Published by oskardudycz 2 months ago

🚀 What's New

  • Ported 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

Pongo - 0.11.0

Published by oskardudycz 2 months ago

🚀 What's New

  • Moved shim to separate bundle to remove automatic dependency to MongoDB package. Now it won't be always loading. Loading it automatically caused compatibility issues in Cloudflare Workers, plus increased bundle size. Now you can access it by `@event-driven-io/pongo/shim' by @oskardudycz in https://github.com/event-driven-io/Pongo/pull/56

📝 What's Changed

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.10.0...0.11.0

Pongo - 0.10.0

Published by oskardudycz 2 months ago

🚀 What's New

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

Pongo - 0.9.0

Published by oskardudycz 3 months ago

🚀 What's New

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.8.0...0.9.0

Pongo - 0.8.0

Published by oskardudycz 3 months ago

🚀 What's New

📄 Docs

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.7.0...0.8.0

Pongo - 0.7.0

Published by oskardudycz 3 months ago

🚀 What's New

Full Changelog: https://github.com/event-driven-io/Pongo/compare/0.6.1...0.7.0

Pongo - 0.6.1

Published by oskardudycz 3 months ago

Pongo - 0.6.0

Published by oskardudycz 3 months ago

Something went wrong with 0.5.0 publishing, had to republish again 🤦‍♂️