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

mssqlhelper

v0.2.0

Published

Microsoft SQL Server database helper.

Downloads

8

Readme

nodejs Microsoft SQL Server Helper

nodejs的一个用于连接mssql数据库的工具类

Features 介绍

  • 采用微软tds协议,不需要任何C/C++扩展,跨平台使用
  • 执行sql语句,获得结果行
  • 执行存储过程,获得输出参数以及结果行

TODO 待实现内容

  • 将支持获得多个结果集(Table)
  • 将支持连接池
  • 更多性能加强

Use 使用

$ git clone [email protected]:play175/mssqlhelper.git
$ cd mssqlhelper
$ node test.js

Test 测试代码

var db = require('./index');

db.config({ host: '192.168.1.100' ,port: 1433 ,userName: 'sa' ,password: '123' ,database:'testdb' });

//test query sql 执行sql

db.query( 'select @Param1 Param1,@Param2 Param2' ,{ Param1: { type : 'NVarChar', size: 7,value : 'myvalue' } ,Param2: { type : 'Int',value : 321 } } ,function(res){ if(res.err)throw new Error('database error:'+res.err.msg); var rows = res.tables[0].rows; for (var i = 0; i < rows.length; i++) { console.log(rows[i].getValue(0),rows[i].getValue('Param2')); } } );

//test excute sp 执行存储过程

db.exec( 'test_sp' ,{ Param1: {direction:'out', type : 'NVarChar', size: 50,value : 'my Param1 value' } ,Param2: { type : 'Int',value : 123 } ,Param3: {direction:'out', type : 'VarChar', size: 50,value : '789' } } ,function(res){ if(res.err)throw new Error('database error:'+res.err.msg);

	//get output paramater value
	console.log('output @Param1='+res.params.Param1.value);

	//get rows
	var rows = res.tables[0].rows;
	for (var i = 0; i < rows.length; i++) {
		var rp = '';
		for(var j=0,len = rows[i].metadata.columns.length;j<len;j++){
			var col = rows[i].metadata.columns[j];
			rp += ' ' +(rows[i].getValue(j));
		}
		console.log(rp);
	}
}

);

///////////////////////////////问题和解决方案////////////////////////////////////// 问题/Issues: 1:不能输出匿名列,比如select * 2:如果不能排序,比如 select a from table oerder by b desc,目前的解决方法: ;with result as( SELECT Actor,ActorName FROM [GameActor] order by time desc ) select * from result 3:输出中文乱码,引发这个问题有几个方面,解决方法: (1)把所有js文件用utf-8编码保存 (2)数据库中含有中文的字段,必须是unicode类型,比如varchar应该改为nvarchar

4:在多进程cluster的的使用: var db = require('./index'); var cluster = require('cluster'); if (cluster.isMaster) { var numCPUs = require('os').cpus().length; for (var i = 0; i < numCPUs; i++) { var worker = cluster.fork(); } } else { db.config(..); db.query(..); }