# asbestos

> generate CRUD handler functions from a model constructor function

Latest version **1.0.1** (published 2015-04-30) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2015-04-30 |
| First published | 2015-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | William Fisher, Besart Shyti |
| Maintainers | filwisher |
| Keywords | crud, handlers, automatic, model, constructor |

## Links

- npm: https://www.npmjs.com/package/asbestos
- Repository: https://github.com/foundersandcoders/asbestos
- Issues: https://github.com/foundersandcoders/asbestos/issues
- npm.io page: https://npm.io/package/asbestos

## Dependencies (6)

- [tape](https://npm.io/package/tape.md) ^4.0.0
- [torf](https://npm.io/package/torf.md) ^1.0.6
- [faucet](https://npm.io/package/faucet.md) ^0.0.1
- [jshint](https://npm.io/package/jshint.md) ^2.7.0
- [istanbul](https://npm.io/package/istanbul.md) ^0.3.13
- [pre-commit](https://npm.io/package/pre-commit.md) ^1.0.6

## Recent versions

- 1.0.1 (latest) — 2015-04-30
- 1.0.0 — 2015-04-28

## README

# asbestos
Generate hapi CRUD handler functions from a model constructor function

## use
```js

var route = {
  method: "POST",
  path: "/models",
  handler: handlers.create
}

// model prototype
var model = {

  // model must expose create method
  create: function (obj, cb) {

    //... do some db stuff
    return cb("created");
  },

  // model must expose findOne method
  findOne: function (criteria, cb) {

    //... do some db stuff
    return cb("found");
  },

  // model must expose update method
  update: function (criteria, changes, cb) {

    //... do some db stuff
    return cb("updated");
  },

  // model must expose delete method
  del: function (criteria, cb) {

    //... do some db stuff
    return cb("deleted");
  }

  // model must expose search method
  find: function (criteria, cb) {

    //... do some db stuff
    return cb("deleted");
  }
}

var handlers = require("asbestos")(model);

```

## api

asbestos exposes a single function that returns on object with 5 methods:
1. ```.create```
2. ```.find```
3. ```.findOne```
4. ```.update```
5. ```.del```

### createHandlers(obj)

**_params_**

```obj```: an object with create, find, findOne, update, and del methods.


**_returns_**

An object with 5 methods:

```.create(req, res)```: a hapi handler function. It passes req.payload to the constructor's create method. It returns the object just created on success.

```.find(req, res)```: a hapi handler function. It passes req.query to the constructor's find method. It returns the matched documents on success. It returns an empty array if not found.

```.findOne(req, res)```: a hapi handler function. It passes req.params.id to the constructor's findOne method. It returns the matched document on success. It returns an empty object and a 404 if not found.

```.update(req, res)```: a hapi handler function. It passes req.params.id and req.payload to the constructor's update method. It returns the updated document on success. It returns an empty object and a 404 if not found.

```.del(req, res)```: a hapi handler function. It passes req.params.id to the constructor's delete method. It returns the deleted document on success. It returns an empty object and a 404 if not found.

## license

MIT

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