npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

typeorm-deserializer

v1.0.2

Published

Allows to deserialize TypeORM entities from raw queries

Readme

Description

Allows to deserialize TypeORM entities from raw queries.

Installation

npm i typeorm-deserializer

Usage

Query

SELECT person.id AS person_id, person.name AS person_name, 
       town.id AS town_id, town.name AS town_name, 
       country.id AS country_id, country.name AS country_name, 
       food.id AS food_id, food.name as food_name 
FROM person
JOIN town ON town.id = person.lives_in_town_id
JOIN country ON country.id = town.country_id
JOIN LATERAL (
  SELECT * FROM food
  JOIN person_favorite_food_food ON person_favorite_food_food.food_id = food.id AND person_favorite_food_food.person_id = person.id
	ORDER BY random()
	LIMIT 1
) food ON true
WHERE town.population > 5;

Code

import { deserializeEntities } from 'typeorm-deserializer';

...
const rows = await mgr.query(queryString);
const entities = deserializeEntities(dataSource, Person, rows, {
  alias: 'person',
  relations: {
    livesInTown: {
      alias: 'town',
      relations: {
        country: 'country'
      }
    },
    favoriteFood: 'food'
  }
});

Entities

@Entity()
export class Person {
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @Column()
  name: string;
  @ManyToOne(() => Town, town => town.people)
  livesInTown: Town;
  @JoinTable()
  @ManyToMany(() => Food, food => food.people)
  favoriteFood: Food[];
}
@Entity()
export class Country {
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @Column()
  name: string;
}
@Entity()
export class Food {
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @Column()
  name: string;
  @ManyToMany(() => Person, person => person.favoriteFood)
  people: Person[];
}
@Entity()
export class Town {
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @Column()
  name: string;
  @Column()
  population: number;
  @ManyToOne(() => Country)
  country: Country;
  @OneToMany(() => Person, person => person.livesInTown)
  people: Person[];
}

Result

[
  Person {
    id: '70108e53-da6d-40f4-a132-9f129df3693b',
    name: 'John',
    livesInTown: Town {
      id: '1a8ffe23-fa1d-4229-8d63-7de292c5505f',
      name: 'London',
      country: Country {
        id: 'c0c78bde-47fb-45db-bbf6-d63f0ce39fbc',
        name: 'UK'
      }
    },
    favoriteFood: [
      Food {
        id: '8a5a3c40-b69e-4fc8-a168-39ab10d63761',
        name: 'salad'
      }
    ]
  },
  Person {
    id: 'e9c50888-0fd8-40dd-88a9-1d3b4d2fd138',
    name: 'Kristin',
    livesInTown: Town {
      id: '1a8ffe23-fa1d-4229-8d63-7de292c5505f',
      name: 'London',
      country: Country {
        id: 'c0c78bde-47fb-45db-bbf6-d63f0ce39fbc',
        name: 'UK'
      }
    },
    favoriteFood: [
      Food { id: 'bceba7c3-fc14-4d51-8954-bf61bae4f048', name: 'tuna' }
    ]
  },
  Person {
    id: '2dc28b66-ec1f-4e89-bf9c-7ab3f68a4c0e',
    name: 'Diego',
    livesInTown: Town {
      id: '1a8ffe23-fa1d-4229-8d63-7de292c5505f',
      name: 'London',
      country: Country {
        id: 'c0c78bde-47fb-45db-bbf6-d63f0ce39fbc',
        name: 'UK'
      }
    },
    favoriteFood: [
      Food {
        id: '241cb138-b159-4463-af62-f70300e5fee2',
        name: 'pizza'
      }
    ]
  },
  Person {
    id: '1a339cde-a900-4861-af80-2ee3436f9690',
    name: 'Sergej',
    livesInTown: Town {
      id: 'e4b31df5-1346-4ff9-81b2-d90429f3ebba',
      name: 'New York',
      country: Country {
        id: '074f35df-83f1-4ec5-b178-5dc9376c11ab',
        name: 'USA'
      }
    },
    favoriteFood: [
      Food {
        id: '628803c1-dbbe-4be2-b4b3-a16fee4f744c',
        name: 'curry'
      }
    ]
  },
  Person {
    id: '566ae208-26cb-4e4a-a5cb-6a2f715869f3',
    name: 'Clara',
    livesInTown: Town {
      id: '950b7160-a3f1-491f-83c2-395dcc81a62a',
      name: 'Tokyo',
      country: Country {
        id: '7da830ae-3d3c-4204-b015-f92c75ee2374',
        name: 'Japan'
      }
    },
    favoriteFood: [
      Food {
        id: '241cb138-b159-4463-af62-f70300e5fee2',
        name: 'pizza'
      }
    ]
  }
]

Local Testing

PostgreSQL Setup

Local installation of PostgreSQL is required to run local tests.
Environment variables used by tests:

POSTGRES_HOST
POSTGRES_PORT
POSTGRES_USERNAME
POSTGRES_PASSWORD
POSTGRES_DATABASE

SQLite setup

None required as SQLite runs in memory.

Running Tests

npm run test