event-driven-io / emmett

Emmett - a Node.js library taking your event-driven applications back to the future!
https://event-driven-io.github.io/emmett/
199 stars 19 forks source link

Added raw sql projections to support raw SQL handling #102

Closed oskardudycz closed 3 months ago

oskardudycz commented 3 months ago

Generalised also projection definition.

Made postgreSQLProjection and inlineProjection obsolete, use postgreSQLProjection and postgreSQLInlineProjection instead.

Now you can use the new projections raw projection as:

import { postgreSQLRawSQLProjection } from '@event-driven-io/emmett-postgresql';

const rawSQLProjection = postgreSQLRawSQLProjection<ProductItemAdded>({
  name: 'customProjection',
  canHandle: ['ProductItemAdded'],
  handle: (event, context) => sql('INSERT INTO product_items VALUES(%s, %L, %L)', event.productId, event.quantity))
});

There's also postgreSQLRawBatchSQLProjection that handles a batch of events accordingly. Both can be sync or async. You can access and query the database through the context handler param.

Fixes #97

oskardudycz commented 3 months ago

@jameswoodley FYI