rom-sql 0.3.2 → 0.4.0.beta1
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/.gitignore +1 -0
- data/.rubocop.yml +55 -18
- data/.rubocop_todo.yml +15 -0
- data/.travis.yml +10 -5
- data/CHANGELOG.md +18 -0
- data/Gemfile +8 -1
- data/Guardfile +24 -0
- data/README.md +14 -22
- data/Rakefile +13 -5
- data/lib/rom/sql.rb +5 -5
- data/lib/rom/sql/commands.rb +7 -49
- data/lib/rom/sql/commands/create.rb +29 -0
- data/lib/rom/sql/commands/delete.rb +18 -0
- data/lib/rom/sql/commands/transaction.rb +17 -0
- data/lib/rom/sql/commands/update.rb +54 -0
- data/lib/rom/sql/commands_ext/postgres.rb +24 -0
- data/lib/rom/sql/header.rb +8 -9
- data/lib/rom/sql/migration.rb +26 -0
- data/lib/rom/sql/plugin/pagination.rb +93 -0
- data/lib/rom/sql/rake_task.rb +2 -0
- data/lib/rom/sql/relation.rb +320 -0
- data/lib/rom/sql/relation/associations.rb +104 -0
- data/lib/rom/sql/relation/class_methods.rb +47 -0
- data/lib/rom/sql/relation/inspection.rb +16 -0
- data/lib/rom/sql/repository.rb +59 -0
- data/lib/rom/sql/support/rails_log_subscriber.rb +1 -1
- data/lib/rom/sql/tasks/migration_tasks.rake +56 -0
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +2 -3
- data/spec/integration/commands/create_spec.rb +66 -8
- data/spec/integration/commands/delete_spec.rb +22 -3
- data/spec/integration/commands/update_spec.rb +57 -6
- data/spec/integration/read_spec.rb +42 -1
- data/spec/shared/database_setup.rb +10 -5
- data/spec/spec_helper.rb +17 -0
- data/spec/support/active_support_notifications_spec.rb +5 -4
- data/spec/support/rails_log_subscriber_spec.rb +2 -2
- data/spec/unit/logger_spec.rb +5 -3
- data/spec/unit/many_to_many_spec.rb +2 -2
- data/spec/unit/migration_spec.rb +34 -0
- data/spec/unit/migration_tasks_spec.rb +99 -0
- data/spec/unit/one_to_many_spec.rb +0 -2
- data/spec/unit/plugin/pagination_spec.rb +73 -0
- data/spec/unit/relation_spec.rb +49 -3
- data/spec/unit/repository_spec.rb +33 -0
- data/spec/unit/schema_spec.rb +5 -17
- metadata +32 -35
- data/lib/rom/sql/adapter.rb +0 -100
- data/lib/rom/sql/relation_inclusion.rb +0 -149
- data/lib/rom/sql/support/sequel_dataset_ext.rb +0 -33
- data/spec/unit/adapter_spec.rb +0 -48
- data/spec/unit/config_spec.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43358c16de1cbf1030d10052160c9a5a7e922216
|
4
|
+
data.tar.gz: 0c9950d51f83c690436f1ba9504435c2bad53d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 916eb01f87b7825519ec9d917ee1904e04fa75537e5e2e35ba470cdc6239f4a0f2037393b64cec97e77fd9f1ea322939cf919e00618a6fff628297bfd1d9ab34
|
7
|
+
data.tar.gz: d2a3fe1e9077a547b44938c3600d5586548a7a283fa4d46de8c2d73d8b51394f56e8691b88d6197a38de9662c2c3ec697d24ed5415ee48df522010877da70728
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,41 +1,78 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
Max: 27
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
4
3
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
4
|
+
# Exclude temporary files
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- tmp/**/*
|
8
|
+
|
9
|
+
# It’s quite readable when we know what we are doing
|
10
|
+
Lint/AssignmentInCondition:
|
11
|
+
Enabled: false
|
8
12
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
13
|
+
# No need to handle LoadError in Rakefile
|
14
|
+
Lint/HandleExceptions:
|
15
|
+
Exclude:
|
16
|
+
- Rakefile
|
12
17
|
|
13
|
-
#
|
18
|
+
# gemspec is a special snowflake
|
14
19
|
Metrics/LineLength:
|
15
20
|
Exclude:
|
16
|
-
-
|
21
|
+
- rom.gemspec
|
17
22
|
|
18
23
|
# The enforced style doesn’t match Vim’s defaults
|
19
24
|
Style/AlignParameters:
|
20
25
|
Enabled: false
|
21
26
|
|
27
|
+
# UTF-8 is perfectly fine in comments
|
28
|
+
Style/AsciiComments:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
# Allow using braces for value-returning blocks
|
32
|
+
Style/Blocks:
|
33
|
+
Enabled: false
|
34
|
+
|
22
35
|
# Documentation checked by Inch CI
|
23
36
|
Style/Documentation:
|
24
37
|
Enabled: false
|
25
38
|
|
26
|
-
#
|
27
|
-
Style/
|
28
|
-
|
29
|
-
- lib/rom-sql.rb
|
39
|
+
# Early returns have their vices
|
40
|
+
Style/GuardClause:
|
41
|
+
Enabled: false
|
30
42
|
|
31
|
-
#
|
32
|
-
Style/
|
33
|
-
|
43
|
+
# Need to be skipped for >-> usage
|
44
|
+
Style/Lambda:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
# Multiline block chains are ok
|
48
|
+
Style/MultilineBlockChain:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
# Result::Success and Result::Failure use > for callbacks
|
52
|
+
Style/OpMethod:
|
53
|
+
Exclude:
|
54
|
+
- lib/rom/command_registry.rb
|
34
55
|
|
35
56
|
# Even a single escaped slash can be confusing
|
36
57
|
Style/RegexpLiteral:
|
37
58
|
MaxSlashes: 0
|
38
59
|
|
60
|
+
# Don’t introduce semantic fail/raise distinction
|
61
|
+
Style/SignalException:
|
62
|
+
EnforcedStyle: only_raise
|
63
|
+
|
64
|
+
# Need to be skipped for >-> usage
|
65
|
+
Style/SpaceAroundOperators:
|
66
|
+
Enabled: false
|
67
|
+
|
39
68
|
# Accept both single and double quotes
|
40
69
|
Style/StringLiterals:
|
41
70
|
Enabled: false
|
71
|
+
|
72
|
+
# Allow def self.foo; @foo; end
|
73
|
+
Style/TrivialAccessors:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
# Allow rom-sql
|
77
|
+
Style/FileName:
|
78
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-01-25 22:37:25 +0100 using RuboCop version 0.28.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 3
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 20
|
11
|
+
|
12
|
+
# Offense count: 2
|
13
|
+
# Configuration parameters: CountComments.
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 14
|
data/.travis.yml
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
bundler_args: --without yard guard benchmarks tools
|
5
5
|
before_script:
|
6
6
|
- psql -c 'create database rom;' -U postgres
|
7
|
-
script: "bundle exec rake
|
7
|
+
script: "bundle exec rake ci"
|
8
8
|
rvm:
|
9
9
|
- 2.0
|
10
10
|
- 2.1
|
11
11
|
- 2.2
|
12
12
|
- rbx-2
|
13
13
|
- jruby
|
14
|
+
- jruby-head
|
14
15
|
- ruby-head
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- CODECLIMATE_REPO_TOKEN=03d7f66589572702b12426d2bc71c4de6281a96139e33b335b894264b1f8f0b0
|
19
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
15
20
|
matrix:
|
16
21
|
allow_failures:
|
17
22
|
- rvm: ruby-head
|
18
|
-
- rvm: jruby
|
23
|
+
- rvm: jruby-head
|
19
24
|
notifications:
|
20
25
|
webhooks:
|
21
26
|
urls:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## v0.4.0 to-be-released
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* `ROM::SQL::Relation` which explictly defines an interface on top of Sequel (solnic + mcls)
|
6
|
+
* Experimental migration API using sequel/migrations (gotar)
|
7
|
+
* Pagination plugin (solnic)
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
* Use ROM's own inflector which uses either ActiveSupport or Inflecto backends (mjtko)
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
* Indentation in Rails logger (morgoth)
|
16
|
+
|
17
|
+
[Compare v0.3.2...master](https://github.com/rom-rb/rom-sql/compare/v0.3.2...master)
|
18
|
+
|
1
19
|
## v0.3.2 2015-01-01
|
2
20
|
|
3
21
|
### Fixed
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem 'rom', '~> 0.
|
6
|
+
gem 'rom', '~> 0.6.0', github: 'rom-rb/rom', branch: 'master'
|
7
7
|
gem 'virtus'
|
8
8
|
gem 'activesupport'
|
9
9
|
gem 'rspec', '~> 3.1'
|
@@ -11,3 +11,10 @@ group :test do
|
|
11
11
|
gem 'pg', platforms: [:mri, :rbx]
|
12
12
|
gem 'pg_jruby', platforms: :jruby
|
13
13
|
end
|
14
|
+
|
15
|
+
group :tools do
|
16
|
+
gem 'guard'
|
17
|
+
gem 'guard-rspec'
|
18
|
+
gem 'guard-rubocop'
|
19
|
+
gem 'rubocop', '~> 0.28'
|
20
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
group :red_green_refactor, halt_on_fail: true do
|
2
|
+
guard :rspec, cmd: "rspec", all_on_start: true do
|
3
|
+
# run all specs if Gemfile.lock is modified
|
4
|
+
watch('Gemfile.lock') { 'spec' }
|
5
|
+
|
6
|
+
# run all specs if any library code is modified
|
7
|
+
watch(%r{\Alib/.+\.rb\z}) { 'spec' }
|
8
|
+
|
9
|
+
# run all specs if supporting files are modified
|
10
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
11
|
+
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
|
12
|
+
|
13
|
+
# run a spec if it is modified
|
14
|
+
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
15
|
+
|
16
|
+
notification :tmux, display_message: true if ENV.key?('TMUX')
|
17
|
+
end
|
18
|
+
|
19
|
+
guard :rubocop do
|
20
|
+
# run rubocop on modified file
|
21
|
+
watch(%r{\Alib/.+\.rb\z})
|
22
|
+
watch(%r{\Aspec/.+\.rb\z})
|
23
|
+
end
|
24
|
+
end
|
data/README.md
CHANGED
@@ -41,15 +41,15 @@ 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(
|
44
|
+
setup = ROM.setup(:sql, "sqlite::memory")
|
45
45
|
|
46
|
-
setup.
|
46
|
+
setup.default.connection.create_table(:users) do
|
47
47
|
primary_key :id
|
48
48
|
String :name
|
49
49
|
Boolean :admin
|
50
50
|
end
|
51
51
|
|
52
|
-
setup.
|
52
|
+
setup.default.connection.create_table(:tasks) do
|
53
53
|
primary_key :id
|
54
54
|
Integer :user_id
|
55
55
|
String :title
|
@@ -60,15 +60,15 @@ end
|
|
60
60
|
|
61
61
|
``` ruby
|
62
62
|
|
63
|
-
|
63
|
+
class Users < ROM::Relation[:sql]
|
64
|
+
base_name :users
|
64
65
|
|
65
|
-
setup.relation(:users) do
|
66
66
|
def by_name(name)
|
67
67
|
where(name: name)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
rom =
|
71
|
+
rom = ROM.finalize.env
|
72
72
|
|
73
73
|
users = rom.relations.users
|
74
74
|
tasks = rom.relations.tasks
|
@@ -95,9 +95,9 @@ Sequel's association DSL is available in relation definitions which enables
|
|
95
95
|
aggregate objects `wrap` and `group` mapping transformation can be used
|
96
96
|
|
97
97
|
``` ruby
|
98
|
-
setup
|
98
|
+
ROM.setup(:sql, "sqlite::memory")
|
99
99
|
|
100
|
-
|
100
|
+
class Users < ROM::Relation[:sql]
|
101
101
|
one_to_many :tasks, key: :user_id
|
102
102
|
|
103
103
|
def by_name(name)
|
@@ -109,15 +109,15 @@ setup.relation(:users) do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
|
113
|
-
|
114
|
-
model name: 'User'
|
112
|
+
class UserMapper < ROM::Mapper
|
113
|
+
relation :users
|
115
114
|
|
116
|
-
|
117
|
-
|
115
|
+
model name: 'User'
|
116
|
+
|
117
|
+
group tasks: [:title]
|
118
118
|
end
|
119
119
|
|
120
|
-
rom =
|
120
|
+
rom = ROM.finalize.env
|
121
121
|
|
122
122
|
users = rom.relations.users
|
123
123
|
tasks = rom.relations.tasks
|
@@ -131,14 +131,6 @@ rom.read(:users).with_tasks.by_name("Piotr").to_a
|
|
131
131
|
|
132
132
|
## ROADMAP
|
133
133
|
|
134
|
-
On a very high level:
|
135
|
-
|
136
|
-
* Make it dead simple to join relations and support all types of joins
|
137
|
-
* Make it dead simple to select and alias column names
|
138
|
-
* Discover conventions for typical query scenarios and make common things trivial,
|
139
|
-
less common things simple and super rare cases possible
|
140
|
-
* Make mapper interface smart enough to figure out when columns are aliased
|
141
|
-
|
142
134
|
For details please refer to [issues](https://github.com/rom-rb/rom-sql/issues).
|
143
135
|
|
144
136
|
## License
|
data/Rakefile
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
require "rspec/core/rake_task"
|
2
|
-
require "rubocop/rake_task"
|
3
|
-
|
4
|
-
task default: [:spec, :rubocop]
|
5
2
|
|
6
3
|
RSpec::Core::RakeTask.new(:spec)
|
4
|
+
task default: [:ci]
|
5
|
+
|
6
|
+
desc "Run CI tasks"
|
7
|
+
task ci: [:spec]
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "rubocop/rake_task"
|
11
|
+
|
12
|
+
Rake::Task[:default].enhance [:rubocop]
|
7
13
|
|
8
|
-
RuboCop::RakeTask.new do |task|
|
9
|
-
|
14
|
+
RuboCop::RakeTask.new do |task|
|
15
|
+
task.options << "--display-cop-names"
|
16
|
+
end
|
17
|
+
rescue LoadError
|
10
18
|
end
|
data/lib/rom/sql.rb
CHANGED
@@ -8,13 +8,13 @@ module ROM
|
|
8
8
|
end
|
9
9
|
|
10
10
|
require "rom/sql/version"
|
11
|
-
require "rom/sql/
|
12
|
-
require "rom/sql/
|
13
|
-
require "rom/sql/
|
14
|
-
|
15
|
-
require "rom/sql/support/sequel_dataset_ext"
|
11
|
+
require "rom/sql/relation"
|
12
|
+
require "rom/sql/repository"
|
13
|
+
require "rom/sql/migration"
|
16
14
|
|
17
15
|
if defined?(Rails)
|
18
16
|
require "rom/sql/support/active_support_notifications"
|
19
17
|
require 'rom/sql/support/rails_log_subscriber'
|
20
18
|
end
|
19
|
+
|
20
|
+
ROM.register_adapter(:sql, ROM::SQL)
|
data/lib/rom/sql/commands.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rom/commands'
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
module Commands
|
@@ -5,55 +7,11 @@ module ROM
|
|
5
7
|
Sequel::UniqueConstraintViolation,
|
6
8
|
Sequel::NotNullConstraintViolation
|
7
9
|
].freeze
|
8
|
-
|
9
|
-
module TupleCount
|
10
|
-
# TODO: we need an interface for "target_count" here
|
11
|
-
def assert_tuple_count
|
12
|
-
if result == :one && target.count > 1
|
13
|
-
raise TupleCountMismatchError, "#{inspect} expects one tuple"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Create < ROM::Commands::Create
|
19
|
-
include TupleCount
|
20
|
-
|
21
|
-
def execute(tuples)
|
22
|
-
pks = Array([tuples]).flatten.map do |tuple|
|
23
|
-
attributes = input[tuple]
|
24
|
-
validator.call(attributes)
|
25
|
-
relation.insert(attributes.to_h)
|
26
|
-
end
|
27
|
-
|
28
|
-
relation.where(relation.model.primary_key => pks)
|
29
|
-
rescue *ERRORS => e
|
30
|
-
raise ConstraintError, e.message
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Update < ROM::Commands::Update
|
35
|
-
include TupleCount
|
36
|
-
|
37
|
-
def execute(tuple)
|
38
|
-
attributes = input[tuple]
|
39
|
-
validator.call(attributes)
|
40
|
-
|
41
|
-
pks = relation.map { |t| t[relation.model.primary_key] }
|
42
|
-
|
43
|
-
relation.update(attributes.to_h)
|
44
|
-
relation.unfiltered.where(relation.model.primary_key => pks)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class Delete < ROM::Commands::Delete
|
49
|
-
include TupleCount
|
50
|
-
|
51
|
-
def execute
|
52
|
-
deleted = target.to_a
|
53
|
-
target.delete
|
54
|
-
deleted
|
55
|
-
end
|
56
|
-
end
|
57
10
|
end
|
58
11
|
end
|
59
12
|
end
|
13
|
+
|
14
|
+
require 'rom/sql/commands/create'
|
15
|
+
require 'rom/sql/commands/update'
|
16
|
+
require 'rom/sql/commands/delete'
|
17
|
+
require 'rom/sql/commands_ext/postgres'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rom/sql/commands'
|
2
|
+
require 'rom/sql/commands/transaction'
|
3
|
+
|
4
|
+
module ROM
|
5
|
+
module SQL
|
6
|
+
module Commands
|
7
|
+
class Create < ROM::Commands::Create
|
8
|
+
include Transaction
|
9
|
+
|
10
|
+
def execute(tuples)
|
11
|
+
insert_tuples = Array([tuples]).flatten.map do |tuple|
|
12
|
+
attributes = input[tuple]
|
13
|
+
validator.call(attributes)
|
14
|
+
attributes.to_h
|
15
|
+
end
|
16
|
+
|
17
|
+
insert(insert_tuples)
|
18
|
+
rescue *ERRORS => e
|
19
|
+
raise ConstraintError, e.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def insert(tuples)
|
23
|
+
pks = tuples.map { |tuple| relation.insert(tuple) }
|
24
|
+
relation.where(relation.primary_key => pks)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|