Code Monkey home page Code Monkey logo

meteortedious's Introduction

Meteortedious

A tedious module wrapper for MSQL connection query and data manipulation (insert,update,delete)

Example code

// Create a configuration option object

var config = {
    server: 'YOURSERVER',
    userName: 'YOURUSER',
    password: 'YOURPASSWORD',
    options: {
        instanceName: 'YOURINSTANCENAME', database: 'YOURDBNAME'
        //encrypt: true // for Azure users
    }
};

// user try to handle possible errors, connecting or executing queries

try{

	// make the connection
    var sqlServerConnection = new tdsConnection(config) ;

   	// executing more than one sql statement
    var sqls=[
    	"DELETE FROM items",
    	"INSERT INTO items (code, description) VALUES (1,'bar')"
    ];
    
	var currentSql ;
    sqls.forEach(function(sql,index){
        currentSql = sql ;
        
        // calling query method one time for each sql statement 
        var result = sqlServerConnection.query(currentSql) ;
        
        console.log("result:" + index,result) ;
    }) ;

    delete(currentSql) ;


	// instead of using sql statements you can use helper metods
	
	// inserting records
    var insertObj = {
        code: '2',
        description: 'foo'
    }
    var result = sqlServerConnection.insert(insertObj,'items') ;
    console.log("insert result:", result) ;

	// updating records
    var updateObj = {
        description : 'foobar'
    };
	// update only the items with code === 2
    var updateSelector = {
        code: '2'
    };

    var result = sqlServerConnection.update(updateObj,updateSelector,'items') ;
    console.log("update result:", result) ;


	// deleting records
    var deleteSelector = {
        code: '1'
    }

    var result = sqlServerConnection.delete(deleteSelector,'items') ;
    console.log("delete result:", result) ;

	// searching records
    var findSelector = {
        code: '2'
    }
    var result = sqlServerConnection.find(findSelector,'items') ;
    console.log("find result:", result) ;
    
    
    // close the connection
    sqlServercConnection.close()


} catch (err){

	// handling error 
    console.log("sql error",err) ;
    if (currentSql) console.log("executing",currentSql) ;

}

For more info go to https://github.com/cashbit/meteortedious and see inside the code.

meteortedious's People

Contributors

cashbit avatar

Watchers

 avatar James Cloos 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.