{"id":31658343,"url":"https://github.com/couchbase/couchbase-ruby-model","last_synced_at":"2025-10-07T15:19:46.934Z","repository":{"id":4804944,"uuid":"5958282","full_name":"couchbase/couchbase-ruby-model","owner":"couchbase","description":"The Active Model implementation for Couchbase Server built on couchbase-ruby-client","archived":false,"fork":false,"pushed_at":"2015-10-21T16:03:51.000Z","size":549,"stargazers_count":61,"open_issues_count":15,"forks_count":23,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-09-06T23:23:00.325Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/couchbase.png","metadata":{"files":{"readme":"README.markdown","changelog":"HISTORY.markdown","contributing":"CONTRIBUTING.markdown","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-25T23:41:24.000Z","updated_at":"2023-07-27T19:37:17.000Z","dependencies_parsed_at":"2022-08-18T00:11:01.118Z","dependency_job_id":null,"html_url":"https://github.com/couchbase/couchbase-ruby-model","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/couchbase/couchbase-ruby-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase%2Fcouchbase-ruby-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase%2Fcouchbase-ruby-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase%2Fcouchbase-ruby-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase%2Fcouchbase-ruby-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchbase","download_url":"https://codeload.github.com/couchbase/couchbase-ruby-model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchbase%2Fcouchbase-ruby-model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278679774,"owners_count":26027160,"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-10-06T02:00:05.630Z","response_time":65,"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":[],"created_at":"2025-10-07T15:19:46.136Z","updated_at":"2025-10-07T15:19:46.930Z","avatar_url":"https://github.com/couchbase.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Couchbase Model\n\nThis library allows to declare models for [couchbase gem][1].\n\n## SUPPORT\n\nIf you found an issue, please file it in our [JIRA][3]. Also you are\nalways welcome on `#libcouchbase` channel at [freenode.net IRC servers][4].\n\nDocumentation: [http://rdoc.info/gems/couchbase-model](http://rdoc.info/gems/couchbase-model)\n\n## Rails integration\n\nTo generate config you can use `rails generate couchbase:config`:\n\n    $ rails generate couchbase:config\n    create  config/couchbase.yml\n\nIt will generate this `config/couchbase.yml` for you:\n\n    common: \u0026common\n      hostname: localhost\n      port: 8091\n      username:\n      password:\n      pool: default\n\n    development:\n      \u003c\u003c: *common\n      bucket: couchbase_tinyurl_development\n\n    test:\n      \u003c\u003c: *common\n      bucket: couchbase_tinyurl_test\n\n    # set these environment variables on your production server\n    production:\n      hostname: \u003c%= ENV['COUCHBASE_HOST'] %\u003e\n      port: \u003c%= ENV['COUCHBASE_PORT'] %\u003e\n      username: \u003c%= ENV['COUCHBASE_USERNAME'] %\u003e\n      password: \u003c%= ENV['COUCHBASE_PASSWORD'] %\u003e\n      pool: \u003c%= ENV['COUCHBASE_POOL'] %\u003e\n      bucket: \u003c%= ENV['COUCHBASE_BUCKET'] %\u003e\n\n## Examples\n\n    require 'couchbase/model'\n\n    class Post \u003c Couchbase::Model\n      attribute :title\n      attribute :body\n      attribute :draft\n    end\n\n    p = Post.new(:id =\u003e 'hello-world',\n                 :title =\u003e 'Hello world',\n                 :draft =\u003e true)\n    p.save\n    p = Post.find('hello-world')\n    p.body = \"Once upon the times....\"\n    p.save\n    p.update(:draft =\u003e false)\n    Post.bucket.get('hello-world')  #=\u003e {\"title\"=\u003e\"Hello world\", \"draft\"=\u003efalse,\n                                    #    \"body\"=\u003e\"Once upon the times....\"}\n\nYou can also let the library generate the unique identifier for you:\n\n    p = Post.create(:title =\u003e 'How to generate ID',\n                    :body =\u003e 'Open up the editor...')\n    p.id        #=\u003e \"74f43c3116e788d09853226603000809\"\n\nThere are several algorithms available. By default it use `:sequential`\nalgorithm, but you can change it to more suitable one for you:\n\n    class Post \u003c Couchbase::Model\n      attribute :title\n      attribute :body\n      attribute :draft\n\n      uuid_algorithm :random\n    end\n\nYou can define connection options on per model basis:\n\n    class Post \u003c Couchbase::Model\n      attribute :title\n      attribute :body\n      attribute :draft\n\n      connect :port =\u003e 80, :bucket =\u003e 'blog'\n    end\n\n## Validations\n\nThere are all methods from ActiveModel::Validations accessible in\ncontext of rails application:\n\n    class Comment \u003c Couchbase::Model\n      attribute :author, :body\n\n      validates_presence_of :author, :body\n    end\n\n## Views (aka Map/Reduce indexes)\n\nViews are stored in models directory in subdirectory named after the\nmodel (to be precious `design_document` attribute of the model class).\nHere is an example of directory layout for `Link` model with three\nviews.\n\n    .\n    └── app\n        └── models\n            ├── link\n            │   ├── total_count\n            │   │   ├── map.js\n            │   │   └── reduce.js\n            │   ├── by_created_at\n            │   │   └── map.js\n            │   └── by_view_count\n            │       └── map.js\n            └── link.rb\n\nTo generate view you can use yet another generator `rails generate\ncouchbase:view DESIGNDOCNAME VIEWNAME`. For example how `total_count`\nview could be generated:\n\n    $ rails generate couchbase:view link total_count\n\nThe generated files contains useful info and links about how to write\nmap and reduce functions, you can take a look at them in the [templates\ndirectory][2].\n\nIn the model class you should declare accessible views:\n\n    class Post \u003c Couchbase::Model\n      attribute :title\n      attribute :body\n      attribute :draft\n      attribute :view_count\n      attribute :created_at, :default =\u003e lambda { Time.now }\n\n      view :total_count, :by_created_at, :by_view_count\n    end\n\nAnd request them later:\n\n    Post.by_created_at(:include_docs =\u003e true).each do |post|\n      puts post.title\n    end\n\n    Post.by_view_count(:include_docs =\u003e true).group_by(\u0026:view_count) do |count, posts|\n      p \"#{count} -\u003e #{posts.map{|pp| pp.inspect}.join(', ')}\"\n    end\n\n\n[1]: https://github.com/couchbase/couchbase-ruby-client/\n[2]: https://github.com/couchbase/couchbase-ruby-model/blob/master/lib/rails/generators/couchbase/view/templates/\n[3]: http://couchbase.com/issues/browse/RCBC\n[4]: http://freenode.net/irc_servers.shtml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase%2Fcouchbase-ruby-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchbase%2Fcouchbase-ruby-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchbase%2Fcouchbase-ruby-model/lists"}