Coder Social home page Coder Social logo

mssqlhelper's Introduction

# nodejs Microsoft SQL Server Helper 
# nodejs的一个用于连接mssql数据库的工具类

## Features 介绍

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

## TODO 待实现内容

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

## Requirements 需要如下组件(已内置)

 * [tds](http://cretz.github.com/node-tds/)(已内置)



## 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);
		}
	}
);

mssqlhelper's People

Contributors

play175 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.