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

orm-adapter

v0.0.11

Published

A javascript orm that adapts other orms in decorator base orm in Typescirpt.

Downloads

45

Readme

orm-adapter

An npm package that adapts other orms into a decorator based orm. Currently supports:

1- DynamoDB
2- Js-data
3- BookShelf
4- Mongoose
5- Custom

Supported API fields:

1- @Entity() or @Entity(OrmType.<Select_Orm>, OrmConfig): Creates the database model using the defined Orm or in case of passing the parameters it will used the configurations passed.
2- @column() or @column(params): Creates a column in the model. The params are optional and the can veary depending on the orm used.
3- @id: Creates a column as well as identifies as id for quiries and updates.
4- @key: Creates a column as well as identifies as secondary id for quiries and updates.
5- @hasMany: creates a one to many relationship. Will be fully functional next release.
6- @belongsTo: creates a one to one relationship. Will be fully functional next release.
7- @beforeCreate: runs function before saving model to database.
8- @afterCreate: runs function after saving model to database.
9- @beforeUpdate: runs function before updating model in the database.
10- @afterUpdate: runs function after updating model in the database.
11- @beforeDelete: runs function before deleting model in the database.
12- @afterDelete: runs function after deleting model in the database.

Creating models:

import { column, id, Entity } from 'orm-adapter';
@Entity()
class User {
  @id()
  username: string;
  @column()
  firstName: string;
  @column()
  lastName: string;
  @column()
  email: string;
}
That will simply create a user model using any orm or custom database connector and connection.

You can also create different models using different orms:

User.ts

import { column, id, Entity } from 'orm-adapter';
@Entity()
class User {
  @id()
  username: string;
  @column()
  firstName: string;
  @column()
  lastName: string;
  @column()
  email: string;
}

Nerd.ts

import { Schema, Container } from 'js-data';
import { MongoDBAdapter } from 'js-data-mongodb';
import { column, id, Entity } from 'orm-adapter';
@Entity(JS_DATA,
        <JsDataConfig>{ Schema: Schema,
                        Adapter: MongoDBAdapter,
                        adapterConfig: { uri: 'mongodb://localhost:27017' },
                        adapterName: "mongodb",
                        Container: Container })
class Nerd {
  @id()
  realName: string;
  @column()
  alterEgo: string;
  @column()
  cursh: string;
}

User will be created using the global orm and Nerd will be created using js-data.

Life hooks Support?:

import { column, id, 
         Entity,
         beforeCreate,
         afterCreate,
         beforeUpdate,
         afterUpdate,
         beforeDelete,
         afterDelete } from 'orm-adapter';

@Entity()
class Nerd {
  @id()
  realName: string;
  @column()
  alterEgo: string;
  @column()
  cursh: string;
  // lets help our friend out.
  @beforeCreate()
  initialize() {
    // Do some real work then joke a little:
    console.log('You have no chance buddy.');
  }
  @afterCreate()
  ready (data: any) {
    // Do real job with the data.
    console.log(data);
  }
  
  @beforeUpdate()
  myMan() {
    // Do some real work then joke a little:
    console.log('You still have no chance buddy.')
  }
  @afterUpdate()
  newMan (data: any) {
    // Do real job with the data.
    console.log(data);
  }
  
  @beforeDelete()
  beforeRest() {
    // Do some real work then joke a little:
    console.log('High five');
  }
  @afterDelete()
  afterRest (data: any) {
    // Do real job with the data.
    console.log(data);
  }
}

The api also supports multiple helpful properties:

import { column, id, Entity,
         key, passwordField,
         ignore, hasMany,
         belongsTo } from 'orm-adapter';

@Entity()
class User {
  @id()
  username: string;
  @column()
  firstName: string;
  @column()
  lastName: string;
  @key()
  email: string;
  @ignore()
  deepSecret: string;
  @passwordField()
  password: string;
  @hasMany(Friend /*or 'Friend'*/)
  friends: Friend[];
  @belongsTo(Friend /*or 'Friend'*/)
  bestFriend: Friend;
}

API usage:

import { getGlobalConnector } from 'orm-adapter';

// Getting all users.
getGlobalConnector()
.then(conn => conn.getRepository(User).findAll())

// Getting a user by id = 11.
getGlobalConnector()
.then(conn => conn.getRepository(User).findById(11))

// Getting a user by a param: firstName = 'sal'.
getGlobalConnector()
.then(conn => conn.getRepository(User).findByKey({firstName: 'sal'}))

// Save a user.
getGlobalConnector()
.then(conn => conn.getRepository(User).save(new User(/* pass your params*/))

// Update a user.
getGlobalConnector()
.then(conn => conn.getRepository(User).update(someUser))

// Update a user by id.
getGlobalConnector()
.then(conn => conn.getRepository(User).updateById(11,someUser))

// Delete a user.
getGlobalConnector()
.then(conn => conn.getRepository(User).delete(someUser))

// Delete a user by id.
getGlobalConnector()
.then(conn => conn.getRepository(User).deleteById(11))