All Projects → crate → activerecord-crate-adapter

crate / activerecord-crate-adapter

Licence: Apache-2.0 license
Ruby on Rails ActiveRecord adapter for CrateDB

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to activerecord-crate-adapter

crate ruby
A Ruby client library for CrateDB.
Stars: ✭ 31 (+14.81%)
Mutual labels:  ruby-library, ruby-gem, sql-database, cratedb
Ransack
Object-based searching.
Stars: ✭ 5,020 (+18492.59%)
Mutual labels:  ruby-library, ruby-gem, activerecord, ruby-on-rails
rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (-22.22%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
activerecord-setops
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Stars: ✭ 21 (-22.22%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (+3.7%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
Motion
Reactive frontend UI components for Rails in pure Ruby
Stars: ✭ 498 (+1744.44%)
Mutual labels:  ruby-gem, ruby-on-rails
React on rails
Integration of React + Webpack + Rails + rails/webpacker including server-side rendering of React, enabling a better developer experience and faster client performance.
Stars: ✭ 4,815 (+17733.33%)
Mutual labels:  ruby-gem, ruby-on-rails
Unscoped associations
🔦 Skip the default_scope in your associations (ActiveRecord)
Stars: ✭ 53 (+96.3%)
Mutual labels:  ruby-gem, activerecord
Rorvswild
Ruby on Rails app monitoring: performances & exceptions insights for rails developers.
Stars: ✭ 159 (+488.89%)
Mutual labels:  ruby-gem, ruby-on-rails
Devise masquerade
Extension for devise, enable login as functionality. Add link to the masquerade_path(resource) and use it.
Stars: ✭ 380 (+1307.41%)
Mutual labels:  ruby-gem, ruby-on-rails
Sidekiq Cron
Scheduler / Cron for Sidekiq jobs
Stars: ✭ 1,383 (+5022.22%)
Mutual labels:  ruby-gem, ruby-on-rails
Filestack Rails
Official Ruby on Rails plugin for Filestack File Picker that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
Stars: ✭ 220 (+714.81%)
Mutual labels:  ruby-gem, ruby-on-rails
Matestack Ui Core
Matestack enables you to create sophisticated, reactive UIs in pure Ruby, without touching JavaScript and HTML. You end up writing 50% less code while increasing productivity, maintainability and developer happiness.
Stars: ✭ 469 (+1637.04%)
Mutual labels:  ruby-gem, ruby-on-rails
Cloudinary gem
Cloudinary GEM for Ruby on Rails integration
Stars: ✭ 394 (+1359.26%)
Mutual labels:  ruby-gem, ruby-on-rails
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+2285.19%)
Mutual labels:  ruby-gem, activerecord
Postgresql cursor
ActiveRecord PostgreSQL Adapter extension for using a cursor to return a large result set
Stars: ✭ 384 (+1322.22%)
Mutual labels:  ruby-gem, activerecord
Mailjet Gem
[API v3] Mailjet official Ruby GEM
Stars: ✭ 119 (+340.74%)
Mutual labels:  ruby-gem, ruby-on-rails
glimmer-dsl-tk
Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library)
Stars: ✭ 26 (-3.7%)
Mutual labels:  ruby-library, ruby-gem
glimmer-dsl-swt
Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
Stars: ✭ 53 (+96.3%)
Mutual labels:  ruby-library, ruby-gem
Loaf
Manages and displays breadcrumb trails in Rails app - lean & mean.
Stars: ✭ 360 (+1233.33%)
Mutual labels:  ruby-gem, ruby-on-rails

Gem version Build status Code Climate

About

The Ruby on Rails ActiveRecord adapter for CrateDB, using the crate_ruby driver with HTTP connectivity.

Note: The activerecord-crate-adapter currently only works with Rails 4.1.x.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-crate-adapter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-crate-adapter

Usage

When using Rails update your database.yml

 development:
   adapter: crate
   host: 127.0.0.1
   port: 4200

CrateDB doesn't come with an autoincrement feature for your model ids. So you need to set it yourself. One way is to use SecureRandom.uuid, if you think there is a better one, please add an issue, so we can discuss.

class Post < ActiveRecord::Base

  before_validation :set_id, on: :create

  private

  def set_id
    self.id = SecureRandom.uuid
  end

end

Special data types

Array

You can simply create Array columns by specifying t.array and passing array_type when you create a migration.

t.array :tags, array_type: :string
t.array :votes, array_type: :integer
t.array :bool_arr, array_type: :boolean

When you create an object just pass your Array directly

Post.create!(title: 'Arrays are awesome', tags: %w(hot fresh), votes: [1,2])
post = Post.where("'fresh' = ANY (tags)")

Object

CrateDB allows you to define nested objects. I tried to make it as simply as possible to use and reuse existing AR functionality, I therefore ask you to reuse the existing serialize functionality. AR#serialize allows you to define your own serialization mechanism, and we simply reuse that for serializing an AR object. To get serialize working simply create #dump and #load methods on 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.

I tried to make your guys life easier and created a module that does this automatically for you. Simply make all attributes accessible and assign it in the initializer. So a serialized class should look like this:

require 'active_record/attribute_methods/crate_object'

class Address
  attr_accessor :street, :city, :phones, :zip

  include CrateObject

  def initialize(opts)
    @street = opts[:street]
    @city = opts[:city]
    @phones = opts[:phones]
    @zip = opts[:zip]
  end

end

Check out the CrateObject module if you need to write your own serializer.

Then in your model simply use #serialize to have objects working.

  class User < ActiveRecord::Base
    serialize :address, Address
  end

Note: I do not plan to support nested objects inside objects.

Object Migrations

In the migrations, you can create an object, specify the object behaviour (strict|dynamic|ignored), and its schema.

t.object :address, object_schema_behaviour: :strict,
                   object_schema: {street: :string, city: :string, phones: {array: :string}, zip: :integer}

Migrations

Currently, adding and dropping indices is not support by CrateDB, see issue #733.

# not supported by CrateDB yet
add_index :posts, :comment_count
remove_index :posts, :comment_count

Caveats

CrateDB is eventually consistent, that means if you create a record, and query for it right away, it won't work (except queries for the primary key).

In this context, read more about the REFRESH TABLE statement.

Tests

See DEVELOP.md.

Contributing

If you think something is missing, either create a pull request or log a new issue, so someone else can tackle it. Please refer to CONTRIBUTING.rst for further information.

Maintainers

License

This project is licensed under the Apache License 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].