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

@wakit/waorm

v1.1.1

Published

ORM for javascript

Readme


Waorm (Web Applications Object-Relational Mapping) is a great way to expand your web applications to work with databases and models.

If you are building Progressive Web Applications (mobile like applications using web) it's a great way to store data and keep your application working even offline.

It's a great addition for applications built using capacitor.js (Ionic for example)

How

Waorm utilizes the IndexedDB by default, creating a simple interface for create models.

await user().find('email', '[email protected]')

Simple calls like these abstract the complex code needed to utilize a complex system like IndexedDB. Makes your code more readable and easier to use. In addition, it provides features like aggregation, inclusive searches, etc.

You can even create and use other database plugins, if you want it to interface with other techologies.

Waorm includes IndexedDB and LocalStorage, though it's certainly recommended to use IndexedDB due to the performance and no "storage limitation".

Usage

Models

Creating a model is easy! It is done by classes to make it easier to manipulate but it's super simple, just follow the example bellow:

import { Model } from '@wakit/waorm'

export default class User extends Model {
  storeName(): string {
    return 'users'
  }
}

export const user = () => (new User)

We also support typescript so here's an example of a more complex model with relationships, all typed

import { Model } from '@wakit/waorm'
import type { Resource, WaormRelationshipBag } from '@wakit/waorm'

import Todo from '~/models/todo'

export interface UserResource extends Resource {
  name: string;
  email: string;
}

export default class User extends Model<UserResource> {
  public name?: string;
  public email?: string;

  relationships(): WaormRelationshipBag {
    return {
      todos: {
        related: Todo,
        relationship: 'many',
        foreignKey: 'user_id',
      },
    }
  }

  storeName(): string {
    return 'users'
  }
}

export const user = () => (new User)

Database

In order to use your models, you need to set up the database. When initializing, by default, it sets the connection of all models to that database connection, so you don't need to keep track of your database connection. You can, of course, use a specific database connection for a specific model.

Here's an example how to setup the database>

initDB({
  name: 'MyDatabase',
  // Increment the version every time you do a change on the schema
  version: 1,
  stores: [
    {
      name: 'todos',
      indexes: [
        { name: 'user_id' },
      ],
    },
    {
      name: 'users',
      indexes: [
        { name: 'name' },
        { name: 'email', unique: true },
      ],
    },
  ],
})

Example

Here is an example setup for a simple Todo App

JavaScript


import { initDB, Model } from '@wakit/waorm'

class Todo extends Model {
  relationships() {
    return {
      user: {
        related: User,
        relationship: 'belongs',
        foreignKey: 'user_id',
      }
    }
  }

  storeName() {
    return 'todos'
  }
}

class User extends Model {
  relationships() {
    return {
      todos: {
        related: Todo,
        relationship: 'many',
        foreignKey: 'user_id',
      },
    }
  }

  storeName() {
    return 'users'
  }
}

const todo = () => (new Todo)
const user = () => (new User)

await initDB({
  name: 'TodoApp',
  version: 1,
  stores: [
    {
      name: 'todos',
      indexes: [
        { name: 'due_by' },
        { name: 'user_id' },
      ],
    },
    {
      name: 'users',
      indexes: [
        { name: 'name' },
        { name: 'email', unique: true },
      ],
    },
  ],
})

///// Using within the application /////

// Get 10 users that name doesn't include 'joao'
console.log(await user().with('todo').many('name', 'joao', { operator: 'not_includes', limit: 10 }))

const myUser = await user().find('email', '[email protected]')

await todo().hydrate({ name: 'Clean room', due_by: '2025-01-01', user_id: myUser.id }).save()

TypeScript

import { initDB, Model } from '@wakit/waorm'
import type { Resource, WaormRelationshipBag } from '@wakit/waorm'

interface TodoResource extends Resource {
  due_by: string;
  user_id: UserResource['id'];
}

interface UserResource extends Resource {
  name: string;
  email: string;
}

class Todo extends Model<TodoResource> {
  public due_by?: string;

  relationships(): WaormRelationshipBag {
    return {
      user: {
        related: User,
        relationship: 'belongs',
        foreignKey: 'user_id',
      }
    }
  }

  storeName(): string {
    return 'todos'
  }
}

class User extends Model<UserResource> {
  public name?: string;
  public email?: string;

  relationships(): WaormRelationshipBag {
    return {
      todos: {
        related: Todo,
        relationship: 'many',
        foreignKey: 'user_id',
      },
    }
  }

  storeName(): string {
    return 'users'
  }
}

const todo = () => (new Todo)
const user = () => (new User)

await initDB({
  name: 'TodoApp',
  version: 1,
  stores: [
    {
      name: 'todos',
      indexes: [
        { name: 'due_by' },
        { name: 'user_id' },
      ],
    },
    {
      name: 'users',
      indexes: [
        { name: 'name' },
        { name: 'email', unique: true },
      ],
    },
  ],
})

///// Using within the application /////

// Get 10 users that name doesn't include 'joao'
console.log(await user().with('todo').many('name', 'joao', { operator: 'not_includes', limit: 10 }))

const myUser = await user().find('email', '[email protected]')

await todo().hydrate({ name: 'Clean room', due_by: '2025-01-01', user_id: myUser.id }).save()