Coder Social home page Coder Social logo

queriesmanager.js's Introduction

This is a node module, that provides:

  • linking generic-pool, and felixge-mysql
  • sending sequences of queries
  • usage of external queries module, that would accept { type, arguments } objects and return ready queries
  • execution of single queries, mentioned objects, arrays of them, and arrays of arrays of a.........rrays of them :P

It is currently dependent on:

It is planned to become independent of above.

Hope you like it.

//	Usage:
/*	Options:
Necessary: 
-		user
-		password
Optional
-		database - better use it or you will have to use USE sth; as first query of each connection
-		queriesModule - module returning function that would return queries given (type, arguments); I strongly suggest to make use of it
-		host - default to localhost
-		port - default to 3306
-		poolSize - default to 10
-		cluster - default to false; if true then poolSize will be devided by numCPUs with minimal minSize || 10 value
-		numCPUs - default to require('os').cpus().length, but only if cluster is truthy
-		minSize - default to ten
-		initQueries - false/true, default true; if false, no initQueries will be executed on start
-		log
-		includeFields - if true every result will be array of[{ rows1, fields1 }, { rows2, fields2 }, ...] objects; otherwise it will be only [ rows1, rows2, rows3, ...]
*/
	var	qrMan = require("queriesManager")(options)
		,	database;
	qrMan(function(err, db){
		if(err){
			console.log("You are guilty of:\n" + err);
		}else{
			database = db;
		}
	});
	
//	e.g.
	database([
		[ { type: "getCakes", arguments: [ withCherries, withCockolate ] }
		,	{ type: "getCookies", arguments: [ withMarmolade, small, fresh ] }
		]
	,	"SELECT * FROM users;"
	], function(err, resp){
		if(err){
			console.log("You naughty one, you! Here's your error:\n" + err);
		}else{
			console.log("Server responded with sth like this:\n" + JSON.stringify(resp));
		}
	});
/*
	database( queries, callback )
		
		queries ::= "string being a ready to send query;"
		queries ::= {
				type: "query_function_name_from_queries_module"
			, arguments: [whatever_works_with_it]
			}
			arguments ::= whatever your queries module work with
				if you want to return another function inside, then you will of course have to route the arguments, but it's possible to for a function to return e.g. { type: "addUser", arguments: [arguments_from_outer_function] }, and all recursive processing will be done
		queries ::= [ array of those above, or even arrays of arrays of arrays of ... of arrays ... of those above ]
		
		callback ::= function(err, resp){ ... }
*/

Distributed under MIT licence; see LICENCE for more

queriesmanager.js's People

Stargazers

Sebastian Krzyszkowiak avatar

Watchers

Sebastian Krzyszkowiak avatar Michał Zajączkowski-de Mezer 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.