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

node-entities

v2.1.8

Published

this is a less mysql orm

Readme

entities

this is a less mysql for node orm

安装

简介

这是一个简单的node orm

模仿mongoose的链式调用。

并开放原生query函数,当此工具无法满足业务需求或原生sql语句更简洁时使用

entities是为单位项目开发的简单node orm,仅仅适用于mysql数据库,

功能不多,没有数据库与数据表的创建,没有mapping配置

entities基于约定大于配置思想,以命名约定实现mapping映射

entities的功能实现了数据库的增删改查与事物的增删改查功能,增加操作可单条或多条同时增加,修改与删除的都是基于条件参数的

主要扩展的功能是查询,增加findOnecount函数,实现获取单条与长度。对于复杂查询对SQL对象增加andjoin函数实现多表联合查询,并可再where函数中统一配置对外参数查询

entities依赖于mysql库,增删改的返回值现都为mysql的返回结果,并未封装

entities的依赖:

使用方法

var factoryMaster = require('node-entities');

// 定义模型
var models = {
    test: function Test() {
        this.name = {
            type: String
        };
        this.id = {
            type: Number
        };
        this.deScription = {
            type: String
        };
    }
};

// 初始化,并返回工厂构造器 
var Factory = factoryMaster.init({
    host: 'your mysql host',
    port: 8292,
    user: 'your mysql user',
    password: 'your mysql pwd',
    database: 'your mysql db',
    connectionLimit: 20,
    supportBigNumbers: true
}, models);



// 查询
var getTest = function(query) {

    var factory = new Factory();
    factory.find("test", {
        id: {      //  或 id: 57
            value: 57,
            type: "="
        }
    }, {
        id: "testId"
    }, function(err, result) {
        console.log(result);
    });

};

getTest();

API

Entitie(master)对象:
工厂管理者对象
var master = require('node-entities');  // return factoryMaster;
getModels:
获取当前所有的模型配置
var models = master.getModels();  // return models;
setModels:
设置模型,可将模型集合对象配置给entities,也支持
init:
初始化方法,接受两个参数,mysql配置对象,与models对象
master.init(opts, models);  // return class:Factory;
Factory:
工厂提供者类,用来创建工厂对象
var factory = new master.Factory();  // return entity:factory;
find:
查询,返回SQL对象或null,取决于是否传入callback。results总是返回一个数组,除非err不为null
// return SQL || null;
// callback(err, results)
factory.find("模型名", [{查询参数}], [{返回结构}], callback);
findOne:
查询一条数据,返回结构省略时返回所有属性,callback中的result为对象类型
// return null;
// callback(err, result);
factory.findOne("模型名", [{查询参数}], [{返回结构}], callback); 
count:
查询总条数
// return null;
// callback(err, count); 
factory.count("模型名", [{查询参数}], callback); 

v2.0版本文档