meadow
A data access library.
Last updated a year ago by jasonhillier .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install meadow 
SYNC missed versions from official npm registry.

Meadow

A Javascript Data Broker.

Coverage Status Build Status Dependency Status devDependency Status

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.

Install

$ npm install meadow

Because meadow requires the fable library, you will also need to install that dependency:

$ 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.

// 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 MySQL connection pool (assuming MySQL is the provider you are using)
var libMySQL = require('mysql2');
fable.MeadowMySQLConnectionPool = libMySQL.createPool
	(
		{
			connectionLimit: _Fable.settings.MySQL.ConnectionPoolLimit,
			host: _Fable.settings.MySQL.Server,
			port: _Fable.settings.MySQL.Port,
			user: _Fable.settings.MySQL.User,
			password: _Fable.settings.MySQL.Password,
			database: _Fable.settings.MySQL.Database,
			namedPlaceholders: true
		}
	);


// 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);
		}
	);

You can also use the ALASQL persistence engine

// These settings are read automatically from the fable.settings object by meadow
var fable = require('fable').new();

// Create the IndexdDB database [example], attach and use it
var libALASQL = require('alasql');
libALASQL('CREATE INDEXEDDB DATABASE IF NOT EXISTS example;');
libALASQL('ATTACH INDEXEDDB DATABASE example;');
libALASQL('USE example;');
fable.ALASQL = libALASQL;



// Create a new meadow DAL object for the "Customers" data set
var meadow = require('meadow').new(fable, 'Customers')
		.setProvider('ALASQL')
		.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);
		}
	);

Current Tags

  • 1.0.29                                ...           latest (a year ago)

41 Versions

  • 1.0.29                                ...           a year ago
  • 1.0.28                                ...           2 years ago
  • 1.0.26                                ...           2 years ago
  • 1.0.25                                ...           2 years ago
  • 1.0.22                                ...           2 years ago
  • 1.0.21                                ...           2 years ago
  • 1.0.20                                ...           3 years ago
  • 1.0.19                                ...           4 years ago
  • 1.0.18                                ...           4 years ago
  • 1.0.17                                ...           4 years ago
  • 1.0.16                                ...           4 years ago
  • 1.0.15                                ...           4 years ago
  • 1.0.14                                ...           4 years ago
  • 1.0.13                                ...           4 years ago
  • 1.0.12                                ...           4 years ago
  • 1.0.11                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 0.1.17                                ...           5 years ago
  • 0.1.16                                ...           5 years ago
  • 0.1.15                                ...           5 years ago
  • 0.1.14                                ...           5 years ago
  • 0.1.13                                ...           5 years ago
  • 0.1.12                                ...           5 years ago
  • 0.1.11                                ...           5 years ago
  • 0.1.10                                ...           5 years ago
  • 0.1.9                                ...           5 years ago
  • 0.1.8                                ...           5 years ago
  • 0.1.7                                ...           5 years ago
  • 0.1.6                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |