Comparing version 0.1.12 to 0.1.13
{ | ||
"name": "meadow", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "A data access library.", | ||
@@ -9,3 +9,5 @@ "main": "source/Meadow.js", | ||
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -u tdd -R spec", | ||
"test": "./node_modules/mocha/bin/_mocha -u tdd -R spec" | ||
"test": "./node_modules/mocha/bin/_mocha -u tdd -R spec", | ||
"doc": "./node_modules/groc/bin/groc --index-page-title Overview ./README.md ./source/**/*.js ./source/*.js", | ||
"doc-stage-retold": "./node_modules/groc/bin/groc --index-page-title Overview -o ../retold/meadow ./README.md ./source/**/*.js ./source/*.js" | ||
}, | ||
@@ -30,2 +32,3 @@ "repository": { | ||
"coveralls": "^2.11.2", | ||
"groc": "^0.8.0", | ||
"istanbul": "0.3.5", | ||
@@ -32,0 +35,0 @@ "mocha": "2.1.0" |
@@ -6,6 +6,65 @@ Meadow | ||
[![Code Climate](https://codeclimate.com/github/stevenvelozo/meadow/badges/gpa.svg)](https://codeclimate.com/github/stevenvelozo/meadow) [![Coverage Status](https://coveralls.io/repos/stevenvelozo/meadow/badge.svg?branch=master)](https://coveralls.io/r/stevenvelozo/meadow?branch=master) [![Build Status](https://travis-ci.org/stevenvelozo/meadow.svg?branch=master)](https://travis-ci.org/stevenvelozo/meadow) [![Dependency Status](https://david-dm.org/stevenvelozo/meadow.svg)](https://david-dm.org/stevenvelozo/meadow) [![devDependency Status](https://david-dm.org/stevenvelozo/meadow/dev-status.svg)](https://david-dm.org/stevenvelozo/meadow#info=devDependencies) | ||
[![Code Climate](https://codeclimate.com/github/stevenvelozo/meadow/badges/gpa.svg)](https://codeclimate.com/github/stevenvelozo/meadow) | ||
[![Coverage Status](https://coveralls.io/repos/stevenvelozo/meadow/badge.svg?branch=master)](https://coveralls.io/r/stevenvelozo/meadow?branch=master) | ||
[![Build Status](https://travis-ci.org/stevenvelozo/meadow.svg?branch=master)](https://travis-ci.org/stevenvelozo/meadow) | ||
[![Dependency Status](https://david-dm.org/stevenvelozo/meadow.svg)](https://david-dm.org/stevenvelozo/meadow) | ||
[![devDependency Status](https://david-dm.org/stevenvelozo/meadow/dev-status.svg)](https://david-dm.org/stevenvelozo/meadow#info=devDependencies) | ||
Who doesn't love writing the same code over and over again? Good question. Anybody who doesn't probably wants something to do simple data access stuff. And some of the complicated interactions as well. Meadow aims to provide a simple “magic where you want it, programmability where you don't” pattern. | ||
_Do not use this yet._ | ||
## Install | ||
```sh | ||
$ npm install meadow | ||
``` | ||
Because meadow requires the [fable](https://github.com/stevenvelozo/fable) library, you will also need to install that dependency: | ||
```sh | ||
$ npm install fable | ||
``` | ||
## Quick Start | ||
It is pretty easy to perform CRUD access on your database. And facilities are there to go crazy with custom queries and stored procedures. | ||
```js | ||
// These settings are read automatically from the fable.settings object by meadow | ||
var databaseSettings = { | ||
MySQL: | ||
{ | ||
Server: "localhost", | ||
Port: 3306, | ||
User: "root", | ||
Password: "", | ||
Database: "sales_data", | ||
ConnectionPoolLimit: 20 | ||
} | ||
}; | ||
var fable = require('fable').new(); | ||
// Create a new meadow DAL object for the "Customers" data set | ||
var meadow = require('meadow').new(fable, 'Customers') | ||
.setProvider('MySQL') | ||
.setDefaultIdentifier('customerID'); | ||
// Construct a query, filtering to a specific customer, number 17 | ||
var queryDescription = meadow.query.addFilter('customerID', 17); | ||
// Now pass the read query into the customer DAL, with a callback | ||
meadow.doRead(queryDescription, | ||
function(error, query, customer) | ||
{ | ||
// The customer parameter will contain a javascript object if there is: | ||
// 1) a record with customerID = 17 | ||
// 2) in the customers table | ||
// 3) in the sales_data database | ||
if (error) | ||
{ | ||
return console.log('Error querying customer data: '+error); | ||
} | ||
console.log('Found customer ID '+customer.customerID+' who is named '+customer.name); | ||
} | ||
); | ||
``` |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Count | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ var libAsync = require('async'); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Create | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ var libAsync = require('async'); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Delete | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ var libAsync = require('async'); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Read | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ var libAsync = require('async'); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Reads | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ var libAsync = require('async'); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Update | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -87,2 +84,8 @@ var libAsync = require('async'); | ||
{ | ||
if (pQueryRead.result.value.length === 0) | ||
{ | ||
//No record found to update | ||
return fStageComplete('No record found to update!', pQueryRead.result, false); | ||
} | ||
var tmpRecord = pMeadow.marshalRecordFromSourceToObject(pQueryRead.result.value[0]); | ||
@@ -89,0 +92,0 @@ fStageComplete(pQuery.result.error, pQuery, pQueryRead, tmpRecord); |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Behavior - Package Loader | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -9,0 +6,0 @@ |
@@ -0,27 +1,22 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Raw Query Module | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow-RawQuery | ||
* @author <steven@velozo.com> | ||
*/ | ||
var libFS = require('fs'); | ||
/** | ||
* Meadow Raw Query Library | ||
* ### Meadow Raw Query Library | ||
* | ||
* This library loads and stores raw queries for FoxHound to use. | ||
* You can overload the default query that is built for each of: | ||
* You can overload the default query that is built for each of | ||
* the following query archetypes: | ||
* | ||
* Create | ||
* Read | ||
* Reads | ||
* Update | ||
* Delete | ||
* Count | ||
* `Create`, `Read`, `Reads`, `Update`, `Delete`, `Count` | ||
* | ||
* You can also load other custom queries and give them an | ||
* arbitrary name. | ||
* | ||
* @class MeadowRawQuery | ||
* @constructor | ||
*/ | ||
var MeadowRawQuery = function() | ||
@@ -42,3 +37,3 @@ { | ||
/** | ||
* Load a Query from File | ||
* Load a Custom Query from a File | ||
* | ||
@@ -58,2 +53,3 @@ * @method doLoadQuery | ||
// There is some debate whether we should leave the queries entry unset or set it to empty so nothing happens. | ||
// If this were to set the query to `false` instead of `''`, FoxHound would be used to generate a query. | ||
doSetQuery(pQueryTag, ''); | ||
@@ -74,3 +70,3 @@ tmpCallBack(false); | ||
/** | ||
* Set a Custom Query from a String | ||
* Sets a Custom Query from a String | ||
* | ||
@@ -87,3 +83,3 @@ * @method doSetQuery | ||
/** | ||
* Return a Custom Query | ||
* Returns a Custom Query if one has been set for this tag | ||
* | ||
@@ -94,3 +90,2 @@ * @method doGetQuery | ||
{ | ||
// This allows us to add hooks at the higher layer (from routing) | ||
if (_Queries.hasOwnProperty(pQueryTag)) | ||
@@ -101,3 +96,2 @@ { | ||
// Return false if there is no query for that tag. | ||
return false; | ||
@@ -104,0 +98,0 @@ } |
@@ -0,18 +1,11 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Schema Module | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow-Schema | ||
* @author <steven@velozo.com> | ||
*/ | ||
var libValidator = require('is-my-json-valid'); | ||
/** | ||
* Meadow Schema Library | ||
* | ||
* @class MeadowSchema | ||
* @constructor | ||
*/ | ||
var libValidator = require('is-my-json-valid'); | ||
var MeadowSchema = function() | ||
@@ -22,58 +15,67 @@ { | ||
{ | ||
// The schema | ||
/* | ||
* An example: | ||
[ | ||
{ "Column": "IDAnimal", "Type":"AutoIdentity" }, | ||
{ "Column": "GUIDAnimal", "Type":"AutoGUID" }, | ||
{ "Column": "Created", "Type":"CreateDate" }, | ||
{ "Column": "CreatingIDUser", "Type":"CreateIDUser" }, | ||
{ "Column": "Modified", "Type":"UpdateDate" }, | ||
{ "Column": "ModifyingIDUser", "Type":"UpdateIDUser" }, | ||
{ "Column": "Deleted", "Type":"Deleted" }, | ||
{ "Column": "DeletingIDUser", "Type":"DeleteIDUser" }, | ||
{ "Column": "DeleteDate", "Type":"DeleteDate" } | ||
] | ||
/* ^ An Example Meadow Schema Object | ||
[ | ||
{ "Column": "IDAnimal", "Type":"AutoIdentity" }, | ||
{ "Column": "GUIDAnimal", "Type":"AutoGUID" }, | ||
{ "Column": "Created", "Type":"CreateDate" }, | ||
{ "Column": "CreatingIDUser", "Type":"CreateIDUser" }, | ||
{ "Column": "Modified", "Type":"UpdateDate" }, | ||
{ "Column": "ModifyingIDUser", "Type":"UpdateIDUser" }, | ||
{ "Column": "Deleted", "Type":"Deleted" }, | ||
{ "Column": "DeletingIDUser", "Type":"DeleteIDUser" }, | ||
{ "Column": "DeleteDate", "Type":"DeleteDate" } | ||
] | ||
*/ | ||
/* #### The Meadow Schema | ||
* | ||
* Meadow uses this description object to create queries, broker data and generate interfaces. | ||
*/ | ||
var _Schema = false; | ||
// The JSONSchema spec schema | ||
/* http://json-schema.org/examples.html | ||
/* ^ An Example JSONSchema Object: | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Product", | ||
"description": "A product from Acme's catalog", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"description": "The unique identifier for a product", | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"description": "Name of the product", | ||
"type": "string" | ||
}, | ||
"price": { | ||
"type": "number", | ||
"minimum": 0, | ||
"exclusiveMinimum": true | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"minItems": 1, | ||
"uniqueItems": true | ||
} | ||
}, | ||
"required": ["id", "name", "price"] | ||
} | ||
*/ | ||
/* #### A JSONSchema Description | ||
* | ||
* http://json-schema.org/examples.html | ||
* | ||
* http://json-schema.org/latest/json-schema-core.html | ||
* | ||
* An example: | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "Product", | ||
"description": "A product from Acme's catalog", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"description": "The unique identifier for a product", | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"description": "Name of the product", | ||
"type": "string" | ||
}, | ||
"price": { | ||
"type": "number", | ||
"minimum": 0, | ||
"exclusiveMinimum": true | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"minItems": 1, | ||
"uniqueItems": true | ||
} | ||
}, | ||
"required": ["id", "name", "price"] | ||
} | ||
*/ | ||
*/ | ||
var _JsonSchema = false; | ||
// The "default" empty object | ||
/* #### An "empty" ORM object | ||
* This is the basis for being filled out by the marshalling code. | ||
*/ | ||
var _Default = false; | ||
// The cached validator | ||
// The cached validator, which uses the JSONSchema | ||
var _Validate = false; | ||
@@ -83,7 +85,7 @@ | ||
/** | ||
* Set the schema to be something else after the object is created. | ||
* Set the Meadow schema | ||
* | ||
* Our schemas are really instructions for what to do when. We track: | ||
* Our schemas are really instructions for *what* to do *when*. We track: | ||
* - Column | ||
* - Type (e.g. AutoIdentity, AutoGUID, CreateDate, CreateIDUser, UpdateDate, UpdateIDUser, DeleteDate, Deleted, DeleteIDUser) | ||
* - Type _(e.g. AutoIdentity, AutoGUID, CreateDate, CreateIDUser, UpdateDate, UpdateIDUser, DeleteDate, Deleted, DeleteIDUser)_ | ||
* - Optionally Special Instractions | ||
@@ -105,3 +107,3 @@ * | ||
/** | ||
* Set the json schema to be something else after the object is created. | ||
* Set the JSONSchema | ||
* | ||
@@ -122,2 +124,7 @@ * @method setJsonSchema | ||
/** | ||
* Set the Default ORM object | ||
* | ||
* @method setDefault | ||
*/ | ||
var setDefault = function(pDefault) | ||
@@ -132,3 +139,3 @@ { | ||
* | ||
* @method setSchema | ||
* @method validateObject | ||
*/ | ||
@@ -160,3 +167,3 @@ var validateObject = function(pObject) | ||
/** | ||
* Schema | ||
* The Meadow Schema | ||
* | ||
@@ -174,3 +181,3 @@ * @property schema | ||
/** | ||
* JsonSchema | ||
* The JsonSchema | ||
* | ||
@@ -177,0 +184,0 @@ * @property jsonSchema |
@@ -0,9 +1,8 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Data Broker Library | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow | ||
* @author <steven@velozo.com> | ||
*/ | ||
var libUnderscore = require('underscore'); | ||
var libFoxHound = require('foxhound'); | ||
@@ -14,9 +13,3 @@ /** | ||
* @class Meadow | ||
* @constructor | ||
*/ | ||
var libUnderscore = require('underscore'); | ||
// Multi server query generation | ||
var libFoxHound = require('foxhound'); | ||
var Meadow = function() | ||
@@ -107,3 +100,3 @@ { | ||
* | ||
* This function expects a string, case sensitive, which matches the | ||
* This function expects a string, case sensitive, which matches the | ||
* provider filename | ||
@@ -239,3 +232,3 @@ * | ||
/** | ||
* Take the stored representation of our object and stuff the proper values | ||
* Take the stored representation of our object and stuff the proper values | ||
* into our record, translating where necessary. | ||
@@ -242,0 +235,0 @@ */ |
@@ -0,11 +1,6 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Provider - MySQL | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow-Schema | ||
* @author <steven@velozo.com> | ||
*/ | ||
var libMySQL = require('mysql2'); | ||
@@ -12,0 +7,0 @@ |
@@ -0,8 +1,5 @@ | ||
// ##### Part of the **[retold](https://stevenvelozo.github.io/retold/)** system | ||
/** | ||
* Meadow Provider - No Data | ||
* | ||
* @license MIT | ||
* | ||
* @author Steven Velozo <steven@velozo.com> | ||
* @module Meadow-Schema | ||
* @author <steven@velozo.com> | ||
*/ | ||
@@ -68,3 +65,3 @@ | ||
marshalRecordFromSourceToObject: marshalRecordFromSourceToObject, | ||
Create: Create, | ||
@@ -71,0 +68,0 @@ Read: Read, |
@@ -761,2 +761,22 @@ /** | ||
( | ||
'Update a record in the database that does not exist', | ||
function(fDone) | ||
{ | ||
var testMeadow = newMeadow(); | ||
var tmpQuery = testMeadow.query | ||
.addRecord({IDAnimal:983924}); | ||
testMeadow.doUpdate(tmpQuery, | ||
function(pError, pQuery, pQueryRead, pRecord) | ||
{ | ||
Expect(pError) | ||
.to.equal('No record found to update!'); | ||
fDone(); | ||
} | ||
) | ||
} | ||
); | ||
test | ||
( | ||
'Set a raw Query', | ||
@@ -763,0 +783,0 @@ function(fDone) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77729
70
6
2695