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

yf-fpm-dbm

v2.0.9

Published

fast sql generateor

Downloads

10

Readme

yf-fpm-dbm

快速极简的orm框架

  • 源码地址: https://github.com/team4yf/yf-fpm-dbm.git
  • 目前支持mysql
  • 通过delflag实现逻辑删除
  • 默认带有四个字段:id,createAt,updateAt,delflag
  • 支持批量插入
  • 支持事务处理
  • TODO:存储过程,mongodb语法

0.Changelog

点击查看 Changelog

1.Installation

$ npm install yf-fpm-dbm

2.API List

  • adapter

获取原生的数据库适配器,可执行自定义的sql来满足一些复杂的业务操作

  • find

通过一组查询、排序、分页的条件筛选一组数据结果。

  • first

通过一组查询、排序、分页的条件筛选一行数据结果。

  • count

通过筛选条件进行统计计数

  • findAndCount

通过一组查询、排序、分页的条件筛选一组数据结果,并返回符合条件的所有数据行数

  • get

通过数据的ID获取到唯一的数据

  • update

修改一些数据

  • remove

删除一条已知的数据

  • clear

通过筛选条件删除一组数据

  • create

添加一条或者多条数据

3.Configuration

模块自带的一些配置信息:

  • Code List 1:
{
    host:'localhost',           //mysql host
    port:3306,                  //mysql port
    database:'test',            //mysql dbname
    user:'root',                //mysql username
    password:'',                //mysql password
    debug:false,                //true:使用 debug 模块输出 生成的sql语句,默认使用 DEBUG=SQL
    showSql:false,              //true:输出本模块生成的sql语句
    pool:{
        connectionLimit:10,     //链接池的配置
        queueLimit:0,
        waitForConnections:true
    }
}

在初始化的时候,可以通过传入的参数覆盖这些默认值

  • Code List 2:
var C = {
    host:'192.168.1.1',
    database:'test',
    username:'root',
    password:'root',
};
var M = require('yf-fpm-dbm')(C);

4.Useage

find
  • Code List 3:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "delflag=0",
 fields: "id,article,ptags,product"
};
M.find(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
first
  • Code List 4:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "delflag=0",
 fields: "id,article,ptags,product"
};
M.first(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
//condition 字段接受各种格式
//比如下面的格式同样支持
var arg = {
    table: "api_app",
    condition: [
      ['appid' , '=' , '10001'],
      "appkey = '45883198abcdc109'",
      ['or',['appname' ,'=','DEV_Activity']]
    ],
    fields: "id,appid,appname,apptype"
};
//最终解析出来的语句是这样的:
// where ( 1 = 1  and appid='10001' and appkey = '45883198abcdc109' or appname='DEV_Activity') and delflag = 0
count
  • Code List 5:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "delflag=0"
};
M.count(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
findAndCount
  • Code List 6:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "delflag=0",
 fields: "id,article,ptags,product"
};
M.first(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
get
  • Code List 7:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 id: 1
};
M.get(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
update
  • Code List 8: 修改所有key为test的val为123
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "key = 'test'",
    row:{val:"123"}
};
M.update(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
remove
  • Code List 9:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 id: 1
};
M.remove(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
clear
  • Code List 10:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 condition: "delflag=0"
};
M.clear(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});
create
  • Code List 11:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 row: {key:"test",val:"mmm"}
};
M.create(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});

or batch insert

  • Code List 12:
// M 的初始化代码请参看 Code List:2
var arg = {
 table: "test",
 row:[{key:"test",val:"mmm"},{key:"test2",val:"mmm2"}]
};
M.create(arg, function(error, data){
  if(error){
   // do error here
  }else{
    // do success here
  }
});

4. Support Transaction

  • Code List 13:
// M 的初始化代码请参看 Code List:2
M.transation(function(err, atom){
  var arg = {
   table: "test",
   condition: "...",
    row: { ... }
  };
  atom.update(arg, function(err, result1){
    if(err){
      atom.rollback();
      return ;
    }
    arg = {
     table: "test",
     condition: "...",
      row:{ ... }
    };
    atom.update(arg, function(err, result2){
      if(err){
        atom.rollback(function(){
          //do rollback code
        });
      }else{
        atom.commit(function(err){
          // do commit code
        });
      }
    });
  });
});