pg-mem and uuid_generate_v4() mock

pg-mem and uuid_generate_v4() mock

pg-mem is an open-source project for javascript (works in Node.js and the browser) where you can mock a Postgres server in memory, is pretty cool to use it on unit and local tests.

And it comes with its own limitations, by default, pg-mem has no native extensions.

The most common I use is the uuid_generate_v4 as default for the records ids, to emulate the same behavior on pg-mem here is the code:

  import { v4 } from 'uuid';

  db.registerExtension('uuid-ossp', (schema) => {
      name: 'uuid_generate_v4',
      returns: DataType.uuid,
      implementation: v4,
      impure: true,

More information on the GitHub project