<commit_before># Database and REST (dare)

[![Greenkeeper badge](https://badges.greenkeeper.io/5app/dare.svg)](https://greenkeeper.io/)
[![Coverage Status](https://coveralls.io/repos/github/5app/dare/badge.svg)](https://coveralls.io/github/5app/dare)
[![CircleCI](https://circleci.com/gh/5app/dare.svg?style=shield)](https://circleci.com/gh/5app/dare)
[![NPM Version](https://img.shields.io/npm/v/dare.svg)](https://www.npmjs.com/package/dare)
[![Known Vulnerabilities](https://snyk.io/test/github/5app/dare/badge.svg)](https://snyk.io/test/github/5app/dare)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)



Dare is a lovely API for generating SQL out of structured JS Object. It can be used to query and modify your flavour of SQL database inside your node app. Or if you dare, give it it's own restful interface and have it construct and execute all the scrumptuous queries the client throws at it. Now the security conscious amongst you may fret but dont fear, your own rules can be applied via "handlers" by table and method, just the thing for maintaining data integrity and developing REST interfaces.

# Example usage...

This is a simple setup to get started with, it'll make a basic SELECT query.

```javascript
// Require the module
const Dare = require('dare');
const sqlConn = require('./someSqlConnection');

// Initiate it
const dare = new Dare();

// Define a module for connecting
dare.execute = async (sql) => {
	// Connect to DB, and execute the `sql`,
	// resolve with a successResponse or throw an errorResponse
	return sqlConn.execute(sql);
};

// Make a request
dare.get('users', ['name'], {id: 1}).then((resp) => {

	// This would have run...
	// SELECT id, name FROM users WHERE id = 1 LIMIT 1;
	// And returned a single record as the response...

	console.log(`Hi ${resp.name}');
});

```


# Setup


## Install

```bash
npm i dare --save
```


## dare = new Dare(options)

Create an instance of Dare with some options

```javascript
const Dare = reqire('dare');

const options = {
	schema
};

const dare = new Dare(options);
```

## Options

The `options Object` is a set of properties to apply at the point of calling any methods. Initially it's used to define default properties. However every method creates its own instance inheritting its parent options as well as defining it's own. See `dare.use(options)` for more.

The `options` themselves are a set of properties used to interpret and manipulate the request.


## Schema `schema`
<commit_msg>docs: Fix typo in require<commit_after># Database and REST (dare)

[![Greenkeeper badge](https://badges.greenkeeper.io/5app/dare.svg)](https://greenkeeper.io/)
[![Coverage Status](https://coveralls.io/repos/github/5app/dare/badge.svg)](https://coveralls.io/github/5app/dare)
[![CircleCI](https://circleci.com/gh/5app/dare.svg?style=shield)](https://circleci.com/gh/5app/dare)
[![NPM Version](https://img.shields.io/npm/v/dare.svg)](https://www.npmjs.com/package/dare)
[![Known Vulnerabilities](https://snyk.io/test/github/5app/dare/badge.svg)](https://snyk.io/test/github/5app/dare)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)



Dare is a lovely API for generating SQL out of structured JS Object. It can be used to query and modify your flavour of SQL database inside your node app. Or if you dare, give it it's own restful interface and have it construct and execute all the scrumptuous queries the client throws at it. Now the security conscious amongst you may fret but dont fear, your own rules can be applied via "handlers" by table and method, just the thing for maintaining data integrity and developing REST interfaces.

# Example usage...

This is a simple setup to get started with, it'll make a basic SELECT query.

```javascript
// Require the module
const Dare = require('dare');
const sqlConn = require('./someSqlConnection');

// Initiate it
const dare = new Dare();

// Define a module for connecting
dare.execute = async (sql) => {
	// Connect to DB, and execute the `sql`,
	// resolve with a successResponse or throw an errorResponse
	return sqlConn.execute(sql);
};

// Make a request
dare.get('users', ['name'], {id: 1}).then((resp) => {

	// This would have run...
	// SELECT id, name FROM users WHERE id = 1 LIMIT 1;
	// And returned a single record as the response...

	console.log(`Hi ${resp.name}');
});

```


# Setup


## Install

```bash
npm i dare --save
```


## dare = new Dare(options)

Create an instance of Dare with some options

```javascript
const Dare = require('dare');

const options = {
	schema
};

const dare = new Dare(options);
```

## Options

The `options Object` is a set of properties to apply at the point of calling any methods. Initially it's used to define default properties. However every method creates its own instance inheritting its parent options as well as defining it's own. See `dare.use(options)` for more.

The `options` themselves are a set of properties used to interpret and manipulate the request.


## Schema `schema`

{'fraction_non_alphanumeric': 0.13419082357458245, 'fraction_numerical': 0.011134574774428873, 'mean_word_length': 4.25731584258325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 24, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '155497', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1587, 'n_words': 574}