{"id":13630233,"url":"https://github.com/maxlath/couch-init2","last_synced_at":"2025-08-12T00:40:32.031Z","repository":{"id":56824037,"uuid":"52176418","full_name":"maxlath/couch-init2","owner":"maxlath","description":"Opiniated CouchDB databases initializer","archived":false,"fork":false,"pushed_at":"2023-11-30T14:48:34.000Z","size":502,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T03:46:22.774Z","etag":null,"topics":["couchdb","design-docs","init"],"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/maxlath.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-02-20T21:26:58.000Z","updated_at":"2023-11-07T03:11:38.000Z","dependencies_parsed_at":"2024-01-14T08:53:38.206Z","dependency_job_id":null,"html_url":"https://github.com/maxlath/couch-init2","commit_stats":{"total_commits":99,"total_committers":1,"mean_commits":99.0,"dds":0.0,"last_synced_commit":"4521e8beab62fa2f06d7935c7a4519a6bf0871cf"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/maxlath/couch-init2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fcouch-init2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fcouch-init2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fcouch-init2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fcouch-init2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxlath","download_url":"https://codeload.github.com/maxlath/couch-init2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxlath%2Fcouch-init2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269689792,"owners_count":24459712,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["couchdb","design-docs","init"],"created_at":"2024-08-01T22:01:35.001Z","updated_at":"2025-08-12T00:40:32.000Z","avatar_url":"https://github.com/maxlath.png","language":"JavaScript","readme":"# couch-init2\n\n[![npm package](http://img.shields.io/npm/v/couch-init2.svg?style=flat-square)](https://www.npmjs.com/package/couch-init2)\n[![node](https://img.shields.io/badge/node-v4.3.x-brightgreen.svg)](http://nodejs.org)\n\n**An opiniated CouchDB databases initializer**\n\nTakes a list of databases to initialise and their design docs, and make sure that everything is up and running and in sync.\n\n### Installation\n\nin a terminal, at the root of your project\n```sh\n# ESM\nnpm install couch-init2\n# CommonJS\nnpm install couch-init2@5\n```\n\n### How To\n\n```javascript\nimport couchInit from 'couch-init2'\n\nconst dbUrl = 'http://username:password@localhost:5984'\nconst dbsList = [\n   {\n     name: 'dbname1',\n     designDocs: ['designdoc1']\n   },\n   {\n     name: 'dbname2',\n     designDocs: ['designdoc2', 'designdoc3']\n   },\n   {\n     name: 'dbname3',\n     designDocs: []\n   }\n ]\n// Path to the folder where design docs can be found on the model `${designDocName}.json`\n// If a design doc file from the list is missing, it will be created with a basic design doc structure\n// If a design doc file changed, the database design doc will be updated\nconst designDocFolder = '/path/to/your/design/docs/folder'\n\nconst { ok, operations } = await couchInit(dbUrl, dbsList, designDocFolder)\nconsole.log('ok', res.ok)\nconsole.log('operations', res.operations)\n// dbs were successfully initialized!\n// time to start your server or whatever crazy thing you're building :)\n```\n\n### Design docs formats\n#### json\nThe JSON format is identical to the document in database, minus the `_rev` id.\n```json\n{\n  \"_id\": \"_design/example\",\n  \"language\": \"javascript\",\n  \"views\": {\n    \"byFoo\": {\n      \"map\": \"function (doc) {\\n  if (doc.foo) emit(doc.foo, 1)\\n}\"\n    }\n  }\n}\n```\n\n#### js\nThe JS format allows to use a JS module that exports just the `views` object, the `_id` being deduced from the filename (ex: if the file is named `foo.js`, the `_id` will be `_design/foo`)\n```js\nexport default {\n  byFoo: {\n    map: function (doc) {\n      if (doc.foo) emit(doc.foo, 1)\n    },\n    reduce: function(keys, values) {\n      return values.reduce((a, b) =\u003e a + b, 0)\n    },\n  },\n  byBar: {\n    // The function stringification won't be able to detect variables in scope.\n    // In this case, you have to pass the function and its dependencies as a string.\n    map: `\n      const double = num =\u003e num * 2\n\n      function (doc) {\n        if (doc.foo) emit(doc.foo, double(1))\n      }`,\n  },\n  byBuzz: {\n    // Alternatively, an array of functions can be passed to preserve text editor\n    // features such as syntax highlighting or linting\n    map: [\n      function double (num) { num * 2 },\n      function (doc) {\n        if (doc.example) emit(doc.example, double(1))\n      }\n    ]\n  },\n}\n```\n\n### What it does\n\n* create databases if missing\n* create or update design documents if not up-to-date\n* create [security documents](http://docs.couchdb.org/en/1.6.1/api/database/security.html) if missing\n\n## See also\n* [couchdb-bootstrap](https://github.com/jo/couchdb-bootstrap): Bootstrap CouchDB projects: configure, setup security, deploy ddocs and create users.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlath%2Fcouch-init2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxlath%2Fcouch-init2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxlath%2Fcouch-init2/lists"}