{"id":15731850,"url":"https://github.com/jadbox/mongoose-sql","last_synced_at":"2025-05-07T02:40:55.548Z","repository":{"id":15050088,"uuid":"77486650","full_name":"jadbox/mongoose-sql","owner":"jadbox","description":"Mongoose compatible interface for PostgreSQL","archived":false,"fork":false,"pushed_at":"2022-01-03T18:22:16.000Z","size":122,"stargazers_count":33,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-24T05:01:53.272Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jadbox.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-27T22:39:15.000Z","updated_at":"2024-11-07T11:31:41.000Z","dependencies_parsed_at":"2022-07-22T11:32:33.717Z","dependency_job_id":null,"html_url":"https://github.com/jadbox/mongoose-sql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadbox%2Fmongoose-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadbox%2Fmongoose-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadbox%2Fmongoose-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jadbox%2Fmongoose-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jadbox","download_url":"https://codeload.github.com/jadbox/mongoose-sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252429931,"owners_count":21746571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-04T00:06:26.103Z","updated_at":"2025-05-07T02:40:55.523Z","avatar_url":"https://github.com/jadbox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose-SQL\n\nMongoose compatible interface for PostgreSQL\n\n\u003cimg height=\"224px\" src = \"http://t10.deviantart.net/l0aLpKFx8pPp4COINIGMRXIVWuQ=/fit-in/700x350/filters:fixed_height(100,100):origin()/pre05/503a/th/pre/f/2014/341/1/5/rikki_tikki_tavi_by_hidde99-d88zxp6.png\"/\u003e\n\nMongoose-SQL covers the basic API surface of [Mongoose](http://mongoosejs.com) [ORM for Mongo] to interface and migrate data to PostgreSQL. This is effectively a small ORM over PostgreSQL that resembles the Mongoose API.\n\nThis library requires ES6 with Node.JS 6+ and uses [Knex](http://knexjs.org/) to interface with PostgreSQL.\n\n```bash\nnpm install mongoose-sql\n```\n\n```js\nvar db = require(\"mongoose-sql\");\nvar e = process.environment;\n\n// Create connection: note default environment variables\n// returns a Knex instance\ndb.connect({\n    client: e.DB_CLIENT || \"pg\",\n    connection: {\n      host: e.DB_HOST || \"127.0.0.1\",\n      user: e.DB_USER || \"user\",\n      password: e.DB_PASSWORD || \"\",\n      database: e.DB_DATABASE || \"test\"\n    }\n});\n\n// Get Knex instance if needed\nvar knex = db.getKnex();\n\n// Use Mongoose-like operations upon PostgreSQL tables\nvar Cat_Schema = new db.Schema(CatModel);\nvar Cat = db.model(\"Cat\", Cat_Schema);\nCat.find().exec(myHandler); // find() returns all rows\nCat.findById(123).exec(myHandler); // find by row id\nCat.findOne({name: 'fluffy'}).exec(myHandler); // findOne\nCat.where({name: 'fluffy'}).findOne().exec(myHandler); // find by where\nCat.find().sort('breed').exec(myHandler); // sort\nCat.find().populate('owner').exec(myHandler); // outer left join\n\nvar simba = new Cat( { CatObject } );\nsimba.save(function() {\n\n});\nsimba.remove(function() {\n    \n});\n\n// Migrations (WIP)\nvar mongoose = require(\"mongoose\"); // instance Mongoose\nvar Cat_Schema_Mongo = new mongoose.Schema(CatModel); // make a mongoose schema\nvar Cat_Mongo = mongoose.model(\"Cat\", Cat_Schema_Mongo); // make a mongoose model\ndb.migrateSchemas([Cat_Mongo]).then(function() { // call migrateSchemas with model\n    console.log(\"moved data to PostgreSQL from Mongoose\");\n});\n```\n\nMongoose API reference:\n[http://mongoosejs.com/index.html](http://mongoosejs.com/index.html)\n### note that not all Mongoose apis are covered\n\n## Migrations (WIP)\n\nBased client Schema definitions, the library will try to create PostgreSQL tables with fields of the right types.\n\n* One-to-one relationships will have foreign key constraints\n* Many-to-many relationships will get their own link table\n* Object or list of object key values (without schema links) will become jsonb fields\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadbox%2Fmongoose-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjadbox%2Fmongoose-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjadbox%2Fmongoose-sql/lists"}