almaden
v0.3.1
Published
ES6 data adapter.
Downloads
11
Readme
Almaden.js
Universal data adapter providing a normalized interface for interacting with data sources on servers and browsers.
import Database from "almaden";
const database = new Database({
"debug": false,
"client": "mysql",
"connection": {
"host": "localhost",
"user": "root",
"password": "",
"database": "almaden_test"
}
});
database
.insert({name:"Bob"})
.into("users")
.results((error, rows) => {
});
Quality and Compatibility
Every build and release is automatically tested on the following platforms:
If your platform is not listed above, you can test your local environment for compatibility by copying and pasting the following commands into your terminal:
npm install almaden
cd node_modules/almaden
gulp test-local
Features
Normalized Interface
Knex.js:
knex
.select("*")
.from("users")
.where("id", 1);
knex("users")
.insert({name:"Bob"});
knex.schema
.createTable("users", tableConstructor);
Almaden.js:
database
.select("*")
.from("users")
.where("id", 1);
database
.insert({name:"Bob"})
.into("users");
database
.creatTable("users", tableConstructor);
Built-In Mocking
const mockResponseData = [
{id:1,name:"Bob"},
{id:2,name:"Gary"}
];
database.mock({
"select * from users":
mockResponseData,
"select * from users where id=#$@#$":
new Error("This is a mocked error response."),
/select \* from users where id=[a-zA-Z]*/:
new Error("ID must be numeric.")
});
database
.select("*")
.from("users")
.results((error, rows) => {
rows.should.eql(mockResponseData); // true
});
database
.select("*")
.from("users")
.where("id", "#$@#$")
.results((error, rows) => {
error.message.should.eql("This is a mocked error response.")
});
database
.select("*")
.from("users")
.where("id", "abc")
.results((error, rows) => {
error.message.should.eql("ID must be numeric.")
});
Built-In Spying
const spyResponseData = [
{id:1,name:"Bob"},
{id:2,name:"Gary"}
];
//string or regex
let selectQuerySpy = database.spy("select * from `users`", spyResponseData);
let deleteQuerySpy = this.database.spy(/select * from `users` where `id` = '[0-9]*'/, {id: 5, name: "Jane"});
database
.select("*")
.from("users")
.results((error, rows) => {
rows.should.eql(spyResponseData); // true
});
database
.select("*")
.from("users")
.where("id", "1")
.results((error, rows) => {
//do something with Jane...
});
selectQuerySpy.callCount.should.equal(1);
deleteQuerySpy.callCount.should.equal(1);
Portable Queries
const query = database.select("*");
typeof query; // Query
query.where("id", 4);
query.results((error, rows) => {
// Do something with the results
});
Installation
Copy and paste the following command into your terminal to install Almaden:
npm install almaden --save
Import / Require
// ES6
import almaden from "almaden";
// ES5
var almaden = require("almaden");
// Require.js
define(["require"] , function (require) {
var almaden = require("almaden");
});
Getting Started
More insights
In order to say something, you should know that almaden()
... (add your test here)
How to Contribute
See something that could use improvement? Have a great feature idea? We listen!
You can submit your ideas through our issues system, or make the modifications yourself and submit them to us in the form of a GitHub pull request.
We always aim to be friendly and helpful.
Running Tests
It's easy to run the test suite locally, and highly recommended if you're using Almaden.js on a platform we aren't automatically testing for.
npm test