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

nodedatahandler

v1.0.1

Published

Node Package for maintaining database connection and also build headers and responses in easier way

Downloads

7

Readme

Nodedatahandler

Nodedatahandler is a comprehensive toolkit for Node.js that simplifies the process of building API responses, reading SQL files, and managing database connections and migrations.

Features

  • Build consistent API responses with ease.
  • Read SQL files from your filesystem.
  • Handle database connections with simplified async/await support.
  • Log errors and track database operations efficiently.
  • Migrate data between databases with minimal configuration.

Installation

Install nodedatahandler by running:

npm install nodedatahandler

Usage

Below are examples of how to use the main features of nodedatahandler.

Building API Responses

const { buildResponse } = require('nodedatahandler');

// ... inside your API handler

const response = buildResponse(event, context, { message: 'Success' });

// send `response` back to your API caller

Reading SQL Files

const readSqlFile = require('nodedatahandler/sql');

const sqlContent = readSqlFile('path/to/your/sqlfile.sql');

// use `sqlContent` with your database client

Database Connection and Error Handling

const { query, migrate } = require('nodedatahandler/dbConnector');

// ... perform database operations

API Reference

Detailed information on all available methods and their usage can be found below.

buildResponse(event, context, response, [statusCode], [methods])

Builds and returns an API response object.

readSqlFile(filename)

Reads an SQL file and returns its content as a string.

query(sql, [data], [db], [env], [response])

Executes a SQL query and returns the results.

migrate(sourceDb, targetDb, selectSql, insertSql, [env], [fetchOne], [cleanup], [truncateSql])

Handles data migration between databases.

Examples

For more examples on how to use nodedatahandler, refer to the /examples directory in this package.

Here's a simple example:

const { buildResponse, query } = require('nodedatahandler');

async function getPosts(event, context) {
  const posts = await query('SELECT * FROM posts');
  return buildResponse(event, context, posts);
}

Support

If you have any questions or encounter issues, please open an issue on the GitHub issue tracker for this project.