npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

peacherine

v0.2.1

Published

Cross-platform cross-datasource querying

Downloads

9

Readme

Peacherine

The cross-platform and multi-datasource query module

Want to see support for another data source type? Open an issue so that it can be prioritized and tracked

Future development: continue to add popular database management systems (SQL, NoSQL, whatever...)

Why?

I think you should be able to query all mainstream data sources from any machine, and this module is the abstraction for that functionality to be consumed by CLI or GUI tools

Install

$ npm install peacherine

Supported data sources

Get supported data sources

const peacherine = require('peacherine');

const supportedDataSources = peacherine.getDataSourceTypes();
// returns a string array of data source types

SQL Server and SQL Azure

Run query (SQL)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType = 'mssql',
  server: '...',
  database: '...',
  username: '...',
  password: '...'
};

const actionOptions = {
  query: 'SELECT object_id, name FROM sys.objects'
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results, if any
});

Test connection (SQL)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType = 'mssql',
  server: '...',
  database: '...',
  username: '...',
  password: '...'
};

peacherine.testConnection(connectionOptions, (err) => {
  if (err) {
    // failed connection
  }
  else {
    // successful connection
  }
});

Azure DocumentDB

Query collection (DocumentDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'documentdb',
  endpoint: 'https://...documents.azure.com:.../',
  key: '...',
  database: '...'
};

const actionOptions = {
  operation: 'queryCollection',
  query: 'SELECT * FROM c',
  collection: 'collection-name'
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results
});

Insert document (DocumentDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'documentdb',
  endpoint: 'https://...documents.azure.com:.../',
  key: '...',
  database: '...'
};

const actionOptions = {
  operation: 'createDocument',
  collection: 'collection-name',
  document: {
    id: 'some-id',
    message: 'test document creation'
  }
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results
});

Test connection (DocumentDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'documentdb',
  endpoint: 'https://...documents.azure.com:.../',
  key: '...',
  database: '...'
};

peacherine.testConnection(connectionOptions, (err) => {
  if (err) {
    // failed connection
  }
  else {
    // successful connection
  }
});

MongoDB

Query all documents (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

const actionOptions = {
  operation: 'queryCollection',
  collection: 'collection-name'
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results
});

Query documents in collection with filter (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

const actionOptions = {
  operation: 'queryCollection',
  collection: 'collection-name',
  filter: {
    id: 1
  }
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results
});

Insert document (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

const actionOptions = {
  operation: 'createDocument',
  collection: 'collection-name',
  document: {
    id: 1,
    message: 'test document creation'
  }
};

peacherine.run(connectionOptions, actionOptions, (err) => {
  // handle err
});

Update document (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

const actionOptions = {
  operation: 'updateDocuments',
  collection: 'collection-name',
  filter: {
    id: 1
  },
  updateOptions: {
    $set: {
      message: 'my new message'
    }
  }
};

peacherine.run(connectionOptions, actionOptions, (err, result) => {
  // handle err and result
});

Delete document (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

actionOptions = {
  operation: 'deleteDocuments',
  collection: 'collection-name',
  filter: {
    id: 1
  }
};

peacherine.run(connectionOptions, actionOptions, (err, result) => {
  // handle err and result
});

Test connection (MongoDB)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mongodb',
  host: '...',
  port: 27017,
  database: '...'
};

peacherine.testConnection(connectionOptions, (err) => {
  if (err) {
    // failed connection
  }
  else {
    // successful connection
  }
});

MySQL

Run query (MySQL)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mysql',
  server: '...',
  database: '...',
  username: '...',
  password: '...'
};

const actionOptions = {
  query: 'SELECT * FROM information_schema.tables'
};

peacherine.run(connectionOptions, actionOptions, (err, results) => {
  // handle err and results, if any
});

Test connection (MySQL)

const peacherine = require('peacherine');

const connectionOptions = {
  dataSourceType: 'mysql',
  server: '...',
  database: '...',
  username: '...',
  password: '...'
};

peacherine.testConnection(connectionOptions, (err) => {
  if (err) {
    // failed connection
  }
  else {
    // successful connection
  }
});

Test

Want to contribute? Clone the repo and use npm test to run unit tests

$ git clone https://github.com/tstringer/peacherine.git
$ cd peacherine
$ npm install
$ npm test