{"id":16260059,"url":"https://github.com/cludden/mycro-adapters","last_synced_at":"2025-04-08T13:50:09.833Z","repository":{"id":72389591,"uuid":"64980790","full_name":"cludden/mycro-adapters","owner":"cludden","description":"adapter hook for mycro apps","archived":false,"fork":false,"pushed_at":"2016-08-05T02:13:20.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T10:18:24.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cludden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-05T02:05:40.000Z","updated_at":"2016-08-05T02:09:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"d77a49cd-0efd-438f-b277-b7588d176205","html_url":"https://github.com/cludden/mycro-adapters","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"81e1b1a061c962b1ae2514628c7bae77e3c96171"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cludden%2Fmycro-adapters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cludden%2Fmycro-adapters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cludden%2Fmycro-adapters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cludden%2Fmycro-adapters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cludden","download_url":"https://codeload.github.com/cludden/mycro-adapters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247855116,"owners_count":21007495,"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-10T16:06:13.976Z","updated_at":"2025-04-08T13:50:09.799Z","avatar_url":"https://github.com/cludden.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mycro-adapters\na [mycro](https://github.com/cludden/mycro) hook for loading adapters.\n\n\n\n## Installing\n```bash\nnpm install --save mycro-adapters\n```\n\n\n\n## Getting Started\n*This hook assumes that the [mycro-containers](https://github.com/cludden/mycro-containers) hook has run prior to this hook.*\n\nDefine one or more connections:\n```javascript\n//in /connections/mongo.js\n\nconst adapter = require('mycro-mongoose');\n\nmodule.exports = {\n    adapter,\n    config: {\n        url: 'mongodb://\u003cusername\u003e:\u003cpassword\u003e@localhost:27017/my-database'\n    }\n};\n```\n\nDefine one or more models:\n```javascript\n// in /models/user.js\n\nmodule.exports = function(mycro) {\n\n    return function createUserModel(connection, Schema) {\n        const schema = new Schema({\n            first: String,\n            last: String,\n            email: String\n        },{\n            collection: 'users'\n        });\n\n        schema.statics.greet = function(greeting) {\n            const result = `${greeting} ${this.first}!`;\n            mycro.log('silly', result);\n            return result\n        }\n\n        return connection.model('user', schema);\n    }\n}\n```\n\n\n\n## Adapter API\nAdapter should follow the schema below.\n```javascript\n{\n    /**\n     * Optional post processing hook that receives the\n     * connection and a map of models registered by\n     * this adapter,\n     * @param  {*} connection - the connection instance returned by #registerConnection\n     * @param  {Object} models - a map of models registered to the connection\n     * @param  {Function} done\n     */\n    processModels(connection, models, done) {\n        // do some post processing here. return a new map of\n        // processed models\n        done(null, processed);\n    },\n\n\n    /**\n     * Create a new connection using the connection config defined in\n     * the connection file. The callback should return a connection\n     * instance.\n     * @param  {Object} config - connection config\n     * @param  {Function} done\n     */\n    registerConnection(config, done) {\n        // create a new connection using config\n        done(null, connection);\n    },\n\n\n    /**\n     * Register a model using the connection instance and the\n     * model definition.\n     * @param  {*} connection - the connection instance returned by #registerConnection\n     * @param  {*} modelDef - the model definition\n     * @param  {Function} done\n     */\n    registerModel(connection, modelDef, done) {\n        // create a new model and return it\n        done(null, model);\n    }\n}\n```\n\n\n\n## Testing\nrun tests  \n```javascript\nnpm test\n```\n\nrun coverage\n```javascript\nnpm run coverage\n```\n\n\n\n## Contributing\n1. [Fork it](https://github.com/cludden/mycro-adapters/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n\n\n## License\nCopyright (c) 2016 Chris Ludden.\nLicensed under the [MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcludden%2Fmycro-adapters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcludden%2Fmycro-adapters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcludden%2Fmycro-adapters/lists"}