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 🙏

© 2025 – Pkg Stats / Ryan Hefner

webiny-entity

v1.15.1

Published

A simple but powerful multi-storage ORM / ODM.

Downloads

143

Readme

code style: prettier PRs Welcome

As the name already suggests, provides a way to work with entities that are part of your business logic. The component can be categorized as both ORM and ODM, because essentially it can work with any type of database, be it SQL, NoSQL or even browser's local storage if needed. It's just a matter of using a specific driver, and you're good to go.

Webiny currently provides the MongoDB official driver. Additional drivers may be added (eg. MongoDB) as the need arises in the near future.

For more information, please visit the official docs.

Install

npm install --save webiny-entity

Or if you prefer yarn:

yarn add webiny-entity

Usage

In general, the first step in defining a new entity is to extend a base Entity class, and then define attributes in class constructor. To quickly get an impression on how it works, please consider the following examples:

import User from "./user.entity.js";

const data = {
  email: "john.doe@webiny.com",
  password: "12345678",
  firstName: "John",
  lastName: "Doe",
  age: 30,
  enabled: true,
  company: { name: "A test company", type: "it" }
};

const user = new User();
user.populate(data);
await user.save();

Only one thing is missing here, and that is to assign an instance of Driver. Let's use MongoDB driver so that Entity component knows how to work with a real database. To do that, on top of the file add:

import MongoDbDriver from "webiny-entity-mongodb";
import { Entity } from "webiny-entity";

Entity.driver = new MongoDBDriver({ connection });

So the full code would be:

import { Entity } from "webiny-entity";
import Company from "./company.entity.js";
import MongoDbDriver from "webiny-entity-mongodb";

Entity.driver = new MongoDBDriver({ connection });

class User extends Entity {
    constructor() {
        super();
        this.attr("email")
            .char()
            .setValidators("required,email")
            .onSet(value => value.toLowerCase().trim());

        this.attr("password")
            .password()
            .setValidators("required");
            
        this.attr("firstName").char();
        this.attr("lastName").char();
        this.attr("age").integer();
        this.attr("enabled").boolean();
        
        this.attr("company")
            .entity(Company)
            .setValidators("required");
    }
}

User.classId = "User";

export default User;

Shown examples are demonstrating basic usage of the Entity component.

Entity pool

Entity pool is simply a local entity cache, which holds entities in memory until the process ends (or manually flushed).

Once an entity has been created or loaded from database, it will immediately be added to it. Then in later stages, when trying to load entities using findById, findByIds or find method, entities will be returned from entity pool if possible, thus preventing additional database queries.

Custom Entity Pool

By default, entities will be held in memory until the process has finished. If this is not appropriate, custom entity pool can be implemented. One example is implementing a per-request entity pool, in which entities would be held in it while the request is active. Once finished, pool would be emptied.

You can assign a custom entity pool using pool static class property.