Meadow
A Javascript Data Broker.
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.
var databaseSettings = {
MySQL:
{
Server: "localhost",
Port: 3306,
User: "root",
Password: "",
Database: "sales_data",
ConnectionPoolLimit: 20
}
};
var fable = require('fable').new();
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
}
);
var meadow = require('meadow').new(fable, 'Customers')
.setProvider('MySQL')
.setDefaultIdentifier('customerID');
var queryDescription = meadow.query.addFilter('customerID', 17);
meadow.doRead(queryDescription,
function(error, query, customer)
{
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
var fable = require('fable').new();
var libALASQL = require('alasql');
libALASQL('CREATE INDEXEDDB DATABASE IF NOT EXISTS example;');
libALASQL('ATTACH INDEXEDDB DATABASE example;');
libALASQL('USE example;');
fable.ALASQL = libALASQL;
var meadow = require('meadow').new(fable, 'Customers')
.setProvider('ALASQL')
.setDefaultIdentifier('customerID');
var queryDescription = meadow.query.addFilter('customerID', 17);
meadow.doRead(queryDescription,
function(error, query, customer)
{
if (error)
{
return console.log('Error querying customer data: '+error);
}
console.log('Found customer ID '+customer.customerID+' who is named '+customer.name);
}
);