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

@nelts/orm

v1.0.25

Published

nelts orm

Readme

@nelts/orm

nelts架构的ORM库。

Install

npm i @nelts/orm

Configure

import { Plugin } from '@nelts/nelts';
export default async (app: Plugin) => {
  app.on('props', async configs => {
    await app.getComponent('@nelts/orm').props({
      // sequelize configs: http://docs.sequelizejs.com/manual/dialects.html
      sequelize: {
        database: configs.sequelize.database,
        username: configs.sequelize.username,
        password: configs.sequelize.password,
        options: configs.sequelize.options,
      },
      // local redis: true
      // object redis: { port, host }
      // string redis: `${host}:${port}`
      redis: '192.168.2.208:6379'
    });
  });
}

Sequelize Models

在项目目录下存在一个sequelize目录,里面指定的目录结构是这样的 sequelize/${database_name}/${table_name}.ts。每个ts文件内容请参考这里

import { sequelize } from '@nelts/orm';
const { Sequelize, Model, DataTypes } = sequelize;

export default class Maintainers extends Model {
  public id: number;
  public account: string;
  public pid: number;
  public ctime: Date;

  public static installer(sequelize: Sequelize) {
    Maintainers.init({
      id: {
        type: DataTypes.INTEGER.UNSIGNED,
        primaryKey: true,
        autoIncrement: true
      },
      account: DataTypes.STRING(100),
      pid: DataTypes.INTEGER({ length: 11 }),
      ctime: DataTypes.DATE
    }, {
      tableName: 'maintainer',
      sequelize,
      createdAt: 'ctime',
      updatedAt: 'utime',
      charset: 'utf8',
      collate: 'utf8_general_ci',
    });
  }
}

public static installer(sequelize: Sequelize) 函数必须存在,定义创建表的结构。

Redis

Redis是存在于 ctx.redis 上。

Redis operations

  • set(key: string, obj: any, expire?: number): Promise<void>;
  • get(key: string): Promise<any>;
  • exists(key: string): Promise<any>;
  • delete(key: string): Promise<any>;
  • clear(): Promise<void>;

具体请看 /src/redis.ts 源码。

Use Cacheable in service

import { Component, Context } from '@nelts/nelts';
import { Cacheable, CacheableInterface } from '../index';
export default class IndexService extends Component.Service {
  constructor(ctx: Context) {
    super(ctx);
  }

  @Cacheable('/test/:id(\\d+)')
  async valid() {
    return await this.ctx.dbomaintainer.findAll({
      attributes: ['id', 'pid', 'account', 'ctime']
    });
  }

  async get() {
    const obj: CacheableInterface = await this.valid();
    return await obj.get({ id: 123 });
  }
}

@Cacheable('/test/:id(\\d+)')注解指定service的方法valid是一个缓存函数。那么可以如下调用:

// eg: in controller
const service = new this.service.IndexService(ctx);
const obj: CacheableInterface = await service.valid();
const result = await obj.invoke();
const result = await obj.set({ id: 234 }, 10000);
const result = await obj.get({ id: 234 }, 10000);
await obj.delete({ id: 234 });

License

MIT

Copyright (c) 2019-present, yunjie (Evio) shen