{"id":13463035,"url":"https://github.com/couchrest/couchrest_model","last_synced_at":"2025-03-25T06:31:30.238Z","repository":{"id":951329,"uuid":"732196","full_name":"couchrest/couchrest_model","owner":"couchrest","description":"Doing the simple stuff so you don't have to","archived":false,"fork":false,"pushed_at":"2024-05-09T12:24:18.000Z","size":4758,"stargazers_count":303,"open_issues_count":52,"forks_count":116,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-08T08:05:27.928Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/couchrest.png","metadata":{"files":{"readme":"README.md","changelog":"history.md","contributing":null,"funding":null,"license":"LICENSE","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":"2010-06-21T15:30:40.000Z","updated_at":"2025-03-04T05:09:23.000Z","dependencies_parsed_at":"2024-10-29T12:30:51.143Z","dependency_job_id":null,"html_url":"https://github.com/couchrest/couchrest_model","commit_stats":{"total_commits":1045,"total_committers":93,"mean_commits":"11.236559139784946","dds":0.7196172248803827,"last_synced_commit":"6c8467e0dd4bfdbd2405c73c2609d81b00651400"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchrest%2Fcouchrest_model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchrest%2Fcouchrest_model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchrest%2Fcouchrest_model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/couchrest%2Fcouchrest_model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/couchrest","download_url":"https://codeload.github.com/couchrest/couchrest_model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245413834,"owners_count":20611353,"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-07-31T13:00:44.580Z","updated_at":"2025-03-25T06:31:29.769Z","avatar_url":"https://github.com/couchrest.png","language":"Ruby","readme":"# CouchRest Model\n\n[![Build Status](https://travis-ci.org/couchrest/couchrest_model.png)](https://travis-ci.org/couchrest/couchrest_model)\n\nCouchRest Model helps you define models that are stored as documents in your CouchDB database.\n\nIt supports useful features such as setting properties with typecasting, callbacks, validations, associations, and helps\nwith creating CouchDB views to access your data.\n\nCouchRest Model uses ActiveModel for a lot of the magic, so if you're using Rails, you'll need at least version 3.0. Releases since 2.0.0 are Rails 4.0 compatible, and we recommend Ruby 2.0+.\n\n## Documentation\n\nPlease visit the documentation project at [http://www.couchrest.info](http://www.couchrest.info). Your [contributions](https://github.com/couchrest/couchrest.github.com) would be greatly appreciated!\n\nGeneral API: [http://rdoc.info/projects/couchrest/couchrest_model](http://rdoc.info/projects/couchrest/couchrest_model)\n\nSee the [update history](https://github.com/couchrest/couchrest_model/blob/master/history.md) for an up to date list of all the changes we've been working on recently.\n\n### Upgrading from an earlier version?\n\n*Pre 2.2:* As of August 2016, dirty tracking has been radically re-factored away from ActiveModel::Dirty, which only has support for basic attributes, into a solution that uses [Hashdiff](https://github.com/liufengyun/hashdiff), more details available in the [pull request](https://github.com/couchrest/couchrest_model/pull/211). The result is that some of ActiveModel's Dirty methods are no longer available, these are: `changes_applied`, `restore_attributes`, `previous_changes`, and `changed_attributes`.\n\n*Pre 2.0:* As of June 2012, couchrest model no longer supports the `view_by` and `view` calls from the model. Views are no only accessed via a design document. If you have older code and wish to upgrade, please ensure you move to the new syntax for using views.\n\n*Pre 1.1:* As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:\n\n```ruby\nCouchRest::Model::Base.configure do |config|\n  config.model_type_key = 'couchrest-type'\nend\n```\n\n## Install\n\n### Gem\n\n```bash\n$ sudo gem install couchrest_model\n```\n\n### Bundler\n\nIf you're using bundler, define a line similar to the following in your project's Gemfile:\n\n```ruby\ngem 'couchrest_model'\n```\n\n### Configuration\n\nCouchRest Model is configured to work out the box with no configuration as long as your CouchDB instance is running on the default port (5984) on localhost. The default name of the database is either the name of your application as provided by the `Rails.application.class.to_s` call (with /application removed) or just 'couchrest' if none is available.\n\nThe library will try to detect a configuration file at `config/couchdb.yml` from the Rails root or `Dir.pwd`. Here you can configuration your database connection in a Rails-like way:\n\n    development:\n      protocol: 'https'\n      host: sample.cloudant.com\n      port: 443\n      prefix: project\n      suffix: test\n      username: test\n      password: user\n\nNote that the name of the database is either just the prefix and suffix combined or the prefix plus any text you specify using `use_database` method in your models with the suffix on the end.\n\nThe example config above for example would use a database called \"project_test\". Here's an example using the `use_database` call:\n\n```ruby\nclass Project \u003c CouchRest::Model::Base\n  use_database 'sample'\nend\n\n# The database object would be provided as:\nProject.database     #=\u003e \"https://test:user@sample.cloudant.com:443/project_sample_test\"\n```\n\n### Using instead of ActiveRecord in Rails\n\nA common use case for a new project is to replace ActiveRecord with CouchRest Model, although they should work perfectly well together. If you no longer want to depend on ActiveRecord or any of its sub-dependencies such as sqlite, update your `config/application.rb` so the top looks something like:\n\n```ruby\n# We don't need active record, so load everything but:\n# require 'rails/all'\nrequire 'action_controller/railtie'\nrequire 'action_mailer/railtie'\nrequire 'rails/test_unit/railtie'\n```\n\nYou'll then need to make sure any references to `config.active_record` are removed from your environment files.\n\nor alternatively below command do the same work\n```ruby\nrails new \u003capplication-name\u003e --skip-active-record\n```\nNow in the gem file just add [couchrest_model] and you are good to go.\n\n## Generators\n\n### Configuration\n\n```bash\n$ rails generate couchrest_model:config\n```\n\n### Model\n\n```bash\n$ rails generate model person --orm=couchrest_model\n```\n\n## General Usage \n\n```ruby\nrequire 'couchrest_model'\n\nclass Cat \u003c CouchRest::Model::Base\n\n  property :name,      String\n  property :lives,     Integer, :default =\u003e 9\n\n  property :nicknames, [String]\n\n  timestamps!\n\n  design do\n    view :by_name\n  end\n\nend\n\n@cat = Cat.new(:name =\u003e 'Felix', :nicknames =\u003e ['so cute', 'sweet kitty'])\n\n@cat.new?   # true\n@cat.save\n\n@cat['name']   # \"Felix\"\n\n@cat.nicknames \u003c\u003c 'getoffdamntable'\n\n@cat = Cat.new\n@cat.update_attributes(:name =\u003e 'Felix', :random_text =\u003e 'feline')\n@cat.new? # false\n@cat.random_text  # Raises error!\n\n# Fetching by views, loading all results into memory\ncats = Cat.by_name.all\ncats.first.name # \"Felix\"\n\n# Streaming views, for efficient memory usage\nCat.by_name.all do |cat|\n  puts cat.name\nend\n```\n\n## Development\n\n### Preparations\n\nCouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:\n\n```bash\nbundle install\n```\n\nThat should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations\nuse different gems.\n\n### Testing\n\nThe most complete documentation is the spec/ directory. To validate your CouchRest install, from the project root directory run `bundle install` to ensure all the development dependencies are available and then `rspec spec` or `bundle exec rspec spec`.\n\nWe will not accept pull requests to the project without sufficient tests.\n\n## Contact\n\nPlease post bugs, suggestions and patches to the bug tracker at [http://github.com/couchrest/couchrest_model/issues](http://github.com/couchrest/couchrest_model/issues).\n\nFollow us on Twitter: [http://twitter.com/couchrest](http://twitter.com/couchrest)\n\nAlso, check [https://twitter.com/search?q=couchrest](https://twitter.com/search?q=couchrest)\n\n\n","funding_links":[],"categories":["Data Persistence"],"sub_categories":["CouchDB Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchrest%2Fcouchrest_model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcouchrest%2Fcouchrest_model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcouchrest%2Fcouchrest_model/lists"}