Mongoose-SQL
Mongoose compatible interface for PostgreSQL
Mongoose-SQL covers the basic API surface of Mongoose [ORM for Mongo] to interface and migrate data to PostgreSQL. This is effectively a small ORM over PostgreSQL that resembles the Mongoose API.
This library requires ES6 with Node.JS 6+ and uses Knex to interface with PostgreSQL.
npm install mongoose-sql
var db = ;var e = processenvironment; // Create connection: note default environment variables// returns a Knex instancedb; // Get Knex instance if neededvar knex = db; // Use Mongoose-like operations upon PostgreSQL tablesvar Cat_Schema = CatModel;var Cat = db;Cat; // find() returns all rowsCat; // find by row idCat; // findOneCat; // find by whereCat; // sortCat; // outer left join var simba = CatObject ;simba;simba; // Migrations (WIP)var mongoose = ; // instance Mongoosevar Cat_Schema_Mongo = CatModel; // make a mongoose schemavar Cat_Mongo = mongoose; // make a mongoose modeldb;
Mongoose API reference: http://mongoosejs.com/index.html
note that not all Mongoose apis are covered
Migrations (WIP)
Based client Schema definitions, the library will try to create PostgreSQL tables with fields of the right types.
- One-to-one relationships will have foreign key constraints
- Many-to-many relationships will get their own link table
- Object or list of object key values (without schema links) will become jsonb fields