purview 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30aabf4950bc6dc20daf5b89eec19e9afe148765
4
- data.tar.gz: 544c19c81308f7276a02a8b6149dd97bcd7f3312
3
+ metadata.gz: 1e7d924c2525271d6ebf479f498241505bbac3e8
4
+ data.tar.gz: 34f49f218bf0268b3801d715a73aa34a5c6847b0
5
5
  SHA512:
6
- metadata.gz: 80b799628ae3f89c0eacab1cf449d1fadaf318d9f590c7408624e66849a9c527a9d7f1f280b9df03bbe54e62b496cf99d379091c0ae78aa571fdb9e6fbfe329e
7
- data.tar.gz: 21600dcd05785d91a627338b14396290fed0dd3c4e18f9a116b9c9b23f25f3fd3715a48e749db0205d283ffd1a26b2764f7bf2339fb9ec90e2c0ea61d43a7708
6
+ metadata.gz: d4f941aeccb17386c82742f3ab4259321ca6d9da026a7a6da3ae1b202125f638153b33c19b5fcededd713287073f913f221b15560a7384403241c0f740721928
7
+ data.tar.gz: 8761615f2d7bfa444bf9b0f6249801a68edd96f3ed65a286c5abe9f9a6b3143004b2672fd33ab53dfeee652d565152f533c93125272779434e8f7d58f4dd0104
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
 
3
+ before_install:
4
+ - sudo apt-get update -q
5
+ - sudo apt-get install -q freetds-dev
6
+
3
7
  rvm:
4
8
  - 1.9.3
5
9
  - 2.0.0
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ Release 1.5.0 (2015-06-12)
2
+ --------------------------
3
+
4
+ * MSSQL support (includes JRuby support)
5
+ * Update README with new examples
6
+ * Remove deprecated documentation
7
+
1
8
  Release 1.4.0 (2015-06-10)
2
9
  --------------------------
3
10
 
data/Gemfile CHANGED
@@ -2,11 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
4
  if defined?(JRUBY_VERSION)
5
+ gem 'jdbc-jtds', '~> 1.3'
5
6
  gem 'jdbc-mysql', '~> 5.1'
6
7
  gem 'jdbc-postgres', '~> 9.4'
7
8
  else
8
9
  gem 'mysql2', '~> 0.3'
9
10
  gem 'pg', '~> 0.18'
11
+ gem 'tiny_tds', '~> 0.6'
10
12
  end
11
13
  end
12
14
 
data/README.md CHANGED
@@ -21,9 +21,10 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Load the `MySQL` client (for `PostgreSQL` simply change 'mysql2' to 'pg' -- when
25
- using this gem in a JRuby environment the 'jdbc/mysql' and/or 'jdbc/postgres'
26
- library must be installed/available)
24
+ Load the `MySQL` client (for `MSSQL` simple change 'mysql2' to 'tiny_tds'; for
25
+ `PostgreSQL` simply change 'mysql2' to 'pg' -- when using this gem in a JRuby
26
+ environment the 'jdbc/jtds', 'jdbc/mysql' and/or 'jdbc/postgres'library must be
27
+ installed/available)
27
28
  ```ruby
28
29
  require 'mysql2'
29
30
  ```
@@ -36,7 +37,7 @@ table_name = :users
36
37
  Define the `Column(s)` (available column-types: `Boolean`, `CreatedTimestamp`,
37
38
  `Date`, `Float`, `Id`, `Integer`, `Money`, `String`, `Text`, `Time`, `Timestamp`,
38
39
  `UpdatedTimestamp` & `UUID` -- the `Id`, `CreatedTimestamp` & `UpdatedTimestamp`
39
- columns are required for all tables)
40
+ columns are required for all `BaseSyncable` tables)
40
41
  ```ruby
41
42
  id_column = Purview::Columns::Id.new(:id),
42
43
  name_column = Purview::Columns::String.new(:name, :nullable => false),
@@ -58,11 +59,12 @@ Define the `Indices` (availble index-types: `Composite` & `Simple`). By default
58
59
  `UpdatedTimestamp`)
59
60
  ```ruby
60
61
  indices = [
61
- Purview::Indices::Simple.new(email_column),
62
+ Purview::Indices::Simple.new(email_column, :unique => true),
62
63
  ]
63
64
  ```
64
65
 
65
- Configure the `Puller` (available puller-types: `MySQL`, `PostgreSQL` & `URI`)
66
+ Configure the `Puller` (available puller-types: `MSSQL`, `MySQL`, `PostgreSQL` &
67
+ `URI`)
66
68
  ```ruby
67
69
  puller_opts = {
68
70
  :type => Purview::Pullers::URI,
@@ -102,7 +104,7 @@ table = Purview::Tables::Raw.new(
102
104
 
103
105
  Set the database-name (this can be anything, but it must exist)
104
106
  ```ruby
105
- database_name = :data_warehouse
107
+ database_name = :data_warehouse_raw
106
108
  ```
107
109
 
108
110
  Combine all the configuration options and instantiate the `Database` (for
@@ -118,12 +120,6 @@ database = Purview::Databases::MySQL.new(
118
120
  )
119
121
  ```
120
122
 
121
- Add the `Table` to the `Database` (schema). In order for [the] `Table` to be
122
- `sync[ed]` it *must* be added to [the] `Database`
123
- ```ruby
124
- database.add_table(table)
125
- ```
126
-
127
123
  Create the `Table` (in the DB). Recommended for testing purposes *only*. For
128
124
  production environments you will likely want an external process to manage the
129
125
  schema (for `PostgreSQL` simply change `Mysql2::Error` to `PG::DuplicateTable`)
@@ -160,16 +156,27 @@ to determine the pool of `Table(s)` available for synchronization (to remove a
160
156
  database.enable_table(table)
161
157
  ```
162
158
 
163
- Sync the `Database`. This process will select a [candidate] `Table`, pull data
164
- from its [remote-]source and reconcile the new data against the main-table (e.g.
165
- perform `INSERTs`, `UPDATEs` and `DELETEs`). When multiple `Table(s)` are
166
- configured the least recently pulled and available (`enabled` and not `locked`)
167
- `Table` will be selected (you will likely want to configure some process to load
168
- the schema run the `sync` at regularly scheduled intervals)
159
+ Sync the `Table`. This process will pull data from its [remote-]source and
160
+ reconcile the new data against the main-table (e.g. perform 'INSERT', 'UPDATE'
161
+ and 'DELETE' operations).
162
+ ```ruby
163
+ database.sync_table(table)
164
+ ```
165
+
166
+ Sync the `Database`. The result of this process is the same as `sync_table`
167
+ except that the process itself will select a candidate table. When multiple
168
+ `Table(s)` are configured the least recently pulled and available (`enabled`,
169
+ `initialized` and `unlocked`) `Table` will be selected.
169
170
  ```ruby
170
171
  database.sync
171
172
  ```
172
173
 
174
+ Fetch the metadata for a `Table`. This process will return a `Struct`
175
+ representation of the current state for the given `Table`
176
+ ```ruby
177
+ database.table_metadata(table)
178
+ ```
179
+
173
180
  ## Contributing
174
181
 
175
182
  1. Fork it ( http://github.com/jzaleski/purview/fork )
@@ -0,0 +1,11 @@
1
+ module Purview
2
+ module Connections
3
+ class MSSQL < Base
4
+ private
5
+
6
+ def raw_connection_type
7
+ Purview::RawConnections::MSSQL
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,4 @@
1
1
  require 'purview/connections/base'
2
+ require 'purview/connections/mssql'
2
3
  require 'purview/connections/mysql'
3
4
  require 'purview/connections/postgresql'
@@ -0,0 +1,25 @@
1
+ module Purview
2
+ module Dialects
3
+ class MSSQL < Base
4
+ def false_value
5
+ '0'
6
+ end
7
+
8
+ def null_value
9
+ 'NULL'
10
+ end
11
+
12
+ def quoted(value)
13
+ value.nil? ? null_value : value.quoted
14
+ end
15
+
16
+ def sanitized(value)
17
+ value.nil? ? null_value : value.sanitized
18
+ end
19
+
20
+ def true_value
21
+ '1'
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,4 +1,5 @@
1
1
  require 'purview/dialects/base'
2
2
 
3
+ require 'purview/dialects/mssql'
3
4
  require 'purview/dialects/mysql'
4
5
  require 'purview/dialects/postgresql'
@@ -3,7 +3,7 @@ module Purview
3
3
  class BaseSQL < Base
4
4
  def pull(window)
5
5
  with_new_connection do |connection|
6
- connection.execute(pull_sql(window))
6
+ connection.execute(pull_sql(window) + additional_sql)
7
7
  end
8
8
  end
9
9
 
@@ -14,6 +14,10 @@ module Purview
14
14
  include Purview::Mixins::Helpers
15
15
  include Purview::Mixins::Logger
16
16
 
17
+ def additional_sql
18
+ " #{opts[:additional_sql]}".rstrip
19
+ end
20
+
17
21
  def column_names
18
22
  table.columns.map do |column|
19
23
  name = column.name
@@ -0,0 +1,15 @@
1
+ module Purview
2
+ module Pullers
3
+ class MSSQL < BaseSQL
4
+ private
5
+
6
+ def connection_type
7
+ Purview::Connections::MSSQL
8
+ end
9
+
10
+ def dialect_type
11
+ Purview::Dialects::MSSQL
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,7 @@
1
1
  require 'purview/pullers/base'
2
2
  require 'purview/pullers/base_sql'
3
3
 
4
+ require 'purview/pullers/mssql'
4
5
  require 'purview/pullers/mysql'
5
6
  require 'purview/pullers/postgresql'
6
7
  require 'purview/pullers/uri'
@@ -10,10 +10,6 @@ module Purview
10
10
  delete?(sql) || insert?(sql) || update?(sql)
11
11
  end
12
12
 
13
- def engine
14
- raise %{All "#{Base}(s)" must override the "engine" method}
15
- end
16
-
17
13
  def execute_sql(sql, opts={})
18
14
  @last_sql = sql
19
15
  @last_statement = statement = raw_connection.createStatement
@@ -58,7 +54,7 @@ module Purview
58
54
  end
59
55
 
60
56
  def url
61
- "jdbc:#{engine}://#{host}#{port && ":#{port}"}/#{database}"
57
+ raise %{All "#{Base}(s)" must override the "url" method}
62
58
  end
63
59
  end
64
60
  end
@@ -0,0 +1,25 @@
1
+ safe_require('jdbc/jtds')
2
+
3
+ if defined?(Jdbc::JTDS)
4
+ Jdbc::JTDS.load_driver
5
+
6
+ module Purview
7
+ module RawConnections
8
+ module JDBC
9
+ class JTDS < Base
10
+ private
11
+
12
+ def url
13
+ "jdbc:jtds:sqlserver://#{host}#{port && ":#{port}"};databaseName=#{database}"
14
+ end
15
+
16
+ def username
17
+ super || ENV['SQLCMDUSER'] || Etc.getlogin
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Purview::RawConnections::MSSQL = Purview::RawConnections::JDBC::JTDS
25
+ end
@@ -9,8 +9,8 @@ if defined?(Jdbc::MySQL)
9
9
  class MySQL < Base
10
10
  private
11
11
 
12
- def engine
13
- 'mysql'
12
+ def url
13
+ "jdbc:mysql://#{host}#{port && ":#{port}"}/#{database}"
14
14
  end
15
15
 
16
16
  def username
@@ -9,8 +9,8 @@ if defined?(Jdbc::Postgres)
9
9
  class Postgres < Base
10
10
  private
11
11
 
12
- def engine
13
- 'postgresql'
12
+ def url
13
+ "jdbc:postgresql://#{host}#{port && ":#{port}"}/#{database}"
14
14
  end
15
15
 
16
16
  def username
@@ -0,0 +1,41 @@
1
+ safe_require('tiny_tds')
2
+
3
+ if defined?(TinyTds)
4
+ module Purview
5
+ module RawConnections
6
+ class TinyTds < Base
7
+ private
8
+
9
+ def execute_sql(sql, opts={})
10
+ raw_connection.execute(sql)
11
+ end
12
+
13
+ def extract_rows(result)
14
+ result && result.to_a
15
+ end
16
+
17
+ def extract_rows_affected(result)
18
+ result.affected_rows
19
+ end
20
+
21
+ def new_connection
22
+ ::TinyTds::Client.new(
23
+ filter_blank_values(
24
+ :database => database.to_s,
25
+ :host => host.to_s,
26
+ :password => password.to_s,
27
+ :port => port,
28
+ :username => username.to_s
29
+ )
30
+ )
31
+ end
32
+
33
+ def username
34
+ super || ENV['SQLCMDUSER'] || Etc.getlogin
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ Purview::RawConnections::MSSQL = Purview::RawConnections::TinyTds
41
+ end
@@ -1,12 +1,17 @@
1
1
  require 'purview/raw_connections/base'
2
2
  require 'purview/raw_connections/jdbc/base'
3
3
 
4
+ require 'purview/raw_connections/jdbc/jtds'
4
5
  require 'purview/raw_connections/jdbc/mysql'
5
6
  require 'purview/raw_connections/jdbc/postgres'
6
7
 
7
8
  require 'purview/raw_connections/mysql2'
8
9
  require 'purview/raw_connections/pg'
10
+ require 'purview/raw_connections/tiny_tds'
9
11
 
10
- if !defined?(Purview::RawConnections::MySQL) && !defined?(Purview::RawConnections::PostgreSQL)
11
- raise 'Could not initialize raw-connections; please install and require one or more of the following gems: `jdbc-mysql`, `jdbc-postgres`, `mysql2` and/or `pg`'
12
+ if \
13
+ !defined?(Purview::RawConnections::MSSQL) &&
14
+ !defined?(Purview::RawConnections::MySQL) &&
15
+ !defined?(Purview::RawConnections::PostgreSQL)
16
+ raise 'Could not initialize raw-connections; please install and require one or more of the following gems: `jdbc-jtds`, `jdbc-mysql`, `jdbc-postgres`, `mysql2`, `pg` and/or `tiny_tds`'
12
17
  end
@@ -1,3 +1,3 @@
1
1
  module Purview
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
data/purview.gemspec CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |gem|
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
20
  gem.require_paths = ['lib']
21
21
 
22
- gem.requirements << '`jdbc-mysql` or `mysql2` gem'
23
- gem.requirements << '`jdbc-postgres` or `pg` gem'
22
+ gem.requirements << '`mysql2` or `jdbc-mysql` gem'
23
+ gem.requirements << '`pg` or `jdbc-postgres` gem'
24
+ gem.requirements << '`tiny_tds` or `jdbc-jtds` gem'
24
25
 
25
26
  gem.add_development_dependency 'bundler', '~> 1.0'
26
27
  gem.add_development_dependency 'pry', '~> 0.10'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purview
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan W. Zaleski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,6 +99,7 @@ files:
99
99
  - lib/purview/columns/uuid.rb
100
100
  - lib/purview/connections.rb
101
101
  - lib/purview/connections/base.rb
102
+ - lib/purview/connections/mssql.rb
102
103
  - lib/purview/connections/mysql.rb
103
104
  - lib/purview/connections/postgresql.rb
104
105
  - lib/purview/databases.rb
@@ -107,6 +108,7 @@ files:
107
108
  - lib/purview/databases/postgresql.rb
108
109
  - lib/purview/dialects.rb
109
110
  - lib/purview/dialects/base.rb
111
+ - lib/purview/dialects/mssql.rb
110
112
  - lib/purview/dialects/mysql.rb
111
113
  - lib/purview/dialects/postgresql.rb
112
114
  - lib/purview/exceptions.rb
@@ -152,6 +154,7 @@ files:
152
154
  - lib/purview/pullers.rb
153
155
  - lib/purview/pullers/base.rb
154
156
  - lib/purview/pullers/base_sql.rb
157
+ - lib/purview/pullers/mssql.rb
155
158
  - lib/purview/pullers/mysql.rb
156
159
  - lib/purview/pullers/postgresql.rb
157
160
  - lib/purview/pullers/uri.rb
@@ -159,10 +162,12 @@ files:
159
162
  - lib/purview/raw_connections/base.rb
160
163
  - lib/purview/raw_connections/jdbc.rb
161
164
  - lib/purview/raw_connections/jdbc/base.rb
165
+ - lib/purview/raw_connections/jdbc/jtds.rb
162
166
  - lib/purview/raw_connections/jdbc/mysql.rb
163
167
  - lib/purview/raw_connections/jdbc/postgres.rb
164
168
  - lib/purview/raw_connections/mysql2.rb
165
169
  - lib/purview/raw_connections/pg.rb
170
+ - lib/purview/raw_connections/tiny_tds.rb
166
171
  - lib/purview/refinements.rb
167
172
  - lib/purview/refinements/object.rb
168
173
  - lib/purview/refinements/string.rb
@@ -212,8 +217,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
217
  - !ruby/object:Gem::Version
213
218
  version: '0'
214
219
  requirements:
215
- - "`jdbc-mysql` or `mysql2` gem"
216
- - "`jdbc-postgres` or `pg` gem"
220
+ - "`mysql2` or `jdbc-mysql` gem"
221
+ - "`pg` or `jdbc-postgres` gem"
222
+ - "`tiny_tds` or `jdbc-jtds` gem"
217
223
  rubyforge_project:
218
224
  rubygems_version: 2.4.6
219
225
  signing_key: