# digger-supplier

> A database warehouse for digger.io.

Latest version **0.1.10** (published 2014-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install digger-supplier
pnpm add digger-supplier
yarn add digger-supplier
bun add digger-supplier
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.10 |
| Published | 2014-04-10 |
| First published | 2013-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kai Davenport |
| Maintainers | binocarlos |
| Keywords | digger |

## Links

- npm: https://www.npmjs.com/package/digger-supplier
- Repository: https://github.com/binocarlos/digger-supplier
- Issues: https://github.com/binocarlos/digger-supplier/issues
- npm.io page: https://npm.io/package/digger-supplier

## Dependencies (4)

- [async](https://npm.io/package/async.md) ~0.2.9
- [miniware](https://npm.io/package/miniware.md) ~0.0.1
- [digger-utils](https://npm.io/package/digger-utils.md) ~1.0.6
- [digger-selector](https://npm.io/package/digger-selector.md) ~0.0.8

## Recent versions

- 0.1.10 (latest) — 2014-04-10
- 0.1.8 — 2013-10-20
- 0.1.7 — 2013-09-29
- 0.1.6 — 2013-09-12
- 0.1.5 — 2013-09-07
- 0.1.3 — 2013-09-03
- 0.1.2 — 2013-09-03
- 0.1.0 — 2013-09-02
- 0.0.10 — 2013-08-30
- 0.0.9 — 2013-08-28
- 0.0.7 — 2013-08-18
- 0.0.5 — 2013-08-17
- 0.0.4 — 2013-08-13
- 0.0.2 — 2013-08-06

## README

digger-supplier
===============

A functional approach to REST api's.

A digger supplier is just a function - it accepts **req** and **reply** arguments.

req is a plain javascript object representing a HTTP request:

```js
// a request represent a load of item 1234
{
	method:'get',
	url:'/1234',
	headers:{

	},
	body:null
}

```

reply is a standard node.js callback.

## installation

	$ npm install digger-supplier --save

## usage

A supplier has 4 distinct roles to play.

 * select
 * append
 * save
 * remove

These are conceptually mapped onto the REST methods: GET, POST, PUT, DELETE

A supplier is a digger-warehouse - which means you can mount middleware onto a supplier like any other warehouse.

```js
var Supplier = require('digger-supplier');
var supplier = Supplier();

// mount a custom middleware onto the supplier
// this is called before the database methods
supplier.use(function(req, res, next){
	
})

```

The point of a supplier is to connect to a data source on the back and interpret our container queries upon that data.


## routing
It is useful to have the same supplier object deal with different backend resources (like files or databases) based upon the route that is used.

Imagine we have a supplier mounted on '/csv' - it is a csv file supplier that has access to a directory '/tmp/mycsvsupplier'.

```js
var folder = '/tmp/mycsvsupplier';
var Supplier = require('digger-supplier');

// we create the supplier with an factory function
var supplier = Supplier(function(ready){
	
	/*
	
		connect to a database or prepare a filesystem or prepare API client etc
		
	*/
	ready();
})

// we run the provision function for every request - it decides what specific database table/collection/file to use
// based upon the route
//
// it is basically a renamed .use
supplier.provision(function(route, ready){
	
	
})


```

### Database Methods
You specify what happens in your supplier when a container is:

 * searched for (select)
 * added (append)
 * updated (save)
 * deleted (remove)

```js
var Supplier = require('digger-supplier');
var supplier = Supplier();

/*

	search the database with a selector and context array
	
*/
supplier.on('select', function(select_query, reply){
	
	/*
	
		a parsed selector string

		{
			tag:'product',
			class:["onsale"],
			attr:[{
				name:"price",
				operator:"<=",
				value:100
			}],
			modifier:{
				tree:true,
				sort:"name",
				limit:"6,10"
			}
		}
		
	*/
	var selector = select_query.selector;

	/*
	
		an array of skeletons from the previous step
		this is the context (i.e. to search within)


		[{
			_digger:{
				id:123
			}
		},{
			_digger:{
				id:456
			}
		}]
		
	*/
	var context = select_query.context;
})

/*

	add an item to the database
	
*/
supplier.on('append', function(append_query, reply){
	/*
	
		a skeleton of the container we are posting to

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = append_query.target;

	/*
	
		an array of container data to add to the target

		[{
			name:"test1",
			_digger:{
				tag:"thing",
				id:"hello"
			}
		},{
			name:"test2",
			_digger:{
				tag:"otherthing",
				id:"goodbye"
			}
		}]
		
	*/
	var append_data = append_query.data;
})

supplier.on('save', function(save_query, reply){
	/*
	
		a skeleton of the container we are saving

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = save_query.target;

	/*
	
		the update for the container

		{
			this:"that"
		}
		
	*/
	var save_data = save_query.data;
})

supplier.on('remove', function(remove_query, reply){
	/*
	
		a skeleton of the container we are removing

		{
			_digger:{
				id:123
			}
		}
		
	*/
	var target = remove_query.target;
})


```

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