rom-sql 2.0.0.beta2 → 2.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +54 -0
- data/lib/rom/sql.rb +1 -1
- data/lib/rom/sql/attribute.rb +17 -18
- data/lib/rom/sql/errors.rb +3 -0
- data/lib/rom/sql/extensions/mysql.rb +1 -1
- data/lib/rom/sql/extensions/mysql/type_builder.rb +28 -0
- data/lib/rom/sql/extensions/postgres.rb +3 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +30 -13
- data/lib/rom/sql/extensions/postgres/{attributes_inferrer.rb → type_builder.rb} +24 -28
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +39 -0
- data/lib/rom/sql/extensions/postgres/types.rb +24 -477
- data/lib/rom/sql/extensions/postgres/types/array.rb +163 -0
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +135 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +235 -0
- data/lib/rom/sql/extensions/postgres/types/network.rb +15 -0
- data/lib/rom/sql/extensions/sqlite.rb +1 -1
- data/lib/rom/sql/extensions/sqlite/{attributes_inferrer.rb → type_builder.rb} +5 -5
- data/lib/rom/sql/extensions/sqlite/types.rb +8 -3
- data/lib/rom/sql/foreign_key.rb +17 -0
- data/lib/rom/sql/function.rb +86 -8
- data/lib/rom/sql/gateway.rb +26 -26
- data/lib/rom/sql/index.rb +4 -0
- data/lib/rom/sql/migration.rb +3 -3
- data/lib/rom/sql/migration/inline_runner.rb +9 -83
- data/lib/rom/sql/migration/migrator.rb +35 -12
- data/lib/rom/sql/migration/recorder.rb +21 -0
- data/lib/rom/sql/migration/runner.rb +115 -0
- data/lib/rom/sql/migration/schema_diff.rb +108 -53
- data/lib/rom/sql/migration/writer.rb +61 -0
- data/lib/rom/sql/relation.rb +2 -1
- data/lib/rom/sql/relation/reading.rb +63 -3
- data/lib/rom/sql/relation/writing.rb +38 -0
- data/lib/rom/sql/schema.rb +9 -3
- data/lib/rom/sql/schema/attributes_inferrer.rb +3 -119
- data/lib/rom/sql/schema/inferrer.rb +99 -18
- data/lib/rom/sql/schema/type_builder.rb +94 -0
- data/lib/rom/sql/type_dsl.rb +30 -0
- data/lib/rom/sql/type_extensions.rb +11 -6
- data/lib/rom/sql/type_serializer.rb +46 -0
- data/lib/rom/sql/types.rb +12 -0
- data/lib/rom/sql/version.rb +1 -1
- metadata +26 -244
- data/.codeclimate.yml +0 -15
- data/.gitignore +0 -17
- data/.rspec +0 -3
- data/.travis.yml +0 -39
- data/.yardopts +0 -2
- data/Gemfile +0 -33
- data/Guardfile +0 -24
- data/LICENSE.txt +0 -22
- data/Rakefile +0 -19
- data/circle.yml +0 -10
- data/lib/rom/sql/extensions/mysql/attributes_inferrer.rb +0 -10
- data/lib/rom/sql/relation/sequel_api.rb +0 -133
- data/log/.gitkeep +0 -0
- data/rom-sql.gemspec +0 -29
- data/spec/extensions/postgres/attribute_spec.rb +0 -217
- data/spec/extensions/postgres/integration_spec.rb +0 -59
- data/spec/extensions/postgres/types_spec.rb +0 -252
- data/spec/extensions/sqlite/types_spec.rb +0 -11
- data/spec/fixtures/migrations/20150403090603_create_carrots.rb +0 -8
- data/spec/integration/associations/many_to_many/custom_fks_spec.rb +0 -76
- data/spec/integration/associations/many_to_many/from_view_spec.rb +0 -88
- data/spec/integration/associations/many_to_many_spec.rb +0 -162
- data/spec/integration/associations/many_to_one/custom_fks_spec.rb +0 -64
- data/spec/integration/associations/many_to_one/from_view_spec.rb +0 -84
- data/spec/integration/associations/many_to_one/self_ref_spec.rb +0 -53
- data/spec/integration/associations/many_to_one_spec.rb +0 -117
- data/spec/integration/associations/one_to_many/custom_fks_spec.rb +0 -54
- data/spec/integration/associations/one_to_many/from_view_spec.rb +0 -57
- data/spec/integration/associations/one_to_many/self_ref_spec.rb +0 -54
- data/spec/integration/associations/one_to_many_spec.rb +0 -86
- data/spec/integration/associations/one_to_one_spec.rb +0 -69
- data/spec/integration/associations/one_to_one_through_spec.rb +0 -92
- data/spec/integration/auto_migrations/errors_spec.rb +0 -31
- data/spec/integration/auto_migrations/indexes_spec.rb +0 -253
- data/spec/integration/auto_migrations/managing_columns_spec.rb +0 -156
- data/spec/integration/auto_migrations/postgres/column_types_spec.rb +0 -63
- data/spec/integration/combine_with_spec.rb +0 -43
- data/spec/integration/commands/create_spec.rb +0 -304
- data/spec/integration/commands/delete_spec.rb +0 -84
- data/spec/integration/commands/update_spec.rb +0 -90
- data/spec/integration/commands/upsert_spec.rb +0 -83
- data/spec/integration/gateway_spec.rb +0 -107
- data/spec/integration/migration_spec.rb +0 -55
- data/spec/integration/plugins/associates/many_to_many_spec.rb +0 -69
- data/spec/integration/plugins/associates_spec.rb +0 -250
- data/spec/integration/plugins/auto_restrictions_spec.rb +0 -74
- data/spec/integration/relation_schema_spec.rb +0 -271
- data/spec/integration/schema/call_spec.rb +0 -24
- data/spec/integration/schema/inferrer/mysql_spec.rb +0 -45
- data/spec/integration/schema/inferrer/postgres_spec.rb +0 -203
- data/spec/integration/schema/inferrer/sqlite_spec.rb +0 -37
- data/spec/integration/schema/inferrer_spec.rb +0 -390
- data/spec/integration/schema/prefix_spec.rb +0 -16
- data/spec/integration/schema/qualified_spec.rb +0 -16
- data/spec/integration/schema/rename_spec.rb +0 -21
- data/spec/integration/schema/view_spec.rb +0 -29
- data/spec/integration/sequel_api_spec.rb +0 -36
- data/spec/integration/setup_spec.rb +0 -26
- data/spec/integration/support/active_support_notifications_spec.rb +0 -24
- data/spec/integration/support/rails_log_subscriber_spec.rb +0 -30
- data/spec/integration/wrap_spec.rb +0 -91
- data/spec/shared/accounts.rb +0 -48
- data/spec/shared/database_setup.rb +0 -70
- data/spec/shared/notes.rb +0 -23
- data/spec/shared/posts.rb +0 -34
- data/spec/shared/puppies.rb +0 -15
- data/spec/shared/relations.rb +0 -8
- data/spec/shared/users.rb +0 -32
- data/spec/shared/users_and_tasks.rb +0 -50
- data/spec/spec_helper.rb +0 -122
- data/spec/support/env_helper.rb +0 -25
- data/spec/support/helpers.rb +0 -24
- data/spec/support/oracle/create_users.sql +0 -7
- data/spec/support/oracle/set_sys_passwords.sql +0 -2
- data/spec/support/test_configuration.rb +0 -16
- data/spec/unit/attribute_spec.rb +0 -104
- data/spec/unit/function_spec.rb +0 -48
- data/spec/unit/gateway_spec.rb +0 -70
- data/spec/unit/logger_spec.rb +0 -14
- data/spec/unit/migration_tasks_spec.rb +0 -111
- data/spec/unit/migrator_spec.rb +0 -25
- data/spec/unit/order_dsl_spec.rb +0 -43
- data/spec/unit/plugin/associates_spec.rb +0 -94
- data/spec/unit/plugin/pagination_spec.rb +0 -91
- data/spec/unit/plugin/timestamp_spec.rb +0 -117
- data/spec/unit/projection_dsl_spec.rb +0 -110
- data/spec/unit/relation/assoc_spec.rb +0 -87
- data/spec/unit/relation/associations_spec.rb +0 -27
- data/spec/unit/relation/avg_spec.rb +0 -11
- data/spec/unit/relation/by_pk_spec.rb +0 -62
- data/spec/unit/relation/dataset_spec.rb +0 -50
- data/spec/unit/relation/distinct_spec.rb +0 -15
- data/spec/unit/relation/exclude_spec.rb +0 -11
- data/spec/unit/relation/exist_predicate_spec.rb +0 -25
- data/spec/unit/relation/exists_spec.rb +0 -18
- data/spec/unit/relation/fetch_spec.rb +0 -21
- data/spec/unit/relation/group_spec.rb +0 -61
- data/spec/unit/relation/having_spec.rb +0 -22
- data/spec/unit/relation/inner_join_spec.rb +0 -158
- data/spec/unit/relation/inspect_spec.rb +0 -11
- data/spec/unit/relation/instrument_spec.rb +0 -45
- data/spec/unit/relation/invert_spec.rb +0 -11
- data/spec/unit/relation/left_join_spec.rb +0 -55
- data/spec/unit/relation/lock_spec.rb +0 -93
- data/spec/unit/relation/map_spec.rb +0 -16
- data/spec/unit/relation/max_spec.rb +0 -11
- data/spec/unit/relation/min_spec.rb +0 -11
- data/spec/unit/relation/order_spec.rb +0 -51
- data/spec/unit/relation/pluck_spec.rb +0 -11
- data/spec/unit/relation/prefix_spec.rb +0 -29
- data/spec/unit/relation/primary_key_spec.rb +0 -27
- data/spec/unit/relation/project_spec.rb +0 -24
- data/spec/unit/relation/qualified_columns_spec.rb +0 -30
- data/spec/unit/relation/qualified_spec.rb +0 -25
- data/spec/unit/relation/read_spec.rb +0 -25
- data/spec/unit/relation/rename_spec.rb +0 -23
- data/spec/unit/relation/right_join_spec.rb +0 -57
- data/spec/unit/relation/select_append_spec.rb +0 -21
- data/spec/unit/relation/select_spec.rb +0 -40
- data/spec/unit/relation/sum_spec.rb +0 -11
- data/spec/unit/relation/union_spec.rb +0 -19
- data/spec/unit/relation/unique_predicate_spec.rb +0 -18
- data/spec/unit/relation/where_spec.rb +0 -133
- data/spec/unit/restriction_dsl_spec.rb +0 -34
- data/spec/unit/schema_spec.rb +0 -25
- data/spec/unit/types_spec.rb +0 -65
data/.codeclimate.yml
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: required
|
4
|
-
cache: bundler
|
5
|
-
services:
|
6
|
-
- postgresql
|
7
|
-
- mysql
|
8
|
-
bundler_args: --without yard guard benchmarks tools
|
9
|
-
before_script:
|
10
|
-
- psql -c 'create database rom_sql;' -U postgres
|
11
|
-
- mysql -u root -e 'create database rom_sql;'
|
12
|
-
- rvm get master
|
13
|
-
after_success:
|
14
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
15
|
-
script: "bundle exec rake ci"
|
16
|
-
rvm:
|
17
|
-
- 2.2.7
|
18
|
-
- 2.3.4
|
19
|
-
- 2.4.1
|
20
|
-
- jruby-9.1.8.0
|
21
|
-
env:
|
22
|
-
global:
|
23
|
-
- CODECLIMATE_REPO_TOKEN=03d7f66589572702b12426d2bc71c4de6281a96139e33b335b894264b1f8f0b0
|
24
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
25
|
-
- COVERAGE='true'
|
26
|
-
notifications:
|
27
|
-
webhooks:
|
28
|
-
urls:
|
29
|
-
- https://webhooks.gitter.im/e/39e1225f489f38b0bd09
|
30
|
-
on_success: change
|
31
|
-
on_failure: always
|
32
|
-
on_start: false
|
33
|
-
addons:
|
34
|
-
postgresql: 9.5
|
35
|
-
apt:
|
36
|
-
packages:
|
37
|
-
- mysql-server-5.6
|
38
|
-
- mysql-client-core-5.6
|
39
|
-
- mysql-client-5.6
|
data/.yardopts
DELETED
data/Gemfile
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gemspec
|
4
|
-
|
5
|
-
gem 'dry-types', git: 'https://github.com/dry-rb/dry-types', branch: 'master'
|
6
|
-
|
7
|
-
gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
|
8
|
-
gem 'rom-core'
|
9
|
-
gem 'rom-mapper'
|
10
|
-
gem 'rom-repository', group: :tools
|
11
|
-
end
|
12
|
-
|
13
|
-
group :test do
|
14
|
-
gem 'pry-byebug', platforms: :mri
|
15
|
-
gem 'pry', platforms: %i(jruby rbx)
|
16
|
-
gem 'dry-struct'
|
17
|
-
gem 'activesupport', '~> 5.0'
|
18
|
-
gem 'codeclimate-test-reporter', require: false
|
19
|
-
gem 'simplecov', require: false
|
20
|
-
|
21
|
-
if RUBY_ENGINE == 'rbx'
|
22
|
-
gem 'pg', '~> 0.18.0', platforms: :rbx
|
23
|
-
else
|
24
|
-
gem 'pg', '~> 0.19', platforms: :mri
|
25
|
-
end
|
26
|
-
|
27
|
-
gem 'mysql2', platforms: [:mri, :rbx]
|
28
|
-
gem 'jdbc-postgres', platforms: :jruby
|
29
|
-
gem 'jdbc-mysql', platforms: :jruby
|
30
|
-
gem 'sqlite3', platforms: [:mri, :rbx]
|
31
|
-
gem 'jdbc-sqlite3', platforms: :jruby
|
32
|
-
gem 'ruby-oci8', platforms: :mri if ENV['ROM_USE_ORACLE']
|
33
|
-
end
|
data/Guardfile
DELETED
@@ -1,24 +0,0 @@
|
|
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/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014-2017 Piotr Solnica
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require "rspec/core/rake_task"
|
3
|
-
|
4
|
-
RSpec::Core::RakeTask.new(:spec)
|
5
|
-
task default: [:ci]
|
6
|
-
|
7
|
-
desc "Run CI tasks"
|
8
|
-
task ci: [:spec]
|
9
|
-
|
10
|
-
begin
|
11
|
-
require "rubocop/rake_task"
|
12
|
-
|
13
|
-
Rake::Task[:default].enhance [:rubocop]
|
14
|
-
|
15
|
-
RuboCop::RakeTask.new do |task|
|
16
|
-
task.options << "--display-cop-names"
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
end
|
data/circle.yml
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module SQL
|
3
|
-
# Query API for SQL::Relation
|
4
|
-
#
|
5
|
-
# @api public
|
6
|
-
module SequelAPI
|
7
|
-
# Select specific columns for select clause
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# users.select(:id, :name).first
|
11
|
-
# # {:id => 1, :name => "Jane" }
|
12
|
-
#
|
13
|
-
# @return [Relation]
|
14
|
-
#
|
15
|
-
# @api public
|
16
|
-
def select(*args, &block)
|
17
|
-
new(dataset.__send__(__method__, *args, &block))
|
18
|
-
end
|
19
|
-
|
20
|
-
# Append specific columns to select clause
|
21
|
-
#
|
22
|
-
# @example
|
23
|
-
# users.select(:id, :name).select_append(:email)
|
24
|
-
# # {:id => 1, :name => "Jane", :email => "jane@doe.org"}
|
25
|
-
#
|
26
|
-
# @param [Array<Symbol>] *args A list with column names
|
27
|
-
#
|
28
|
-
# @return [Relation]
|
29
|
-
#
|
30
|
-
# @api public
|
31
|
-
def select_append(*args, &block)
|
32
|
-
new(dataset.__send__(__method__, *args, &block))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Restrict a relation to match criteria
|
36
|
-
#
|
37
|
-
# If block is passed it'll be executed in the context of a condition
|
38
|
-
# builder object.
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# users.where(name: 'Jane')
|
42
|
-
#
|
43
|
-
# users.where { age >= 18 }
|
44
|
-
#
|
45
|
-
# @param [Hash] *args An optional hash with conditions for WHERE clause
|
46
|
-
#
|
47
|
-
# @return [Relation]
|
48
|
-
#
|
49
|
-
# @see http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html
|
50
|
-
#
|
51
|
-
# @api public
|
52
|
-
def where(*args, &block)
|
53
|
-
new(dataset.__send__(__method__, *args, &block))
|
54
|
-
end
|
55
|
-
|
56
|
-
# Restrict a relation to match grouping criteria
|
57
|
-
#
|
58
|
-
# @example
|
59
|
-
# users.with_task_count.having( task_count: 2 )
|
60
|
-
#
|
61
|
-
# users.with_task_count.having { task_count > 3 }
|
62
|
-
#
|
63
|
-
# @param [Hash] *args An optional hash with conditions for HAVING clause
|
64
|
-
#
|
65
|
-
# @return [Relation]
|
66
|
-
#
|
67
|
-
# @see http://sequel.jeremyevans.net/rdoc/files/doc/dataset_filtering_rdoc.html
|
68
|
-
#
|
69
|
-
# @api public
|
70
|
-
def having(*args, &block)
|
71
|
-
new(dataset.__send__(__method__, *args, &block))
|
72
|
-
end
|
73
|
-
|
74
|
-
# Set order for the relation
|
75
|
-
#
|
76
|
-
# @example
|
77
|
-
# users.order(:name)
|
78
|
-
#
|
79
|
-
# @param [Array<Symbol>] *args A list with column names
|
80
|
-
#
|
81
|
-
# @return [Relation]
|
82
|
-
#
|
83
|
-
# @api public
|
84
|
-
def order(*args, &block)
|
85
|
-
new(dataset.__send__(__method__, *args, &block))
|
86
|
-
end
|
87
|
-
|
88
|
-
# Join with another relation using INNER JOIN
|
89
|
-
#
|
90
|
-
# @example
|
91
|
-
# users.inner_join(:tasks, id: :user_id)
|
92
|
-
#
|
93
|
-
# @param [Symbol] relation name
|
94
|
-
# @param [Hash] join keys
|
95
|
-
#
|
96
|
-
# @return [Relation]
|
97
|
-
#
|
98
|
-
# @api public
|
99
|
-
def inner_join(*args, &block)
|
100
|
-
new(dataset.__send__(__method__, *args, &block))
|
101
|
-
end
|
102
|
-
|
103
|
-
# Join other relation using LEFT OUTER JOIN
|
104
|
-
#
|
105
|
-
# @example
|
106
|
-
# users.left_join(:tasks, id: :user_id)
|
107
|
-
#
|
108
|
-
# @param [Symbol] relation name
|
109
|
-
# @param [Hash] join keys
|
110
|
-
#
|
111
|
-
# @return [Relation]
|
112
|
-
#
|
113
|
-
# @api public
|
114
|
-
def left_join(*args, &block)
|
115
|
-
new(dataset.__send__(__method__, *args, &block))
|
116
|
-
end
|
117
|
-
|
118
|
-
# Group by specific columns
|
119
|
-
#
|
120
|
-
# @example
|
121
|
-
# tasks.group(:user_id)
|
122
|
-
#
|
123
|
-
# @param [Array<Symbol>] *args A list of column names
|
124
|
-
#
|
125
|
-
# @return [Relation]
|
126
|
-
#
|
127
|
-
# @api public
|
128
|
-
def group(*args, &block)
|
129
|
-
new(dataset.__send__(__method__, *args, &block))
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/log/.gitkeep
DELETED
File without changes
|
data/rom-sql.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'rom/sql/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'rom-sql'
|
7
|
-
spec.version = ROM::SQL::VERSION.dup
|
8
|
-
spec.authors = ['Piotr Solnica']
|
9
|
-
spec.email = ['piotr.solnica@gmail.com']
|
10
|
-
spec.summary = 'SQL databases support for ROM'
|
11
|
-
spec.description = spec.summary
|
12
|
-
spec.homepage = 'http://rom-rb.org'
|
13
|
-
spec.license = 'MIT'
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = ['lib']
|
19
|
-
|
20
|
-
spec.add_runtime_dependency 'sequel', '~> 4.43'
|
21
|
-
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
22
|
-
spec.add_runtime_dependency 'dry-types', '~> 0.11'
|
23
|
-
spec.add_runtime_dependency 'dry-core', '~> 0.3'
|
24
|
-
spec.add_runtime_dependency 'rom-core', '~> 4.0.0.beta'
|
25
|
-
|
26
|
-
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
-
spec.add_development_dependency 'rspec', '~> 3.5'
|
29
|
-
end
|
@@ -1,217 +0,0 @@
|
|
1
|
-
RSpec.describe 'ROM::SQL::Attribute', :postgres do
|
2
|
-
include_context 'database setup'
|
3
|
-
|
4
|
-
before do
|
5
|
-
conn.drop_table?(:pg_people)
|
6
|
-
conn.drop_table?(:people)
|
7
|
-
|
8
|
-
conf.relation(:people) do
|
9
|
-
schema(:pg_people, infer: true)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:people) { relations[:people] }
|
14
|
-
let(:create_person) { commands[:people].create }
|
15
|
-
|
16
|
-
%i(json jsonb).each do |type|
|
17
|
-
if type == :json
|
18
|
-
json_hash = Sequel::Postgres::JSONHash.method(:new)
|
19
|
-
json_array = Sequel::Postgres::JSONArray.method(:new)
|
20
|
-
else
|
21
|
-
json_hash = Sequel::Postgres::JSONBHash.method(:new)
|
22
|
-
json_array = Sequel::Postgres::JSONBArray.method(:new)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "using arrays in #{ type }" do
|
26
|
-
before do
|
27
|
-
conn.create_table :pg_people do
|
28
|
-
primary_key :id
|
29
|
-
String :name
|
30
|
-
column :fields, type
|
31
|
-
end
|
32
|
-
|
33
|
-
conf.commands(:people) do
|
34
|
-
define(:create)
|
35
|
-
define(:update)
|
36
|
-
end
|
37
|
-
|
38
|
-
create_person.(name: 'John Doe', fields: [{ name: 'age', value: '30' },
|
39
|
-
{ name: 'height', value: 180 }])
|
40
|
-
create_person.(name: 'Jade Doe', fields: [{ name: 'age', value: '25' }])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'fetches data from jsonb array by index' do
|
44
|
-
expect(people.select { [fields.get(1).as(:field)] }.where(name: 'John Doe').one).
|
45
|
-
to eql(field: json_hash['name' => 'height', 'value' => 180])
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'fetches data from jsonb array' do
|
49
|
-
expect(people.select { fields.get(1).get_text('value').as(:height) }.where(name: 'John Doe').one).
|
50
|
-
to eql(height: '180')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'fetches data with path' do
|
54
|
-
expect(people.select(people[:fields].get_text('1', 'value').as(:height)).to_a).
|
55
|
-
to eql([{ height: '180' }, { height: nil }])
|
56
|
-
end
|
57
|
-
|
58
|
-
if type == :jsonb
|
59
|
-
it 'allows to query jsonb by inclusion' do
|
60
|
-
expect(people.select(:name).where { fields.contain([value: '30']) }.one).
|
61
|
-
to eql(name: 'John Doe')
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'cat project result of contains' do
|
65
|
-
expect(people.select { fields.contain([value: '30']).as(:contains) }.to_a).
|
66
|
-
to eql([{ contains: true }, { contains: false }])
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'deletes key from result' do
|
70
|
-
expect(people.select { fields.delete(0).as(:result) }.limit(1).one).
|
71
|
-
to eq(result: json_array[['name' => 'height', 'value' => 180]])
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'deletes by path' do
|
75
|
-
expect(people.select { fields.delete('0', 'name').delete('1', 'name').as(:result) }.limit(1).one).
|
76
|
-
to eq(result: json_array[[{ 'value' => '30' }, { 'value' => 180 }]])
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'concatenates JSON values' do
|
80
|
-
expect(people.select { (fields + [name: 'height', value: 165]).as(:result) }.by_pk(2).one).
|
81
|
-
to eq(result: json_array[[{ 'name' => 'age', 'value' => '25' },
|
82
|
-
{ 'name' => 'height', 'value' => 165 }]])
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
if type == :jsonb
|
88
|
-
describe "using maps in #{ type }" do
|
89
|
-
before do
|
90
|
-
conn.create_table :pg_people do
|
91
|
-
primary_key :id
|
92
|
-
String :name
|
93
|
-
column :data, type
|
94
|
-
end
|
95
|
-
|
96
|
-
conf.commands(:people) do
|
97
|
-
define(:create)
|
98
|
-
define(:update)
|
99
|
-
end
|
100
|
-
|
101
|
-
create_person.(name: 'John Doe', data: { age: 30, height: 180 })
|
102
|
-
create_person.(name: 'Jade Doe', data: { age: 25 })
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'queries data by inclusion' do
|
106
|
-
expect(people.select(:name).where { data.contain(age: 30) }.one).
|
107
|
-
to eql(name: 'John Doe')
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'queries data by left inclusion' do
|
111
|
-
expect(people.select(:name).where { data.contained_by(age: 25, foo: 'bar') }.one).
|
112
|
-
to eql(name: 'Jade Doe')
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'checks for key presence' do
|
116
|
-
expect(people.select { data.has_key('height').as(:there) }.to_a).
|
117
|
-
to eql([{ there: true }, { there: false }])
|
118
|
-
|
119
|
-
expect(people.select(:name).where { data.has_any_key('height', 'width') }.one).
|
120
|
-
to eql(name: 'John Doe')
|
121
|
-
|
122
|
-
expect(people.select(:name).where { data.has_all_keys('height', 'age') }.one).
|
123
|
-
to eql(name: 'John Doe')
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'concatenates JSON values' do
|
127
|
-
expect(people.select { data.merge(height: 165).as(:result) }.by_pk(2).one).
|
128
|
-
to eql(result: json_hash['age' => 25, 'height' => 165])
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'deletes key from result' do
|
132
|
-
expect(people.select { data.delete('height').as(:result) }.to_a).
|
133
|
-
to eql([{ result: json_hash['age' => 30] },
|
134
|
-
{ result: json_hash['age' => 25] }])
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe 'using array types' do
|
141
|
-
before do
|
142
|
-
conn.create_table :pg_people do
|
143
|
-
primary_key :id
|
144
|
-
String :name
|
145
|
-
column :emails, 'text[]'
|
146
|
-
column :bigids, 'bigint[]'
|
147
|
-
end
|
148
|
-
|
149
|
-
conf.commands(:people) do
|
150
|
-
define(:create)
|
151
|
-
define(:update)
|
152
|
-
end
|
153
|
-
|
154
|
-
create_person.(name: 'John Doe', emails: %w(john@doe.com john@example.com), bigids: [84])
|
155
|
-
create_person.(name: 'Jade Doe', emails: %w(jade@hotmail.com), bigids: [42])
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'filters by email inclusion' do
|
159
|
-
expect(people.select(:name).where { emails.contain(['john@doe.com']) }.one).
|
160
|
-
to eql(name: 'John Doe')
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'coerces values so that PG does not complain' do
|
164
|
-
expect(people.select(:name).where { bigids.contain([84]) }.one).
|
165
|
-
to eql(name: 'John Doe')
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'fetches element by index' do
|
169
|
-
expect(people.select { [name, emails.get(2).as(:second_email)] }.to_a).
|
170
|
-
to eql([{ name: 'John Doe', second_email: 'john@example.com' },
|
171
|
-
{ name: 'Jade Doe', second_email: nil }])
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'restricts with ANY' do
|
175
|
-
expect(people.select(:name).where { bigids.any(84)}.one).
|
176
|
-
to eql(name: 'John Doe')
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'restricts by <@' do
|
180
|
-
expect(people.select(:name).where { bigids.contained_by((30..50).to_a) }.one).
|
181
|
-
to eql(name: 'Jade Doe')
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'returns array length' do
|
185
|
-
expect(people.select { [name, emails.length.as(:size)] }.to_a).
|
186
|
-
to eql([{ name: 'John Doe', size: 2 }, { name: 'Jade Doe', size: 1 }])
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'restrict by overlapping with other array' do
|
190
|
-
expect(people.select(:name).where { emails.overlaps(%w(jade@hotmail.com)) }.one).
|
191
|
-
to eql(name: 'Jade Doe')
|
192
|
-
|
193
|
-
expect(people.select(:name).where { bigids.overlaps([42]) }.one).
|
194
|
-
to eql(name: 'Jade Doe')
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'removes element by value' do
|
198
|
-
expect(people.select { emails.remove_value('john@example.com').as(:emails) }.to_a).
|
199
|
-
to eq([{ emails: %w(john@doe.com) }, { emails: %w(jade@hotmail.com) }])
|
200
|
-
|
201
|
-
pending "doesn't have auto-casting yet"
|
202
|
-
expect(people.select(:name).where { bigids.remove_value(100).contains([42]) }.one).
|
203
|
-
to eql(name: 'Jade Doe')
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'joins values' do
|
207
|
-
expect(people.select { emails.join(',').as(:emails) }.to_a).
|
208
|
-
to eql([{ emails: 'john@doe.com,john@example.com' },
|
209
|
-
{ emails: 'jade@hotmail.com' }])
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'concatenates arrays' do
|
213
|
-
expect(people.select { (emails + %w(foo@bar.com)).as(:emails) }.where { name.is('Jade Doe') }.one).
|
214
|
-
to eq(emails: %w(jade@hotmail.com foo@bar.com))
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|