Module: ArJdbc::Cassandra

Included in:
ActiveRecord::ConnectionAdapters::CassandraAdapter
Defined in:
lib/arjdbc/cassandra.rb,
lib/arjdbc/cassandra/version.rb

Constant Summary collapse

NATIVE_DATABASE_TYPES =
{
    :primary_key  => 'uuid PRIMARY KEY',
    :string       => { :name => 'varchar' },
    :text         => { :name => 'text' },
    :integer      => { :name => 'int' },
    :float        => { :name => 'float' },
    :decimal      => { :name => 'decimal' },
    :datetime     => { :name => 'timestamp' },
    :timestamp    => { :name => 'timestamp' },
    :time         => { :name => 'timestamp' },
    :date         => { :name => 'timestamp' },
    :binary       => { :name => 'blob' },
    :boolean      => { :name => 'boolean' },
    # Extended support for Cassandra types
    :ascii        => { :name => 'ascii' },
    :bigint       => { :name => 'bigint' },
    :blob         => { :name => 'blob' },
    :counter      => { :name => 'counter' },
    :double       => { :name => 'double' },
    :inet         => { :name => 'inet' },
    :timeuuid     => { :name => 'timeuuid' },
    :uuid         => { :name => 'uuid' },
    :varchar      => { :name => 'varchar' },
    :varint       => { :name => 'varint' }
}
ADAPTER_NAME =
'Cassandra'.freeze
VERSION =
'0.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arel2_visitors(config) ⇒ Object



59
60
61
62
63
64
# File 'lib/arjdbc/cassandra.rb', line 59

def self.arel2_visitors(config)
  {
      'cassandra' => ::Arel::Visitors::ToSql,
      'jdbccassandra' => ::Arel::Visitors::ToSql
  }
end

.column_selectorObject



15
16
17
# File 'lib/arjdbc/cassandra.rb', line 15

def self.column_selector
  [ /cassandra/i, lambda { |_,column| column.extend(::ArJdbc::Cassandra::Column) } ]
end

.extended(adapter) ⇒ Object



11
12
13
# File 'lib/arjdbc/cassandra.rb', line 11

def self.extended(adapter)
  adapter.configure_connection
end

.jdbc_connection_classObject



19
20
21
# File 'lib/arjdbc/cassandra.rb', line 19

def self.jdbc_connection_class
  ::ActiveRecord::ConnectionAdapters::CassandraJdbcConnection
end

Instance Method Details

#adapter_nameObject

:nodoc:



55
56
57
# File 'lib/arjdbc/cassandra.rb', line 55

def adapter_name #:nodoc:
  ADAPTER_NAME
end

#case_sensitive_modifier(node) ⇒ Object



66
67
68
# File 'lib/arjdbc/cassandra.rb', line 66

def case_sensitive_modifier(node)
  Arel::Nodes::Bin.new(node)
end

#create_database(name, options = {}) ⇒ Object

:nodoc:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/arjdbc/cassandra.rb', line 126

def create_database(name, options = {}) #:nodoc:
  query = "CREATE KEYSPACE #{name} WITH strategy_class = #{options[:strategy_class] || 'SimpleStrategy'}"

  if options[:strategy_options]
    if options[:strategy_options].is_a?(Array)
      options[:strategy_options].each do |strategy_option|
        query += " AND strategy_options:#{strategy_option}"
      end
    else
      query += " AND strategy_options:#{options[:strategy_options]}"
    end
  end

  execute query
end

#create_table(name, options = {}) {|td| ... } ⇒ Object

:nodoc:

Yields:

  • (td)


146
147
148
149
150
151
152
153
154
155
156
# File 'lib/arjdbc/cassandra.rb', line 146

def create_table(name, options = {}) #:nodoc:
  td = table_definition
  td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false

  yield td if block_given?

  create_sql = "CREATE TABLE #{name} ("
  create_sql << td.to_sql
  create_sql << ") #{options[:options]}"
  execute create_sql
end

#drop_database(name) ⇒ Object

:nodoc:



142
143
144
# File 'lib/arjdbc/cassandra.rb', line 142

def drop_database(name) #:nodoc:
  execute "DROP KEYSPACE #{name}"
end

#drop_table(name) ⇒ Object

:nodoc:



158
159
160
# File 'lib/arjdbc/cassandra.rb', line 158

def drop_table(name) #:nodoc:
  execute "DROP TABLE #{name}"
end

#exec_insert(sql, name, binds) ⇒ Object Also known as: exec_update, exec_delete

DATABASE STATEMENTS ======================================



104
105
106
# File 'lib/arjdbc/cassandra.rb', line 104

def exec_insert(sql, name, binds)
  execute sql, name, binds
end

#limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key) ⇒ Object



70
71
72
# File 'lib/arjdbc/cassandra.rb', line 70

def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
  where_sql
end

#native_database_typesObject



49
50
51
# File 'lib/arjdbc/cassandra.rb', line 49

def native_database_types
  NATIVE_DATABASE_TYPES
end

#recreate_database(name, options = {}) ⇒ Object

:nodoc:



121
122
123
124
# File 'lib/arjdbc/cassandra.rb', line 121

def recreate_database(name, options = {}) #:nodoc:
  drop_database(name)
  create_database(name, options)
end

#select(sql, name = nil, binds = []) ⇒ Object



110
111
112
113
# File 'lib/arjdbc/cassandra.rb', line 110

def select(sql, name = nil, binds = [])
  query = sql.gsub(/[0-9a-z_-]+\.\*/i, '*')
  execute query
end

#structure_dumpObject

SCHEMA STATEMENTS ========================================



117
118
119
# File 'lib/arjdbc/cassandra.rb', line 117

def structure_dump #:nodoc:
  execute('DESCRIBE SCHEMA')
end

#supports_bulk_alter?Boolean

:nodoc:

Returns:

  • (Boolean)


82
83
84
# File 'lib/arjdbc/cassandra.rb', line 82

def supports_bulk_alter? # :nodoc:
  false
end

#supports_index_sort_order?Boolean

:nodoc:

Returns:

  • (Boolean)


86
87
88
# File 'lib/arjdbc/cassandra.rb', line 86

def supports_index_sort_order? # :nodoc:
  false
end

#supports_migrations?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/arjdbc/cassandra.rb', line 74

def supports_migrations?
  false
end

#supports_primary_key?Boolean

:nodoc:

Returns:

  • (Boolean)


78
79
80
# File 'lib/arjdbc/cassandra.rb', line 78

def supports_primary_key? # :nodoc:
  true
end

#supports_savepoints?Boolean

:nodoc:

Returns:

  • (Boolean)


98
99
100
# File 'lib/arjdbc/cassandra.rb', line 98

def supports_savepoints? # :nodoc:
  false
end

#supports_transaction_isolation?Boolean

:nodoc:

Returns:

  • (Boolean)


90
91
92
# File 'lib/arjdbc/cassandra.rb', line 90

def supports_transaction_isolation? # :nodoc:
  false
end

#supports_views?Boolean

:nodoc:

Returns:

  • (Boolean)


94
95
96
# File 'lib/arjdbc/cassandra.rb', line 94

def supports_views? # :nodoc:
  false
end