# nodedatahandler

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

Latest version **1.0.1** (published 2023-11-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install nodedatahandler
pnpm add nodedatahandler
yarn add nodedatahandler
bun add nodedatahandler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-11-07 |
| First published | 2023-11-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thaamarai Kannan |
| Maintainers | thaamaraikannan |
| Keywords | nodejs, mysql, headers |

## Links

- npm: https://www.npmjs.com/package/nodedatahandler
- Repository: https://github.com/ThaamaraiKannan/nodedatahandler
- Homepage: https://github.com/ThaamaraiKannan/nodedatahandler#readme
- Issues: https://github.com/ThaamaraiKannan/nodedatahandler/issues
- npm.io page: https://npm.io/package/nodedatahandler

## Dependencies (3)

- [util](https://npm.io/package/util.md) ^0.12.5
- [mysql](https://npm.io/package/mysql.md) ^2.18.1
- [date-fns](https://npm.io/package/date-fns.md) ^2.30.0

## Recent versions

- 1.0.1 (latest) — 2023-11-07
- 1.0.0 — 2023-11-07

## 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**

```javascript
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**

```javascript
const readSqlFile = require('nodedatahandler/sql');

const sqlContent = readSqlFile('path/to/your/sqlfile.sql');

// use `sqlContent` with your database client
```

**Database Connection and Error Handling**

```javascript
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:

```javascript
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.

---
_Source: https://npm.io/package/nodedatahandler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
