{"id":15431990,"url":"https://github.com/ritikesh/active_record_lite","last_synced_at":"2025-03-29T14:25:23.441Z","repository":{"id":59150368,"uuid":"192333659","full_name":"ritikesh/active_record_lite","owner":"ritikesh","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-05T15:47:15.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-27T03:23:27.976Z","etag":null,"topics":["activerecord","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/ritikesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-17T11:27:50.000Z","updated_at":"2023-01-05T15:45:54.000Z","dependencies_parsed_at":"2023-02-04T07:01:30.749Z","dependency_job_id":null,"html_url":"https://github.com/ritikesh/active_record_lite","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritikesh%2Factive_record_lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritikesh%2Factive_record_lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritikesh%2Factive_record_lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ritikesh%2Factive_record_lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ritikesh","download_url":"https://codeload.github.com/ritikesh/active_record_lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246194842,"owners_count":20738754,"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":["activerecord","ruby","ruby-on-rails"],"created_at":"2024-10-01T18:24:48.736Z","updated_at":"2025-03-29T14:25:23.417Z","avatar_url":"https://github.com/ritikesh.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveRecordLite\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/ritikesh/active_record_lite/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/ritikesh/active_record_lite/tree/master)\n[![Gem Version](https://badge.fury.io/rb/active_record_lite.svg)](https://badge.fury.io/rb/active_record_lite)\n\nLightweight ActiveRecord extension for basic reads and caching.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_record_lite'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install active_record_lite\n\n## Usage\n\nTo start using lite models, inject `has_lite` in your model and append `.to_lite` to your `ActiveRecord` `scope` or `chained` method calls.\n\n```ruby\n    class User \u003c ActiveRecord::Base\n        has_lite\n    end\n\n    @user = User.where(id: 1).to_lite # \u003cUser::ActiveRecordLite... \u003e\n    @user.id # =\u003e 1\n    @user.name # =\u003e \"name\"\n\n    @users = User.where(tenant_id: 1).to_lite # [\u003cUser::ActiveRecordLite... \u003e, ...]\n    @users.first.id # =\u003e 1\n    @users[-1].id # =\u003e 100\n```\n\nBy default the lite class will include all columns defined in the parent model class. To limit to specific columns, pass the columns key to the `has_lite` call.\n\n```ruby\n    class User \u003c ActiveRecord::Base\n        has_lite, columns: %w(id name)\n    end\n\n    @user = User.where(id: 1).to_lite\n    @user.id # =\u003e 1\n    @user.name # =\u003e \"name\"\n\n    @user.email # =\u003e undefined method\n```\n\nFor specific use-cases, you can also limit loading the number of columns by passing the selectable columns to `to_lite`.\n\n```ruby\n    class User \u003c ActiveRecord::Base\n        has_lite, columns: %w(id name email)\n    end\n\n    @user = User.where(id: 1).to_lite(:id, :name) # select id, name from users where id = 1;\n    @user.id # =\u003e 1\n    @user.name # =\u003e \"name\"\n\n    @user.email # =\u003e nil\n```\n\n#### NOTE:\n1. active_record_lite internally uses active_record, hence model level default scopes will apply when querying for the record from db.\n\n2. `to_lite` should be called after all `serialize` calls in the model. `to_lite` relies on `serialised_attributes` which will be correctly initialised only after all the `serialize` calls.\n\n#### TODO:\n1. Add support to eager load lite objects via AR relation.currently.\n\n## Development\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ritikesh/active_record_lite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ActiveRecordLite project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_record_lite/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritikesh%2Factive_record_lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fritikesh%2Factive_record_lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fritikesh%2Factive_record_lite/lists"}