rom-sql 0.4.0.beta2 → 0.4.0.rc1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +4 -1
- data/lib/rom/sql/repository.rb +93 -4
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +1 -1
- data/spec/integration/read_spec.rb +3 -2
- data/spec/shared/database_setup.rb +1 -2
- data/spec/unit/many_to_one_spec.rb +1 -1
- data/spec/unit/one_to_many_spec.rb +4 -1
- data/spec/unit/repository_spec.rb +1 -0
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57a2bfb4e1713bec72222dc1c886372999102814
|
4
|
+
data.tar.gz: 302233e252f9cf434f73bc8493d726fe849d5a28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b0520c09a6e9db3c2ea2571df0b9c5f4815283f75b876c71bd6a5598d80f55208b5d7cc8468abbaa9f729d2ab9c9943603480da3f12483acbab5017c8deb0c0
|
7
|
+
data.tar.gz: d862d6d1892af178796824e0c1f09a5d393dab89c23966524ed24d67f4f706367d502bdf34339866e678c4550619829afe59875b4b86cfbd022dd3cf70b95902
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,9 +13,12 @@
|
|
13
13
|
[][codeclimate]
|
14
14
|
[][inchpages]
|
15
15
|
|
16
|
-
|
17
16
|
RDBMS suport for [Ruby Object Mapper](https://github.com/rom-rb/rom).
|
18
17
|
|
18
|
+
## Issues
|
19
|
+
|
20
|
+
Please report any issues in the main [rom-rb/rom](https://github.com/rom-rb/rom/issues) issue tracker.
|
21
|
+
|
19
22
|
## Installation
|
20
23
|
|
21
24
|
Add this line to your application's Gemfile:
|
data/lib/rom/sql/repository.rb
CHANGED
@@ -6,38 +6,111 @@ require 'rom/sql/commands'
|
|
6
6
|
module ROM
|
7
7
|
module SQL
|
8
8
|
class Repository < ROM::Repository
|
9
|
-
|
9
|
+
# Return optionally configured logger
|
10
|
+
#
|
11
|
+
# @return [Object] logger
|
12
|
+
#
|
13
|
+
# @api public
|
14
|
+
attr_reader :logger
|
10
15
|
|
16
|
+
# Returns a list of datasets inferred from table names
|
17
|
+
#
|
18
|
+
# @return [Array] array with table names
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
attr_reader :schema
|
22
|
+
|
23
|
+
# @param [String,Symbol] scheme
|
24
|
+
#
|
25
|
+
# @api public
|
11
26
|
def self.database_file?(scheme)
|
12
27
|
scheme.to_s.include?('sqlite')
|
13
28
|
end
|
14
29
|
|
30
|
+
# SQL repository interface
|
31
|
+
#
|
32
|
+
# @overload connect(uri, options)
|
33
|
+
# Connects to database via uri passing options
|
34
|
+
#
|
35
|
+
# @param [String,Symbol] uri connection URI
|
36
|
+
# @param [Hash] options connection options
|
37
|
+
#
|
38
|
+
# @overload connect(connection)
|
39
|
+
# Re-uses connection instance
|
40
|
+
#
|
41
|
+
# @param [Sequel::Database] connection a connection instance
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# repository = ROM::SQL::Repository.new('postgres://localhost/rom')
|
45
|
+
#
|
46
|
+
# # or reuse connection
|
47
|
+
# DB = Sequel.connect('postgres://localhost/rom')
|
48
|
+
# repository = ROM::SQL::Repository.new(DB)
|
49
|
+
#
|
50
|
+
# @api public
|
15
51
|
def initialize(uri, options = {})
|
16
|
-
@connection =
|
52
|
+
@connection = connect(uri, options)
|
17
53
|
@schema = connection.tables
|
18
54
|
end
|
19
55
|
|
56
|
+
# Disconnect from database
|
57
|
+
#
|
58
|
+
# @api public
|
20
59
|
def disconnect
|
21
60
|
connection.disconnect
|
22
61
|
end
|
23
62
|
|
63
|
+
# Return dataset with the given name
|
64
|
+
#
|
65
|
+
# @param [String] name dataset name
|
66
|
+
#
|
67
|
+
# @return [Dataset]
|
68
|
+
#
|
69
|
+
# @api public
|
24
70
|
def [](name)
|
25
71
|
connection[name]
|
26
72
|
end
|
27
73
|
|
74
|
+
# Setup a logger
|
75
|
+
#
|
76
|
+
# @param [Object] logger
|
77
|
+
#
|
78
|
+
# @see Sequel::Database#loggers
|
79
|
+
#
|
80
|
+
# @api public
|
28
81
|
def use_logger(logger)
|
29
82
|
@logger = logger
|
30
83
|
connection.loggers << logger
|
31
84
|
end
|
32
85
|
|
33
|
-
|
34
|
-
|
86
|
+
# Return dataset with the given name
|
87
|
+
#
|
88
|
+
# @param [String] name a dataset name
|
89
|
+
#
|
90
|
+
# @return [Dataset]
|
91
|
+
#
|
92
|
+
# @api public
|
93
|
+
def dataset(name)
|
94
|
+
connection[name]
|
35
95
|
end
|
36
96
|
|
97
|
+
# Check if dataset exists
|
98
|
+
#
|
99
|
+
# @param [String] name dataset name
|
100
|
+
#
|
101
|
+
# @api public
|
37
102
|
def dataset?(name)
|
38
103
|
schema.include?(name)
|
39
104
|
end
|
40
105
|
|
106
|
+
# Extend database-specific behavior
|
107
|
+
#
|
108
|
+
# @param [Class] klass command class
|
109
|
+
# @param [Object] dataset a dataset that will be used
|
110
|
+
#
|
111
|
+
# Note: Currently, only postgres is supported.
|
112
|
+
#
|
113
|
+
# @api public
|
41
114
|
def extend_command_class(klass, dataset)
|
42
115
|
type = dataset.db.database_type
|
43
116
|
|
@@ -54,6 +127,22 @@ module ROM
|
|
54
127
|
|
55
128
|
klass
|
56
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
# Connect to database or reuse established connection instance
|
134
|
+
#
|
135
|
+
# @return [Database::Sequel] a connection instance
|
136
|
+
#
|
137
|
+
# @api private
|
138
|
+
def connect(uri, *args)
|
139
|
+
case uri
|
140
|
+
when ::Sequel::Database
|
141
|
+
uri
|
142
|
+
else
|
143
|
+
::Sequel.connect(uri.to_s, *args)
|
144
|
+
end
|
145
|
+
end
|
57
146
|
end
|
58
147
|
end
|
59
148
|
end
|
data/lib/rom/sql/version.rb
CHANGED
data/rom-sql.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "sequel", "~> 4.18"
|
22
22
|
spec.add_runtime_dependency "equalizer", "~> 0.0", ">= 0.0.9"
|
23
|
-
spec.add_runtime_dependency "rom", "~> 0.6.0.
|
23
|
+
spec.add_runtime_dependency "rom", "~> 0.6.0.rc1"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -87,7 +87,7 @@ describe 'Reading relations' do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'loads domain objects' do
|
90
|
-
user = rom.
|
90
|
+
user = rom.relation(:users).as(:users).with_tasks.by_name('Piotr').to_a.first
|
91
91
|
|
92
92
|
expect(user).to eql(
|
93
93
|
User.new(
|
@@ -98,7 +98,8 @@ describe 'Reading relations' do
|
|
98
98
|
it 'works with grouping and aggregates' do
|
99
99
|
rom.relations[:tasks].insert(id: 2, user_id: 1, title: 'Get Milk')
|
100
100
|
|
101
|
-
users_with_task_count = rom.
|
101
|
+
users_with_task_count = rom.relation(:user_task_counts).as(:user_task_counts).all
|
102
|
+
|
102
103
|
expect(users_with_task_count.to_a).to eq([
|
103
104
|
UserTaskCount.new(id: 1, name: "Piotr", task_count: 2)
|
104
105
|
])
|
@@ -3,7 +3,7 @@ shared_context 'database setup' do
|
|
3
3
|
|
4
4
|
let(:uri) { 'postgres://localhost/rom' }
|
5
5
|
let(:conn) { Sequel.connect(uri) }
|
6
|
-
let(:setup) { ROM.setup(:sql,
|
6
|
+
let(:setup) { ROM.setup(:sql, conn) }
|
7
7
|
|
8
8
|
def drop_tables
|
9
9
|
[:users, :tasks, :tags, :task_tags].each { |name| conn.drop_table?(name) }
|
@@ -39,7 +39,6 @@ shared_context 'database setup' do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
after do
|
42
|
-
rom.repositories[:default].disconnect
|
43
42
|
conn.disconnect
|
44
43
|
end
|
45
44
|
end
|
@@ -34,7 +34,7 @@ describe 'Defining many-to-one association' do
|
|
34
34
|
[{ id: 1, name: 'Piotr', title: 'Finish ROM' }]
|
35
35
|
)
|
36
36
|
|
37
|
-
expect(rom.
|
37
|
+
expect(rom.relation(:tasks).map_with(:with_user).all.with_user.to_a).to eql(
|
38
38
|
[{ id: 1, title: 'Finish ROM', user: { name: 'Piotr' } }]
|
39
39
|
)
|
40
40
|
end
|
@@ -34,7 +34,10 @@ describe 'Defining one-to-many association' do
|
|
34
34
|
[{ id: 1, name: 'Piotr', tasks_id: 1, title: 'Finish ROM' }]
|
35
35
|
)
|
36
36
|
|
37
|
-
|
37
|
+
result = rom.relation(:users).map_with(:with_tasks)
|
38
|
+
.all.with_tasks.by_name("Piotr").to_a
|
39
|
+
|
40
|
+
expect(result).to eql(
|
38
41
|
[{ id: 1, name: 'Piotr', tasks: [{ tasks_id: 1, title: 'Finish ROM' }] }]
|
39
42
|
)
|
40
43
|
end
|
@@ -28,6 +28,7 @@ describe ROM::SQL::Repository do
|
|
28
28
|
|
29
29
|
it 'disconnects via sequel connection' do
|
30
30
|
# FIXME: no idea how to test it in a different way
|
31
|
+
# FIXME: we are leaking connection here
|
31
32
|
expect(repository.connection).to receive(:disconnect)
|
32
33
|
repository.disconnect
|
33
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.
|
4
|
+
version: 0.4.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.6.0.
|
53
|
+
version: 0.6.0.rc1
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.6.0.
|
60
|
+
version: 0.6.0.rc1
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: bundler
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: 1.3.1
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.4.5
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: SQL databases support for ROM
|
@@ -193,4 +193,3 @@ test_files:
|
|
193
193
|
- spec/unit/relation_spec.rb
|
194
194
|
- spec/unit/repository_spec.rb
|
195
195
|
- spec/unit/schema_spec.rb
|
196
|
-
has_rdoc:
|