{"id":15554173,"url":"https://github.com/crate/activerecord-crate-adapter","last_synced_at":"2025-05-13T13:09:51.851Z","repository":{"id":15925531,"uuid":"18667373","full_name":"crate/activerecord-crate-adapter","owner":"crate","description":"Ruby on Rails ActiveRecord adapter for CrateDB","archived":false,"fork":false,"pushed_at":"2024-09-01T04:54:17.000Z","size":102,"stargazers_count":26,"open_issues_count":11,"forks_count":7,"subscribers_count":42,"default_branch":"main","last_synced_at":"2025-05-08T07:48:19.652Z","etag":null,"topics":["activerecord","cratedb","database","rails","ruby","ruby-gem","ruby-library","ruby-on-rails","sql","sql-database"],"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/crate.png","metadata":{"files":{"readme":"README.md","changelog":"history.txt","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2014-04-11T08:23:13.000Z","updated_at":"2023-07-19T17:42:53.000Z","dependencies_parsed_at":"2024-02-19T09:52:36.857Z","dependency_job_id":"6ec475e3-e780-478d-8907-6131609463d1","html_url":"https://github.com/crate/activerecord-crate-adapter","commit_stats":{"total_commits":62,"total_committers":10,"mean_commits":6.2,"dds":0.4193548387096774,"last_synced_commit":"2bc80929683adac6c0e0e702161f02b36207b7c1"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crate%2Factiverecord-crate-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crate%2Factiverecord-crate-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crate%2Factiverecord-crate-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crate%2Factiverecord-crate-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crate","download_url":"https://codeload.github.com/crate/activerecord-crate-adapter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253948432,"owners_count":21988957,"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","cratedb","database","rails","ruby","ruby-gem","ruby-library","ruby-on-rails","sql","sql-database"],"created_at":"2024-10-02T14:51:14.166Z","updated_at":"2025-05-13T13:09:51.753Z","avatar_url":"https://github.com/crate.png","language":"Ruby","readme":"[![Gem version](https://badge.fury.io/rb/activerecord-crate-adapter.svg)](https://rubygems.org/gems/activerecord-crate-adapter)\n[![Build status](https://github.com/crate/activerecord-crate-adapter/actions/workflows/tests.yml/badge.svg)](https://github.com/crate/activerecord-crate-adapter/actions/workflows/tests.yml)\n[![Code Climate](https://codeclimate.com/github/crate/activerecord-crate-adapter.png)](https://codeclimate.com/github/crate/activerecord-crate-adapter)\n\n\n## About\n\nThe Ruby on Rails ActiveRecord adapter for [CrateDB],\nusing the [crate_ruby] driver with HTTP connectivity.\n\n**Note:** The `activerecord-crate-adapter` currently only works with Rails 4.1.x.\n\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n    gem 'activerecord-crate-adapter'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install activerecord-crate-adapter\n\n## Usage\n\nWhen using Rails update your database.yml\n\n     development:\n       adapter: crate\n       host: 127.0.0.1\n       port: 4200\n\nCrateDB doesn't come with an autoincrement feature for your model ids. So you need to set\nit yourself. One way is to use `SecureRandom.uuid`, if you think there is a better one,\nplease add an issue, so we can discuss.\n\n    class Post \u003c ActiveRecord::Base\n\n      before_validation :set_id, on: :create\n\n      private\n\n      def set_id\n        self.id = SecureRandom.uuid\n      end\n\n    end\n\n## Special data types\n\n### Array\nYou can simply create Array columns by specifying `t.array` and passing `array_type` when you create a migration.\n\n    t.array :tags, array_type: :string\n    t.array :votes, array_type: :integer\n    t.array :bool_arr, array_type: :boolean\n\nWhen you create an object just pass your Array directly\n\n    Post.create!(title: 'Arrays are awesome', tags: %w(hot fresh), votes: [1,2])\n    post = Post.where(\"'fresh' = ANY (tags)\")\n\n### Object\nCrateDB allows you to define nested objects. I tried to make it as simply as possible to use and reuse existing AR functionality,\nI therefore ask you to reuse the existing serialize functionality. `AR#serialize` allows you to define your own serialization\nmechanism, and we simply reuse that for serializing an AR object. To get serialize working simply create `#dump` and `#load` methods\non the class that creates a literal statement that is then used in the SQL. Read up more in this [commit about array and object literals].\n\nI tried to make your guys life easier and created a module that does this automatically for you. Simply make all attributes accessible\nand assign it in the initializer. So a serialized class should look like this:\n\n    require 'active_record/attribute_methods/crate_object'\n\n    class Address\n      attr_accessor :street, :city, :phones, :zip\n\n      include CrateObject\n\n      def initialize(opts)\n        @street = opts[:street]\n        @city = opts[:city]\n        @phones = opts[:phones]\n        @zip = opts[:zip]\n      end\n\n    end\n\nCheck out the `CrateObject` module if you need to write your own serializer.\n\nThen in your model simply use `#serialize` to have objects working.\n\n      class User \u003c ActiveRecord::Base\n        serialize :address, Address\n      end\n\nNote: I do not plan to support nested objects inside objects.\n\n#### Object Migrations\n\nIn the migrations, you can create an object, specify the object behaviour \n`(strict|dynamic|ignored)`, and its schema.\n\n    t.object :address, object_schema_behaviour: :strict,\n                       object_schema: {street: :string, city: :string, phones: {array: :string}, zip: :integer}\n\n\n\n## Migrations\n\nCurrently, adding and dropping indices is not support by CrateDB, see [issue #733].\n\n    # not supported by CrateDB yet\n    add_index :posts, :comment_count\n    remove_index :posts, :comment_count\n\n\n## Caveats\n\nCrateDB is eventually consistent, that means if you create a record, and query\nfor it right away, it won't work (except queries for the primary key).\n\nIn this context, read more about the [`REFRESH TABLE`] statement.\n\n## Tests\n\nSee [DEVELOP.md](DEVELOP.md).\n\n\n## Contributing\n\nIf you think something is missing, either create a pull request\nor log a new issue, so someone else can tackle it.\nPlease refer to [CONTRIBUTING.rst](CONTRIBUTING.rst) for further information.\n\n## Maintainers\n\n* [Crate.IO GmbH](https://crate.io)\n* [Christoph Klocker](http://vedanova.com), [@corck](https://twitter.com/corck)\n\n## License\n\nThis project is licensed under the [Apache License 2.0].\n\n\n[Apache License 2.0]: https://github.com/crate/activerecord-crate-adapter/blob/master/LICENSE\n[commit about array and object literals]: https://github.com/crate/crate/commit/16a3d4b3f2\n[CrateDB]: https://github.com/crate/crate\n[crate_ruby]: https://github.com/crate/crate_ruby\n[issue #733]: https://github.com/crate/crate/issues/733\n[`REFRESH TABLE`]: https://crate.io/docs/crate/reference/en/latest/general/dql/refresh.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrate%2Factiverecord-crate-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrate%2Factiverecord-crate-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrate%2Factiverecord-crate-adapter/lists"}