rom-sql 0.1.1 → 0.2.0
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 +21 -4
- data/Gemfile +1 -0
- data/README.md +6 -8
- data/lib/rom/sql.rb +12 -1
- data/lib/rom/sql/adapter.rb +18 -1
- data/lib/rom/sql/commands.rb +49 -0
- data/lib/rom/sql/support/active_support_notifications.rb +29 -0
- data/lib/rom/sql/support/rails_log_subscriber.rb +36 -0
- data/lib/rom/sql/version.rb +1 -1
- data/log/.gitkeep +0 -0
- data/rom-sql.gemspec +3 -3
- data/spec/integration/commands/create_spec.rb +51 -0
- data/spec/integration/commands/delete_spec.rb +33 -0
- data/spec/integration/commands/update_spec.rb +26 -0
- data/spec/shared/database_setup.rb +36 -0
- data/spec/shared/users_and_tasks.rb +1 -28
- data/spec/spec_helper.rb +3 -0
- data/spec/support/active_support_notifications_spec.rb +22 -0
- data/spec/support/rails_log_subscriber_spec.rb +29 -0
- data/spec/unit/adapter_spec.rb +18 -0
- data/spec/unit/logger_spec.rb +12 -0
- metadata +49 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c088db5ced8d4a5297ceb909e77dba86cd80ed37
|
4
|
+
data.tar.gz: 9d7f52c636a1418b966d7c609f57e766a1a4b224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2603a384db038ddf194df6827b4d29585f48b5db8cd4791117149e292c55d3c0e8ddcec364e516b046fab29a28c32af22e964f4788c4f44082b808239b1127b3
|
7
|
+
data.tar.gz: 67d0846c7bea76d5c9365d35874a9755aa1c0306cbf09de7ce51b4964c16784c740f2b8713bb632dca0d54ac3ba480fc931d3a477abd602791ed28be4ba81183
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
-
|
1
|
+
## v0.2.0 2014-12-06
|
2
2
|
|
3
|
-
|
4
|
-
* [internal] minor refactor in adapter (solnic)
|
3
|
+
### Added
|
5
4
|
|
6
|
-
|
5
|
+
* Command API (solnic)
|
6
|
+
* Support for ActiveSupport::Notifications with a log subscriber (solnic)
|
7
|
+
* New `ROM::SQL::Adapter#dataset?(name)` checking if a given table exists (solnic)
|
8
|
+
|
9
|
+
[Compare v0.1.1...v0.2.0](https://github.com/rom-rb/rom-sql/compare/v0.1.1...v0.2.0)
|
10
|
+
|
11
|
+
## v0.1.1 2014-11-24
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
* Equalizer in header (solnic)
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
* minor refactor in adapter (solnic)
|
20
|
+
|
21
|
+
[Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-sql/compare/v0.1.0...v0.1.1)
|
22
|
+
|
23
|
+
## v0.1.0 2014-11-24
|
7
24
|
|
8
25
|
First release powered by Sequel
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -41,7 +41,7 @@ in relation objects. For schema migrations you can use its
|
|
41
41
|
which is available via repositories.
|
42
42
|
|
43
43
|
``` ruby
|
44
|
-
setup = ROM.setup(sqlite: "memory
|
44
|
+
setup = ROM.setup(sqlite: "sqlite::memory")
|
45
45
|
|
46
46
|
setup.sqlite.connection.create_table(:users) do
|
47
47
|
primary_key :id
|
@@ -87,8 +87,8 @@ rom = setup.finalize
|
|
87
87
|
users = rom.relations.users
|
88
88
|
tasks = rom.relations.tasks
|
89
89
|
|
90
|
-
users.insert(name: "Piotr")
|
91
|
-
tasks.insert(title: "Be happy")
|
90
|
+
users.insert(id: 1, name: "Piotr")
|
91
|
+
tasks.insert(user_id: 1, title: "Be happy")
|
92
92
|
|
93
93
|
puts users.by_name("Piotr").with_tasks.to_a.inspect
|
94
94
|
# => [{:id=>1, :name=>"Piotr", :user_id=>1, :title=>"Be happy"}]
|
@@ -118,9 +118,7 @@ setup.mappers do
|
|
118
118
|
define(:users) do
|
119
119
|
model name: 'User'
|
120
120
|
|
121
|
-
group :
|
122
|
-
attribute :title
|
123
|
-
end
|
121
|
+
group tasks: [:title]
|
124
122
|
end
|
125
123
|
end
|
126
124
|
|
@@ -129,8 +127,8 @@ rom = setup.finalize
|
|
129
127
|
users = rom.relations.users
|
130
128
|
tasks = rom.relations.tasks
|
131
129
|
|
132
|
-
users.insert(name: "Piotr")
|
133
|
-
tasks.insert(title: "Be happy")
|
130
|
+
users.insert(id: 1, name: "Piotr")
|
131
|
+
tasks.insert(user_id: 1, title: "Be happy")
|
134
132
|
|
135
133
|
rom.read(:users).with_tasks.by_name("Piotr").to_a
|
136
134
|
# => [#<User:0x007fb31542a098 @id=1, @name="Piotr", @tasks=[{:title=>"Be happy"}]>]
|
data/lib/rom/sql.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require "sequel"
|
2
|
-
|
3
2
|
require "rom"
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
module SQL
|
6
|
+
ConstraintError = Class.new(ROM::CommandError)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
require "rom/sql/version"
|
5
11
|
require "rom/sql/header"
|
6
12
|
require "rom/sql/relation_extension"
|
@@ -8,3 +14,8 @@ require "rom/sql/relation_inclusion"
|
|
8
14
|
require "rom/sql/adapter"
|
9
15
|
|
10
16
|
require "rom/sql/support/sequel_dataset_ext"
|
17
|
+
|
18
|
+
if defined?(Rails)
|
19
|
+
require "rom/sql/support/active_support_notifications"
|
20
|
+
require 'rom/sql/support/rails_log_subscriber'
|
21
|
+
end
|
data/lib/rom/sql/adapter.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
require 'rom/sql/commands'
|
4
|
+
|
1
5
|
module ROM
|
2
6
|
module SQL
|
3
7
|
|
4
8
|
class Adapter < ROM::Adapter
|
5
|
-
attr_reader :
|
9
|
+
attr_reader :logger
|
6
10
|
|
7
11
|
def self.schemes
|
8
12
|
[:ado, :amalgalite, :cubrid, :db2, :dbi, :do, :fdbsql, :firebird, :ibmdb,
|
@@ -19,10 +23,19 @@ module ROM
|
|
19
23
|
connection[name]
|
20
24
|
end
|
21
25
|
|
26
|
+
def logger=(logger)
|
27
|
+
@logger = logger
|
28
|
+
connection.loggers << logger
|
29
|
+
end
|
30
|
+
|
22
31
|
def schema
|
23
32
|
tables.map { |table| [table, dataset(table), columns(table)] }
|
24
33
|
end
|
25
34
|
|
35
|
+
def dataset?(name)
|
36
|
+
tables.include?(name)
|
37
|
+
end
|
38
|
+
|
26
39
|
def extend_relation_class(klass)
|
27
40
|
klass.send(:include, RelationInclusion)
|
28
41
|
end
|
@@ -31,6 +44,10 @@ module ROM
|
|
31
44
|
relation.extend(RelationExtension)
|
32
45
|
end
|
33
46
|
|
47
|
+
def command_namespace
|
48
|
+
SQL::Commands
|
49
|
+
end
|
50
|
+
|
34
51
|
private
|
35
52
|
|
36
53
|
def tables
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module ROM
|
2
|
+
module SQL
|
3
|
+
module Commands
|
4
|
+
ERRORS = [
|
5
|
+
Sequel::UniqueConstraintViolation,
|
6
|
+
Sequel::NotNullConstraintViolation
|
7
|
+
].freeze
|
8
|
+
|
9
|
+
class Create < ROM::Commands::Create
|
10
|
+
|
11
|
+
def execute(tuples)
|
12
|
+
pks = Array([tuples]).flatten.map do |tuple|
|
13
|
+
attributes = input[tuple]
|
14
|
+
validator.call(attributes)
|
15
|
+
relation.insert(attributes.to_h)
|
16
|
+
end
|
17
|
+
|
18
|
+
relation.where(relation.model.primary_key => pks)
|
19
|
+
rescue *ERRORS => e
|
20
|
+
raise ConstraintError, e.message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Update < ROM::Commands::Update
|
25
|
+
|
26
|
+
def execute(tuple)
|
27
|
+
attributes = input[tuple]
|
28
|
+
validator.call(attributes)
|
29
|
+
|
30
|
+
pks = relation.map { |t| t[relation.model.primary_key] }
|
31
|
+
|
32
|
+
relation.update(attributes.to_h)
|
33
|
+
relation.unfiltered.where(relation.model.primary_key => pks)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class Delete < ROM::Commands::Delete
|
39
|
+
|
40
|
+
def execute
|
41
|
+
target.delete
|
42
|
+
relation
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sequel/database/logging'
|
2
|
+
require 'active_support/notifications'
|
3
|
+
|
4
|
+
module Sequel
|
5
|
+
|
6
|
+
class Database
|
7
|
+
|
8
|
+
def log_yield_with_instrumentation(sql, args = nil, &block)
|
9
|
+
ActiveSupport::Notifications.instrument(
|
10
|
+
'sql.rom',
|
11
|
+
:sql => sql,
|
12
|
+
:name => instrumentation_name,
|
13
|
+
:binds => args
|
14
|
+
) do
|
15
|
+
log_yield_without_instrumentation(sql, args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :log_yield_without_instrumentation, :log_yield
|
20
|
+
alias_method :log_yield, :log_yield_with_instrumentation
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def instrumentation_name
|
25
|
+
"ROM[#{database_type}]"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support/log_subscriber'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
module SQL
|
5
|
+
|
6
|
+
class RailsLogSubscriber < ActiveSupport::LogSubscriber
|
7
|
+
|
8
|
+
def sql(event)
|
9
|
+
return unless logger.debug?
|
10
|
+
|
11
|
+
payload = event.payload
|
12
|
+
|
13
|
+
name = format('%s (%.1fms)', payload[:name], event.duration)
|
14
|
+
sql = payload[:sql].squeeze(' ')
|
15
|
+
binds = payload[:binds].to_a.inspect if payload[:binds]
|
16
|
+
|
17
|
+
if odd?
|
18
|
+
name = color(name, :cyan, true)
|
19
|
+
sql = color(sql, nil, true)
|
20
|
+
else
|
21
|
+
name = color(name, :magenta, true)
|
22
|
+
end
|
23
|
+
|
24
|
+
debug " #{name} #{sql} #{binds}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def odd?
|
28
|
+
@odd_or_even = !@odd_or_even
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ROM::SQL::RailsLogSubscriber.attach_to(:rom)
|
data/lib/rom/sql/version.rb
CHANGED
data/log/.gitkeep
ADDED
File without changes
|
data/rom-sql.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'rom/sql/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rom-sql"
|
8
|
-
spec.version = ROM::SQL::VERSION
|
8
|
+
spec.version = ROM::SQL::VERSION.dup
|
9
9
|
spec.authors = ["Piotr Solnica"]
|
10
10
|
spec.email = ["piotr.solnica@gmail.com"]
|
11
11
|
spec.summary = %q{RDBMS support for ROM}
|
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "sequel", "~> 4.
|
21
|
+
spec.add_runtime_dependency "sequel", "~> 4.17"
|
22
22
|
spec.add_runtime_dependency "equalizer", "~> 0.0", ">= 0.0.9"
|
23
|
-
spec.add_runtime_dependency "rom", "~> 0.
|
23
|
+
spec.add_runtime_dependency "rom", "~> 0.4", ">= 0.4.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Commands / Create' do
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
subject(:users) { rom.commands.users }
|
7
|
+
|
8
|
+
before do
|
9
|
+
setup.relation(:users)
|
10
|
+
|
11
|
+
setup.commands(:users) do
|
12
|
+
define(:create) do
|
13
|
+
result :one
|
14
|
+
end
|
15
|
+
|
16
|
+
define(:create_many, type: :create) do
|
17
|
+
result :many
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns a single tuple when result is set to :one' do
|
23
|
+
result = users.try { create(id: 2, name: 'Jane') }
|
24
|
+
|
25
|
+
expect(result.value).to eql(id: 2, name: 'Jane')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns tuples when result is set to :many' do
|
29
|
+
result = users.try {
|
30
|
+
create_many([{ id: 2, name: 'Jane' }, { id: 3, name: 'Jack' }])
|
31
|
+
}
|
32
|
+
|
33
|
+
expect(result.value.to_a).to match_array([
|
34
|
+
{ id: 2, name: 'Jane' }, { id: 3, name: 'Jack' }
|
35
|
+
])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'handles not-null constraint violation error' do
|
39
|
+
result = users.try { create(id: nil, name: 'Jane') }
|
40
|
+
|
41
|
+
expect(result.error).to be_instance_of(ROM::SQL::ConstraintError)
|
42
|
+
expect(result.error.message).to match(/not-null/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'handles uniqueness constraint violation error' do
|
46
|
+
result = users.try { create(id: 3, name: 'Piotr') }
|
47
|
+
|
48
|
+
expect(result.error).to be_instance_of(ROM::SQL::ConstraintError)
|
49
|
+
expect(result.error.message).to match(/unique/)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Commands / Delete' do
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
subject(:users) { rom.commands.users }
|
7
|
+
|
8
|
+
before do
|
9
|
+
setup.relation(:users) do
|
10
|
+
def by_name(name)
|
11
|
+
where(name: 'Piotr')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
setup.commands(:users) do
|
16
|
+
define(:delete)
|
17
|
+
end
|
18
|
+
|
19
|
+
rom.relations.users.insert(id: 2, name: 'Jane')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'deletes all tuples' do
|
23
|
+
result = users.try { delete }
|
24
|
+
|
25
|
+
expect(result.value.to_a).to match_array([])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'deletes all tuples in a restricted relation' do
|
29
|
+
result = users.try { delete(:by_name, 'Jane').execute }
|
30
|
+
|
31
|
+
expect(result.value.to_a).to match_array([{ id: 2, name: 'Jane' }])
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Commands / Update' do
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
subject(:users) { rom.commands.users }
|
7
|
+
|
8
|
+
it 'works' do
|
9
|
+
setup.relation(:users) do
|
10
|
+
def by_name(name)
|
11
|
+
where(name: name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
setup.commands(:users) do
|
16
|
+
define(:update) do
|
17
|
+
input Hash
|
18
|
+
validator Proc.new {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
result = users.try { update(:by_name, 'Piotr').set(name: 'Peter') }
|
23
|
+
|
24
|
+
expect(result.value.to_a).to match_array([{ id: 1, name: 'Peter' }])
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_context 'database setup' do
|
2
|
+
subject(:rom) { setup.finalize }
|
3
|
+
|
4
|
+
let(:setup) { ROM.setup(postgres: 'postgres://localhost/rom') }
|
5
|
+
let(:conn) { setup.postgres.connection }
|
6
|
+
|
7
|
+
before do
|
8
|
+
setup.postgres.use_logger(LOGGER)
|
9
|
+
|
10
|
+
[:users, :tasks, :tags, :task_tags].each { |name| conn.drop_table?(name) }
|
11
|
+
|
12
|
+
conn.create_table :users do
|
13
|
+
primary_key :id
|
14
|
+
String :name
|
15
|
+
index :name, unique: true
|
16
|
+
end
|
17
|
+
|
18
|
+
conn.create_table :tasks do
|
19
|
+
primary_key :id
|
20
|
+
Integer :user_id
|
21
|
+
String :title
|
22
|
+
end
|
23
|
+
|
24
|
+
conn.create_table :tags do
|
25
|
+
primary_key :id
|
26
|
+
String :name
|
27
|
+
end
|
28
|
+
|
29
|
+
conn.create_table :task_tags do
|
30
|
+
primary_key :tag_id, :task_id
|
31
|
+
Integer :tag_id
|
32
|
+
Integer :task_id
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -1,34 +1,7 @@
|
|
1
1
|
shared_context 'users and tasks' do
|
2
|
-
|
3
|
-
|
4
|
-
let(:setup) { ROM.setup(postgres: 'postgres://localhost/rom') }
|
5
|
-
let(:conn) { setup.postgres.connection }
|
2
|
+
include_context 'database setup'
|
6
3
|
|
7
4
|
before do
|
8
|
-
[:users, :tasks, :tags, :task_tags].each { |name| conn.drop_table?(name) }
|
9
|
-
|
10
|
-
conn.create_table :users do
|
11
|
-
primary_key :id
|
12
|
-
String :name
|
13
|
-
end
|
14
|
-
|
15
|
-
conn.create_table :tasks do
|
16
|
-
primary_key :id
|
17
|
-
Integer :user_id
|
18
|
-
String :title
|
19
|
-
end
|
20
|
-
|
21
|
-
conn.create_table :tags do
|
22
|
-
primary_key :id
|
23
|
-
String :name
|
24
|
-
end
|
25
|
-
|
26
|
-
conn.create_table :task_tags do
|
27
|
-
primary_key :tag_id, :task_id
|
28
|
-
Integer :tag_id
|
29
|
-
Integer :task_id
|
30
|
-
end
|
31
|
-
|
32
5
|
conn[:users].insert id: 1, name: 'Piotr'
|
33
6
|
conn[:tasks].insert id: 1, user_id: 1, title: 'Finish ROM'
|
34
7
|
conn[:tags].insert id: 1, name: 'important'
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rom/sql/support/active_support_notifications'
|
4
|
+
require 'active_support/log_subscriber'
|
5
|
+
|
6
|
+
describe 'ActiveSupport::Notifications support' do
|
7
|
+
include_context 'database setup'
|
8
|
+
|
9
|
+
it 'works' do
|
10
|
+
rom.postgres.use_logger(LOGGER)
|
11
|
+
|
12
|
+
sql = nil
|
13
|
+
|
14
|
+
ActiveSupport::Notifications.subscribe('sql.rom') do |name, start, finish, id, payload|
|
15
|
+
sql = payload[:sql]
|
16
|
+
end
|
17
|
+
|
18
|
+
rom.postgres.connection.run(%(SELECT * FROM "users" WHERE name = 'notification test'))
|
19
|
+
|
20
|
+
expect(sql).to eql(%(SELECT * FROM "users" WHERE name = 'notification test'))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'rom/sql/support/active_support_notifications'
|
4
|
+
require 'rom/sql/support/rails_log_subscriber'
|
5
|
+
|
6
|
+
require 'active_support/log_subscriber/test_helper'
|
7
|
+
|
8
|
+
describe 'Rails log subscriber' do
|
9
|
+
include ActiveSupport::LogSubscriber::TestHelper
|
10
|
+
|
11
|
+
include_context 'database setup'
|
12
|
+
|
13
|
+
let(:test_query) do
|
14
|
+
%(SELECT * FROM "users" WHERE name = 'notification test')
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:logger) { ActiveSupport::LogSubscriber::TestHelper::MockLogger.new }
|
18
|
+
|
19
|
+
before do
|
20
|
+
set_logger(logger)
|
21
|
+
rom.postgres.use_logger(logger)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'works' do
|
25
|
+
rom.postgres.connection.run(test_query)
|
26
|
+
|
27
|
+
expect(logger.logged(:debug).last).to include(test_query)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ROM::Adapter do
|
4
|
+
subject(:adapter) { rom.postgres.adapter }
|
5
|
+
|
6
|
+
let(:setup) { ROM.setup(postgres: "postgres://localhost/rom") }
|
7
|
+
let(:rom) { setup.finalize }
|
8
|
+
|
9
|
+
describe '#dataset?' do
|
10
|
+
it 'returns true if a table exists' do
|
11
|
+
expect(adapter.dataset?(:users)).to be(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns false if a table does not exist' do
|
15
|
+
expect(adapter.dataset?(:not_here)).to be(false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Logger' do
|
4
|
+
include_context 'users and tasks'
|
5
|
+
|
6
|
+
it 'sets up a logger for sequel' do
|
7
|
+
repository = rom.postgres
|
8
|
+
|
9
|
+
expect(repository.logger).to be(LOGGER)
|
10
|
+
expect(repository.connection.loggers).to include(LOGGER)
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,95 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.17'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
26
|
+
version: '4.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: equalizer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.0'
|
34
|
-
- -
|
34
|
+
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 0.0.9
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0.0'
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.0.9
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rom
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - ~>
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
54
|
-
- -
|
53
|
+
version: '0.4'
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0.
|
56
|
+
version: 0.4.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - ~>
|
61
|
+
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '0.
|
64
|
-
- -
|
63
|
+
version: '0.4'
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 0.
|
66
|
+
version: 0.4.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: bundler
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- -
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rake
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - ~>
|
85
|
+
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '10.0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- - ~>
|
92
|
+
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '10.0'
|
95
95
|
description: RDBMS support for ROM
|
@@ -99,9 +99,9 @@ executables: []
|
|
99
99
|
extensions: []
|
100
100
|
extra_rdoc_files: []
|
101
101
|
files:
|
102
|
-
- .gitignore
|
103
|
-
- .rspec
|
104
|
-
- .travis.yml
|
102
|
+
- ".gitignore"
|
103
|
+
- ".rspec"
|
104
|
+
- ".travis.yml"
|
105
105
|
- CHANGELOG.md
|
106
106
|
- Gemfile
|
107
107
|
- LICENSE.txt
|
@@ -110,16 +110,28 @@ files:
|
|
110
110
|
- lib/rom-sql.rb
|
111
111
|
- lib/rom/sql.rb
|
112
112
|
- lib/rom/sql/adapter.rb
|
113
|
+
- lib/rom/sql/commands.rb
|
113
114
|
- lib/rom/sql/header.rb
|
114
115
|
- lib/rom/sql/relation_extension.rb
|
115
116
|
- lib/rom/sql/relation_inclusion.rb
|
116
117
|
- lib/rom/sql/spec/support.rb
|
118
|
+
- lib/rom/sql/support/active_support_notifications.rb
|
119
|
+
- lib/rom/sql/support/rails_log_subscriber.rb
|
117
120
|
- lib/rom/sql/support/sequel_dataset_ext.rb
|
118
121
|
- lib/rom/sql/version.rb
|
122
|
+
- log/.gitkeep
|
119
123
|
- rom-sql.gemspec
|
124
|
+
- spec/integration/commands/create_spec.rb
|
125
|
+
- spec/integration/commands/delete_spec.rb
|
126
|
+
- spec/integration/commands/update_spec.rb
|
127
|
+
- spec/shared/database_setup.rb
|
120
128
|
- spec/shared/users_and_tasks.rb
|
121
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/support/active_support_notifications_spec.rb
|
131
|
+
- spec/support/rails_log_subscriber_spec.rb
|
132
|
+
- spec/unit/adapter_spec.rb
|
122
133
|
- spec/unit/combined_associations_spec.rb
|
134
|
+
- spec/unit/logger_spec.rb
|
123
135
|
- spec/unit/many_to_many_spec.rb
|
124
136
|
- spec/unit/many_to_one_spec.rb
|
125
137
|
- spec/unit/one_to_many_spec.rb
|
@@ -135,26 +147,35 @@ require_paths:
|
|
135
147
|
- lib
|
136
148
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
149
|
requirements:
|
138
|
-
- -
|
150
|
+
- - ">="
|
139
151
|
- !ruby/object:Gem::Version
|
140
152
|
version: '0'
|
141
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
154
|
requirements:
|
143
|
-
- -
|
155
|
+
- - ">="
|
144
156
|
- !ruby/object:Gem::Version
|
145
157
|
version: '0'
|
146
158
|
requirements: []
|
147
159
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.2.2
|
149
161
|
signing_key:
|
150
162
|
specification_version: 4
|
151
163
|
summary: RDBMS support for ROM
|
152
164
|
test_files:
|
165
|
+
- spec/integration/commands/create_spec.rb
|
166
|
+
- spec/integration/commands/delete_spec.rb
|
167
|
+
- spec/integration/commands/update_spec.rb
|
168
|
+
- spec/shared/database_setup.rb
|
153
169
|
- spec/shared/users_and_tasks.rb
|
154
170
|
- spec/spec_helper.rb
|
171
|
+
- spec/support/active_support_notifications_spec.rb
|
172
|
+
- spec/support/rails_log_subscriber_spec.rb
|
173
|
+
- spec/unit/adapter_spec.rb
|
155
174
|
- spec/unit/combined_associations_spec.rb
|
175
|
+
- spec/unit/logger_spec.rb
|
156
176
|
- spec/unit/many_to_many_spec.rb
|
157
177
|
- spec/unit/many_to_one_spec.rb
|
158
178
|
- spec/unit/one_to_many_spec.rb
|
159
179
|
- spec/unit/relation_spec.rb
|
160
180
|
- spec/unit/schema_spec.rb
|
181
|
+
has_rdoc:
|