JSPM

sync-sql

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 163
  • Score
    100M100P100Q74258F
  • License MIT

Make synchronous queries to a database server in node.js

Package Exports

  • sync-sql

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sync-sql) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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