Class: Sequel::Vertica::Database

Inherits:
Database
  • Object
show all
Defined in:
lib/sequel/adapters/vertica.rb

Constant Summary collapse

PK_NAME =
'C_PRIMARY'
AUTO_INCREMENT =
'AUTO_INCREMENT'
DatasetClass =
self

Instance Method Summary collapse

Instance Method Details

#auto_increment_sqlObject



83
84
85
# File 'lib/sequel/adapters/vertica.rb', line 83

def auto_increment_sql
  AUTO_INCREMENT
end

#connect(server) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sequel/adapters/vertica.rb', line 28

def connect(server)
  opts = server_opts(server)
  ::Vertica::Connection.new(
    :host => opts[:host],
    :user => opts[:user],
    :password => opts[:password],
    :port => opts[:port],
    :schema => opts[:schema],
    :database => opts[:database],
    :ssl => opts[:ssl] 
  )
end

#create_table_generator_classObject



87
88
89
# File 'lib/sequel/adapters/vertica.rb', line 87

def create_table_generator_class
  Vertica::CreateTableGenerator
end

#execute(sql, opts = {}, &block) ⇒ Object Also known as: execute_dui



41
42
43
44
45
46
47
48
49
50
# File 'lib/sequel/adapters/vertica.rb', line 41

def execute(sql, opts = {}, &block)
  res = nil
  synchronize(opts[:server]) do |conn|
    res = log_yield(sql) { conn.query(sql) }
    res.each(&block)
  end
  res
rescue ::Vertica::Error => e
  raise_error(e)
end

#execute_insert(sql, opts = {}, &block) ⇒ Object



52
53
54
55
# File 'lib/sequel/adapters/vertica.rb', line 52

def execute_insert(sql, opts = {}, &block)
  result = execute(sql, opts, &block)
  result.first[:OUTPUT]
end

#identifier_input_method_defaultObject



71
72
73
# File 'lib/sequel/adapters/vertica.rb', line 71

def identifier_input_method_default
  nil
end

#identifier_output_method_defaultObject



75
76
77
# File 'lib/sequel/adapters/vertica.rb', line 75

def identifier_output_method_default
  nil
end

#locksObject



79
80
81
# File 'lib/sequel/adapters/vertica.rb', line 79

def locks
  dataset.from(:v_monitor__locks)
end

#schema_parse_table(table_name, options = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/sequel/adapters/vertica.rb', line 103

def schema_parse_table(table_name, options = {})
  schema = options[:schema]

  selector = [:column_name, :constraint_name, :is_nullable.as(:allow_null),
              (:column_default).as(:default), (:data_type).as(:db_type)]
  filter = { :columns__table_name => table_name }
  filter[:columns__table_schema] = schema.to_s if schema

  dataset = .
    select(*selector).
    filter(filter).
    from(:v_catalog__columns).
    left_outer_join(:v_catalog__table_constraints, :table_id => :table_id)

  dataset.map do |row|
    row[:default] = nil if blank_object?(row[:default])
    row[:type] = schema_column_type(row[:db_type])
    row[:primary_key] = row.delete(:constraint_name) == PK_NAME
    [row.delete(:column_name).to_sym, row]
  end
end

#supports_create_table_if_not_exists?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sequel/adapters/vertica.rb', line 59

def supports_create_table_if_not_exists?
  true
end

#supports_drop_table_if_exists?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/sequel/adapters/vertica.rb', line 63

def supports_drop_table_if_exists?
  true
end

#supports_transaction_isolation_levels?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/sequel/adapters/vertica.rb', line 67

def supports_transaction_isolation_levels?
  true
end

#tables(options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/sequel/adapters/vertica.rb', line 91

def tables(options = {})
  schema = options[:schema]
  filter = {}
  filter[:table_schema] = schema.to_s if schema

  dataset.select(:table_name).
    from(:v_catalog__tables).
    filter(filter).
    to_a.
    map { |h| h[:table_name].to_sym }
end