AlenDavid / slonik-interceptor-json-rows

Transform slonik's QueryResultRow key into json-ready objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

test workflow

Slonik Json Interceptor

Transform slonik's QueryResultRow key into json-ready objects.

API usage

import { createPool } from 'slonik';

import JsonInterceptor from 'slonik-json-row-interceptor';

const pool = createPool(connectionString, {
  interceptors: [JsonInterceptor]
});

pool.connect(async (connection) => {
  const query = sql`select
    u.id,
    u.name,
    c.id as "cars.id",
    c.name as "cars.name"
  from
    users u
      join cars c
      on u.id = c.owner;`;

  const results = await connection.many(query);
  console.log(results); // [ { id: 1, name: 'Foo', cars: { id: 1, name: 'Bar' } } ]
});

About

Transform slonik's QueryResultRow key into json-ready objects

License:GNU General Public License v3.0


Languages

Language:TypeScript 100.0%