vertica_rails_adapter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vertica_rails_adapter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sasan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # VerticaRailsAdapter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vertica_rails_adapter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vertica_rails_adapter
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,174 @@
1
+ require 'active_record/connection_adapters/abstract_adapter'
2
+ require 'active_support/core_ext/kernel/requires'
3
+
4
+ module ActiveRecord
5
+ class Base
6
+
7
+ ##
8
+ # Establishes a connection to the database that's used by all Active Record objects
9
+ ##
10
+ def self.vertica_connection(config)
11
+ unless defined? Vertica
12
+ begin
13
+ require 'vertica'
14
+ rescue LoadError
15
+ raise "Vertica Gem not installed"
16
+ end
17
+ end
18
+
19
+ config = config.symbolize_keys
20
+ host = config[:host]
21
+ port = config[:port] || 5433
22
+ username = config[:username].to_s if config[:username]
23
+ password = config[:password].to_s if config[:password]
24
+ schema = config[:schema].to_s if config[:schema]
25
+
26
+ if config.has_key?(:database)
27
+ database = config[:database]
28
+ else
29
+ raise ArgumentError, "No database specified. Missing argument: database."
30
+ end
31
+
32
+ # if config.has_key?(:schema)
33
+ # schema = config[:schema]
34
+ # else
35
+ # raise ArgumentError, "Vertica Schema must be specified."
36
+ # end
37
+
38
+ conn = Vertica.connect({ :user => username,
39
+ :password => password,
40
+ :host => host,
41
+ :port => port,
42
+ :database => database,
43
+ :schema => schema })
44
+
45
+ options = [host, username, password, database, port,schema]
46
+
47
+ ConnectionAdapters::VerticaAdapter.new(conn, options, config)
48
+ end
49
+
50
+
51
+ def self.instantiate(record)
52
+ record.stringify_keys!
53
+
54
+ sti_class = find_sti_class(record[inheritance_column])
55
+ record_id = sti_class.primary_key && record[sti_class.primary_key]
56
+ if ActiveRecord::IdentityMap.enabled? && record_id
57
+ if (column = sti_class.columns_hash[sti_class.primary_key]) && column.number?
58
+ record_id = record_id.to_i
59
+ end
60
+ if instance = IdentityMap.get(sti_class, record_id)
61
+ instance.reinit_with('attributes' => record)
62
+ else
63
+ instance = sti_class.allocate.init_with('attributes' => record)
64
+ IdentityMap.add(instance)
65
+ end
66
+ else
67
+ instance = sti_class.allocate.init_with('attributes' => record)
68
+ end
69
+
70
+ instance
71
+ end
72
+ end
73
+
74
+ module ConnectionAdapters
75
+ class VerticaColumn < Column
76
+
77
+ end
78
+
79
+ class VerticaAdapter < AbstractAdapter
80
+ ADAPTER_NAME = 'Vertica'.freeze
81
+
82
+ def adapter_name #:nodoc:
83
+ ADAPTER_NAME
84
+ end
85
+
86
+ def initialize(connection, connection_options, config)
87
+ super(connection)
88
+ @connection_options, @config = connection_options, config
89
+ @quoted_column_names, @quoted_table_names = {}, {}
90
+ # connect
91
+ end
92
+
93
+ def active?
94
+ @connection.opened?
95
+ end
96
+
97
+ # Disconnects from the database if already connected, and establishes a
98
+ # new connection with the database.
99
+ def reconnect!
100
+ @connection.reset_connection
101
+ end
102
+ def reset
103
+ reconnect!
104
+ end
105
+
106
+ # Close the connection.
107
+ def disconnect!
108
+ @connection.close rescue nil
109
+ end
110
+
111
+ # return raw object
112
+ def execute(sql, name=nil)
113
+ log(sql,name) do
114
+ if block_given?
115
+ @connection = ::Vertica.connect(@connection.options)
116
+ @connection.query(sql) {|row| yield row }
117
+ @connection.close
118
+ else
119
+ @connection = ::Vertica.connect(@connection.options)
120
+ results = @connection.query(sql)
121
+ @connection.close
122
+ results
123
+ end
124
+ end
125
+ end
126
+
127
+ def schema_name
128
+ @schema ||= @connection.options[:schema]
129
+ end
130
+
131
+ def tables(name = nil) #:nodoc:
132
+ sql = "SELECT * FROM tables WHERE table_schema = #{quote_column_name(schema_name)}"
133
+
134
+ tables = []
135
+ execute(sql, name) { |field| tables << field[:table_name] }
136
+ tables
137
+ end
138
+
139
+ def columns(table_name, name = nil)#:nodoc:
140
+ sql = "SELECT * FROM columns WHERE table_name = #{quote_column_name(table_name)}"
141
+
142
+ columns = []
143
+ execute(sql, name){ |field| columns << VerticaColumn.new(field[:column_name],field[:column_default],field[:data_type],field[:is_nullable])}
144
+ columns
145
+ end
146
+
147
+ def select(sql, name = nil, binds = [])
148
+ rows = []
149
+ @connection = ::Vertica.connect(@connection.options)
150
+ @connection.query(sql) {|row| rows << row }
151
+ @connection.close
152
+ rows
153
+ end
154
+
155
+ def primary_key(table)
156
+ ''
157
+ end
158
+
159
+ ## QUOTING
160
+ def quote_column_name(name) #:nodoc:
161
+ "'#{name}'"
162
+ end
163
+
164
+ def quote_table_name(name) #:nodoc:
165
+ if schema_name.blank?
166
+ name
167
+ else
168
+ "#{schema_name}.#{name}"
169
+ end
170
+ end
171
+
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,6 @@
1
+ require "active_record/connection_adapters/vertica_adapter"
2
+ require "activerecord-import/adapters/vertica_adapter"
3
+
4
+ class ActiveRecord::ConnectionAdapters::VerticaAdapter
5
+ include ActiveRecord::Import::VerticaAdapter::InstanceMethods
6
+ end
@@ -0,0 +1,6 @@
1
+ require "activerecord/active_record/connection_adapters/vertica_adapter"
2
+ require "activerecord-import/adapters/vertica_adapter"
3
+
4
+ class ActiveRecord::ConnectionAdapters::VerticaAdapter
5
+ include ActiveRecord::Import::VerticaAdapter::InstanceMethods
6
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveRecord::Import::VerticaAdapter
2
+ module InstanceMethods
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ require 'active_record/connection_adapters/vertica_adapter'
2
+ require 'activerecord-import/active_record/adapters/vertica_adapter'
3
+ require 'activerecord-import/adapters/vertica_adapter'
@@ -0,0 +1,8 @@
1
+ require "vertica_rails_adapter/version"
2
+
3
+ require 'active_record/connection_adapters/vertica_adapter'
4
+ require "activerecord-vertica-adapter"
5
+
6
+ module VerticaRailsAdapter
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,3 @@
1
+ module VerticaRailsAdapter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vertica_rails_adapter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "vertica_rails_adapter"
8
+ gem.version = VerticaRailsAdapter::VERSION
9
+ gem.authors = ["Sasan Padidar"]
10
+ gem.email = ["sasan@raybeam.com"]
11
+ gem.description = %q{Vertica Adapter for ActiveRecord.}
12
+ gem.summary = %q{Adds activerecord functionalites to your Vertica connection. The credit goes to https://github.com/zemis for starting up the project.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rails", ">= 3.0.0"
21
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vertica_rails_adapter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sasan Padidar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ name: rails
23
+ prerelease: false
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ requirement: *id001
36
+ description: Vertica Adapter for ActiveRecord.
37
+ email:
38
+ - sasan@raybeam.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - LICENSE.txt
49
+ - README.md
50
+ - Rakefile
51
+ - lib/active_record/connection_adapters/vertica_adapter.rb
52
+ - lib/activerecord-import/active_record/adapters/vertica_adapter.rb
53
+ - lib/activerecord-import/active_record/adapters/vertica_adapter.rb~
54
+ - lib/activerecord-import/adapters/vertica_adapter.rb
55
+ - lib/activerecord-vertica-adapter.rb
56
+ - lib/vertica_rails_adapter.rb
57
+ - lib/vertica_rails_adapter/version.rb
58
+ - vertica_rails_adapter.gemspec
59
+ homepage: ""
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.22
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Adds activerecord functionalites to your Vertica connection. The credit goes to https://github.com/zemis for starting up the project.
92
+ test_files: []
93
+