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 +4 -4
- data/.travis.yml +4 -0
- data/CHANGELOG +7 -0
- data/Gemfile +2 -0
- data/README.md +26 -19
- data/lib/purview/connections/mssql.rb +11 -0
- data/lib/purview/connections.rb +1 -0
- data/lib/purview/dialects/mssql.rb +25 -0
- data/lib/purview/dialects.rb +1 -0
- data/lib/purview/pullers/base_sql.rb +5 -1
- data/lib/purview/pullers/mssql.rb +15 -0
- data/lib/purview/pullers.rb +1 -0
- data/lib/purview/raw_connections/jdbc/base.rb +1 -5
- data/lib/purview/raw_connections/jdbc/jtds.rb +25 -0
- data/lib/purview/raw_connections/jdbc/mysql.rb +2 -2
- data/lib/purview/raw_connections/jdbc/postgres.rb +2 -2
- data/lib/purview/raw_connections/tiny_tds.rb +41 -0
- data/lib/purview/raw_connections.rb +7 -2
- data/lib/purview/version.rb +1 -1
- data/purview.gemspec +3 -2
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7d924c2525271d6ebf479f498241505bbac3e8
|
4
|
+
data.tar.gz: 34f49f218bf0268b3801d715a73aa34a5c6847b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4f941aeccb17386c82742f3ab4259321ca6d9da026a7a6da3ae1b202125f638153b33c19b5fcededd713287073f913f221b15560a7384403241c0f740721928
|
7
|
+
data.tar.gz: 8761615f2d7bfa444bf9b0f6249801a68edd96f3ed65a286c5abe9f9a6b3143004b2672fd33ab53dfeee652d565152f533c93125272779434e8f7d58f4dd0104
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
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 `
|
25
|
-
using this gem in a JRuby
|
26
|
-
library must be
|
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` &
|
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 = :
|
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 `
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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 )
|
data/lib/purview/connections.rb
CHANGED
@@ -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
|
data/lib/purview/dialects.rb
CHANGED
@@ -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
|
data/lib/purview/pullers.rb
CHANGED
@@ -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
|
-
"
|
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
|
@@ -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
|
11
|
-
|
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
|
data/lib/purview/version.rb
CHANGED
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 << '`
|
23
|
-
gem.requirements << '`
|
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
|
+
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-
|
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
|
-
- "`
|
216
|
-
- "`
|
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:
|