Class: Sequel::Cockroach::Database
- Inherits:
-
Postgres::Database
- Object
- Postgres::Database
- Sequel::Cockroach::Database
- Defined in:
- lib/mimi/db/extensions/sequel-cockroachdb.rb
Instance Method Summary collapse
-
#indexes(table_name) ⇒ Hash
Retrieves indexes for the given table.
- #server_version ⇒ Object
-
#supports_savepoints? ⇒ Boolean
Cockroach DB only supports one savepoint.
Instance Method Details
#indexes(table_name) ⇒ Hash
Retrieves indexes for the given table
NOTE: Apparently CockroachDB is not fully compatible with Postgres or Sequel’s Postgres adapter, and it can’t correctly figure out indexes and their properties. As a workaround, a specific #indexes() method is implemented here, which executes ‘SHOW INDEXES FROM …` and parses the results.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mimi/db/extensions/sequel-cockroachdb.rb', line 36 def indexes(table_name) idxs = {} results = fetch('show indexes from ' + table_name.to_s).all results.each do |idx_entry| idx_name = idx_entry[:Name].to_sym next if idx_name == :primary # ignore primary index idxs[idx_name] ||= { name: idx_name.to_s } idx = idxs[idx_name] idx[:unique] = idx_entry[:Unique] idx[:deferrable] = false idx[:columns] ||= [] idx[:columns] << idx_entry[:Column].to_sym unless idx_entry[:Implicit] end idxs end |
#server_version ⇒ Object
21 22 23 24 |
# File 'lib/mimi/db/extensions/sequel-cockroachdb.rb', line 21 def server_version(*) 80000 # mimics Postgres v8 # 100000 # mimics Postgres v10 end |
#supports_savepoints? ⇒ Boolean
Cockroach DB only supports one savepoint
17 18 19 |
# File 'lib/mimi/db/extensions/sequel-cockroachdb.rb', line 17 def supports_savepoints? false end |