NodeJS MySQL Library and npmjs
My friend publish a library based on mysql to support DAO, I forked that. It looks pretty good.
NodeJS method to convert keys in results
function convertResult(res, mappings) {
if (res === undefined || mappings === undefined) {
return res;
}
for (let i = 0; i < res.length; i++) {
let item = res[i];
let objKeys = Object.keys(item);
let mappingKeys = Object.keys(mappings);
for (let j = 0; j < objKeys.length; j++) {
let sourceKey = objKeys[j];
if (mappingKeys.includes(sourceKey)) {
item[mappings[sourceKey]] = item[sourceKey];
delete item[sourceKey];
}
}
}
return res;
}
I may use lodash to convert that
const _ = require('lodash');
class JSONUtil {
static renamekey(obj, key, newKey) {
if(_.includes(_.keys(obj), key)) {
obj[newKey] = _.clone(obj[key], true);
delete obj[key];
}
return obj;
}
}
module.exports = JSONUtil
I clone my friends’ project. It seems useful to me.
If we want to publish the library to use, we need an account here https://www.npmjs.com/
Type command to login
> npm adduse
Logged in as luohuazju on https://registry.npmjs.org/.
Check who am I
> npm whoami
luohuazju
Publish to public
> npm publish --access=public
publish
> npm publish
Remove the package
> npm unpublish xpmysql@1.0.0
Or we can add codes in package.json as follow:
"dependencies": {
"mysql": "2.18.1",
"lodash": "4.17.15",
"xpmysql": "https://github.com/baimeidaxia/xpmysql"
}
Both ways are working fine.
References:
https://github.com/luohuazju/xpmysql
https://juejin.im/post/5d2708e26fb9a07f06559812
分享到:
相关推荐
这两天学习了nodejs mysql 实现分页,很重要,所以,今天添加一点小笔记。 代码如下 var express = require('express'); var router = express.Router(); var settings = require('../settings.js'); var mysql =...
nodejs mysql mvc 增删改查
nodejs 关于mysql模块 连接超时自动断开解决方法,在这块遇到的坑,而且坑了很久才找到的,分享只为求分
nodejs封装好的mysql数据库模块,使用mysql连接池以及附带百万mysql测试数据,实现mysql数据库的增删改查功能,使用方法很详细。
使用nodejs将mysql数据库中的数据导出成excel格式,并附带mysql连接池及mysql模块的封装,以及三百万的mysql测试数据,内容详细。
诶mongodb 不知为何物,也不想学习,只好用mysql 哈哈本想免费 苦于没积分,需要的朋友给点积分吧
nodejs + mysql 事物处理问题 呵呵 看了就知道 记得npm install啊 需要的东西啊 本想免费 苦于没积分 ,需要的的同学,给点分吧
使用vue、nodejs、mysql组合实现旅行网站
前端 nodejs mysql 基础语法学习,案例里面功能包括:数据库连接测试,查询数据,插入数据,更新数据,删除数据
nodejs+mysql模块化实例代码
根据node和mysql搭建的项目作为入门练手是很好的项目。
基于nodejs+mysql实现的仿京东商城app项目 前端 页面结构(H5,CSS3,原生JS) 框架(基于Vue脚手架:vue-cli)进行搭建 数据请求处理框架(Axios) Vue-Router进行路由处理 Vue-LazyLoad进行图片赖加载 服务端 选用NodeJs...
uniApp+vue+nodejs+express+mysql电商项目.zip
一个简单学习NodeJs中使用MySQL的例子
nodejs和C语言插入mysql数据库乱码问题的解决方法.docx
nodejs+mysql+ejs完成的博客,可以登录注册,查看别人的博客,个人中心,发布编辑删除博客,留言等等
nodejs连接mysql实例
nodejs-mysql-utils nodejs mysql连接池 1. git clone https://github.com/niezhiliang/nodejs-mysql-utils 2.导入数据,项目根目录下面有个nodejs.sql 建立好数据库, 将conf/conf.js改为你数据库的配置 3. npm ...
利用nodejs搭建服务,并使用nodejs测试mysql并发请求