Mohican
Generalized database managment interface.
This is a collection of independent database managment systems, united by common interface, so it almost does not matter whether you use mongodb, mysql or postgresql.
Example
To use Mohican you must connect to existing database server:
// Connect to databasemohican;
And then do anything you need:
mc;
Features
MySQL provider for Mohican has some additional functionality. It is easy now to create complex SQL queries.
Create table
Now you just need to specify options for each field(column) using object syntax. For example, this SQL query
NOT EXISTS table (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), born DATETIME, foreignId INT, FOREIGN KEY(foreignId) REFERENCES anotherTable(id))
Will look like this:
const scheme = // id could be skipped, this is default id meta info // RECOMENDED: don`t use 'AUTO_INCREMENT' option for it id: type: 'INT' options: 'PRIMARY KEY' // specify type like string name: 'VARCHAR(255)' born: 'DATETIME' // or if you need more complex definition, use object definition foreignId: type: 'INT' reference: 'anotherTable.id' // create if not exists safe: true; mc;
Nested selection
Nested selection in SQL:
SELECT * FROM someTable WHERE someField = (SELECT field FROM anotherTable WHERE id = 12345);
Using Mohican it will look like:
const somefieldCursor = mc ; mc ;
JOIN
You can also easy implement multiple JOIN operations. So this:
SELECT table.field, anotherTable.anotherField FROM table JOIN anotherTable ON table.id = anotherTable.id WHERE table.id > 10
Could be written like this:
mc ;
See documentation for more info