1.0.2 • Published 8 years ago

sync-sql v1.0.2

Weekly downloads
89
License
MIT
Repository
github
Last release
8 years ago

sync-sql

sync-sql is designed to make synchronous queries to the database. It has been developed as a tool to help nightwatch.js tests - or other such tools - connect directly to an sql database.

Important note

!!! You should not be using this in a production evironment. Node.js is designed to be asynchronous, therefore running sync queries on the database will seriously impact performance and stability.

Install

npm install sync-sql

For using the latest version with bug fixes, try the command:

npm install cristidraghici/sync-sql

Example usage with mysql

var syncSql = require('sync-sql');

var output = syncSql.mysql(
	{
		host: 'localhost',
		user: 'user',
		pass: 'password',
		database: 'database',
		port: '3306'
	},
	"select * from users"
);

console.log(JSON.stringify(output));

Testing

  • please edit the .env.example with database information and the sql to test and save the file as .env;
  • run npm install;
  • run npm run test-mysql;
  • run npm run test-pg;
  • run npm run test.

Workflow

Internally, this uses a separate worker process that is run using childProcess.spawnSync.

The worker then makes the actual query using the mysql and pg packages.

Thanks

Thanks to sync-request / Forbes Lindesay for providing the base knowledge for this package.

License

MIT