{"id":17482789,"url":"https://github.com/creationix/couch-client","last_synced_at":"2025-04-10T02:44:07.236Z","repository":{"id":1032394,"uuid":"860720","full_name":"creationix/couch-client","owner":"creationix","description":"A minimal CouchDB client that easy and powerful","archived":false,"fork":false,"pushed_at":"2011-10-05T05:03:15.000Z","size":450,"stargazers_count":101,"open_issues_count":17,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T04:14:41.809Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creationix.png","metadata":{"files":{"readme":"README.markdown","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":"2010-08-25T03:51:49.000Z","updated_at":"2025-01-22T20:16:09.000Z","dependencies_parsed_at":"2022-08-16T11:50:35.393Z","dependency_job_id":null,"html_url":"https://github.com/creationix/couch-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fcouch-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fcouch-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fcouch-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fcouch-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creationix","download_url":"https://codeload.github.com/creationix/couch-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248145607,"owners_count":21055168,"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-18T23:44:30.817Z","updated_at":"2025-04-10T02:44:07.214Z","avatar_url":"https://github.com/creationix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Couch Client\n\nCouch Client is a simple wrapper around CouchDB's http interface.\n\n\u003e \"CouchDB is a document-oriented, Non-Relational Database Management Server (NRDBMS).\"\n\nThis wrapper/driver implements some nice things like request batching and automatic revision and key generation. Usage should be simple and straight-forward. For anything advanced, a simple http client is exposed that already connected to the couch server.\n\n## `CouchClient(url)` - A client factory\n\nThis module exports a single factory function called `CouchClient`.  Usage is simple, it takes a single url for the connection to the database.\n\n    var CouchClient = require('couch-client');\n    var Users = CouchClient(\"http://username:password@yourhost:5984/users\");\n\nSince this assumes many defaults, for local testing on a stock CouchDB build, you can connect with simply `CouchCLient(\"/users\")`.\n\nThis object will internally keep track of revisions it's seen before and batches http requests that happen in the same \"tick\" to go out at the same time using CouchDB's batch processing APIs.\n\nThe resulting object has the following four functions (`save`, `get`, `remove`, `request`);\n\nThe default port is 5984.\n\n### `CouchClient.save(doc, callback)` - Save a document\n\nPass in a document and it will save it to the database.  If the document happens to have a `_id` property that that will be used as the key.  Also if the document has a `_rev` property, that will be passed to the server.  If they are missing, CouchClient will provide an automatic UUID using CouchDB's services and look up the latest revision.  Revisions are remembered.\n\n    Users.save({_id: \"creationix\", name: \"Tim Caswell\", age: 28}, function ( err, doc) {\n      // You know know if there was an error and have an updated version\n      // of the document (with `_id` and `_rev`).\n    });\n\n### `CouchClient.get(key, callback)` - Load a document\n\nOnce you put data in the database, it's nice to be able to load it back out.  The `.get()` function takes a key as a string and returns the document in a callback.\n\n    Users.get(\"creationix\", function (err, doc) {\n      // Now you have the document or error if there was trouble\n    });\n\n### `CouchClient.view(path, obj, callback)` - Call a view\n\n`view` takes a path to a view, an object containing GET parameters, and a callback\n\n    Users.view('/users/_design/design_name/_view/usernames', {key: \"creationix\"}, function(err, doc) {\n        // Now you have the document(s) or error if there was trouble\n    });\n\nIf `obj` is missing then it returns all the items in the view.\n\n### `CouchClient.remove(key/doc, callback)` - Remove a document\n\nSometimes you want to remove documents from the database.  This function takes either a key as a string or a document with an `_id` property.  It will tell couch to delete it and give you back the modified document with the `_deleted` property.\n\n    Users.remove(\"creationix\", function (err, doc) {\n      // If there was no error, it's gone\n    });\n\n### `CouchClient.request(method, path, body, callback)` - Arbitrary HTTP request.\n\nThis is the helper used internally to execute HTTP requests against the CouchDB database.  It's exposed here because CouchDB provides a very rich interface, and it can't all be easily wrapped.  The `body` parameter is optional and should be passed in as a raw JavaScript object.\n\n    Users.request(\"GET\", \"/some_database/_design/company/_view/all\", function (err, result) {\n      // result is a javascript object of CouchDB's response JSON\n    });\n\n    // Manually insert a single document\n    Users.request(\"PUT\", \"/foo/bar\", {Foo:\"Bar\"}, function (err, result) {\n      // result is a javascript object of CouchDB's response JSON\n    });\n\nAlso if you omit the callback an `EventEmitter` object that emits `\"data\"`, `\"end\"`, and `\"error\"` events.  Note that the data events are not parsed.  They are raw `utf8` strings.\n\n### `CouchClient.changes(since, callback)` - Watch for changes to the database.\n\nCouchDB provides a neat feature known as the `_changes` feed.  This allows you do watch a database and be notified when it's changed.  The `changes()` function is a wrapper.  You give it the `since` parameter and a callback.  The callback is called once per JSON document in the response stream.\n\n\n## Testing\n\nThe basicTests file currently tests a;\n* local couchdb instance, with no authorization setup. \n* couchone instance with authorization at https://couch-client.couchone.com/_utils couch-client:testingonly\n\n\n### Adding Tests\n\nAdd tests to the basicTests.js file. Test function names need to start with 'test'.\n    \n\ttestSomething:function() {\n\t\t// testing something\n\t},\n\n\n## Contributing\n\n* please include tests with your pull requests.\n\n\n## Changes from 0.0.3 -\u003e 0.0.4\n\n* view improvements / fixes\n* basic auth support\n\n\n### Contributors\n\nflashingpumpkin\ndready92\ndevioustree\nhij1nx\nsteelThread\ncandland\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fcouch-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreationix%2Fcouch-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fcouch-client/lists"}