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 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-nohm

v1.0.1

Published

[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down

Downloads

1

Readme

egg-nohm

NPM version build status Test coverage David deps Known Vulnerabilities npm download

为什么有这个插件

  • 让nohm支持ioredis,egg官方提供的是ioredis,更容易集成.
  • 让nohm的api promise化

Install

$ npm i egg-nohm --save

Usage

nohm 详细请看https://github.com/maritz/nohm

// 模型定义,app/nohm/model目录下的文件会自动加载
// app/nohm/model/ObjModel.js
const nohm = require('nohm').Nohm;
// 别忘记了module.exports =.   
module.exports = nohm.model('ObjectModel', {
  properties: {
    nickName: {
      type: 'string',
    },
    currentSong: {
      type: 'json',
    },
    currentListType: {
      type: 'string',
      defaultValue: 'local',
    },
    localList: {
      type: 'json',
      defaultValue: { items: [] },
    },
    playList: {
      type: 'json',
      defaultValue: { items: [] },
    },
  },
});

//也可以
// app/nohm/model/PlayingSong.js
const nohm = require('nohm').Nohm;

module.exports = app => {
  const PlayingSong = nohm.model('PlayingSong', {
    properties: {
      nickName: {
        type: 'string',
      },
      currentSong: {
        type: 'json',
      },
      currentListType: {
        type: 'string',
        defaultValue: 'local',
      },
      localList: {
        type: 'json',
        defaultValue: { items: [] },
      },
      playList: {
        type: 'json',
        defaultValue: { items: [] },
      },
    },
  });
  return PlayingSong;
};
// 所有app/nohm/model下的文件会加载到app.nohmModel
 const PlayingSong = app.nohmModel.PlayingSong;
    const ps = new PlayingSong();
    ps.id = 'abc';
    const nickName = 'who am i ';
    ps.p({
      nickName,
    });
    yield ps.save$();
    const data = yield PlayingSong.load$(ps.id);
    assert(data.nickName === nickName);
    yield PlayingSong.remove$(ps.id);
// {app_root}/config/plugin.js
exports.redis = {
  enable: true,
  package: 'egg-redis',
};

exports.nohm = {
  enable: true,
  package: 'egg-nohm',
};

promise

nohm中的方法以$结尾的都promisify了. 如原方法save, 会另外增加一个save$返回promise

Configuration

// {app_root}/config/config.default.js
exports.redis = {
  client: {
    host: '127.0.0.1',
    port: 6379,
    password: '',
    db: '0',
  },
};
exports.nohm = {
};

save id分配的问题

如果你期望下面的代码

var model=new SomeNohmModel()  
model.id='abcd'
model.save()

不管这里的id存在还是不存在,都以这个id保存到redis中. 如果存在id='abcd'的,就更新. 如果不存在新插入对象的id还是等于'abcd'.请加下面的配置.

idGenerator (cb) {
      cb(this.id)
    }

因为nohm默认的行为是

  •  如果id不填,自动生成一个不重复的
  •  如果id有值,会进一步的到数据库中验证这个值存在不,不存在他还是会自动生成一个新值代替你填入的id的

配置项目请看

see config/config.default.js for more detail.

Example

Questions & Suggestions

Please open an issue here.

License

MIT