# data-promise

> Data access layer for MySQL using promises

Latest version **1.0.8** (published 2017-05-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install data-promise
pnpm add data-promise
yarn add data-promise
bun add data-promise
```

## 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.8 |
| Published | 2017-05-17 |
| First published | 2016-05-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Olav Gausaker |
| Maintainers | olavgm |

## Links

- npm: https://www.npmjs.com/package/data-promise
- Repository: https://github.com/olavgm/data-promise
- Homepage: https://github.com/olavgm/data-promise#readme
- Issues: https://github.com/olavgm/data-promise/issues
- npm.io page: https://npm.io/package/data-promise

## Dependencies (1)

- [mysql-promise](https://npm.io/package/mysql-promise.md) ^3.0.0

## Recent versions

- 1.0.8 (latest) — 2017-05-17
- 1.0.7 — 2017-05-17
- 1.0.6 — 2017-05-17
- 1.0.5 — 2016-06-04
- 1.0.4 — 2016-06-01
- 1.0.3 — 2016-05-31
- 1.0.2 — 2016-05-31
- 1.0.1 — 2016-05-31
- 1.0.0 — 2016-05-31

## README

# data-promise
**data-promise** is CRUD layer for MySQL. It uses promises to return the results or errors.

## Installation

### npm

```
npm install data-promise
```

## Usage

Let's say you have a table `users` on your MySQL database with a `userId` autogenerated key. Import the module, create a data object for the table you want to have the CRUD layer, and call any of the available methods on the data object.

```
// Import the module
var data = require('data-promise')

// MySQL connection details
var mysql = {
	host: 'mysqlhost.example.com',
	user: 'database_user',
	password: 'database_password',
	database: 'database_name',
	port: 3306
}

// Create a data object for the specific table
var userData = new data(mysql, 'users', 'userId')

// Let's create a new record on the users table!
// Create the object that we will insert in the database (the table contains a field "name")
var user = {
	name: 'Lucía'
}

// Just call the method .create on the data object
userData.create(user).then((userId) => {
	// user created
	console.log(userId)
})
.catch((error) => {
	// error creating user
	console.log(error)
})


// Let's list all the records on the table (CRUDL?? :D)
userData.listAll().then((results) => {
	console.log(results)
})
.catch((error) => {
	// error retrieving the list
	console.log(error)
})

// Let's read one record on the list, filtering by Id (assume the userId is 1077)
userData.read(1077).then((results) => {
	console.log(results)
})
.catch((error) => {
	// error retrieving one record
	console.log(error)
})
```

## Available methods
- create
- createMultiple (pass an array of elements to create all at once)
- read
- update
- delete
- exists (returns `true` if there is a row with the specified Id)
- listAll
- runSql (runs an arbitrary SQL query and returns the results)

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