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
@@ -1,33 +0,0 @@
|
|
1
|
-
module Sequel
|
2
|
-
class Dataset
|
3
|
-
def header
|
4
|
-
ROM::SQL::Header.new(opts.fetch(:select) { columns }, opts[:from].first)
|
5
|
-
end
|
6
|
-
|
7
|
-
def project(*names)
|
8
|
-
select(*header.project(*names))
|
9
|
-
end
|
10
|
-
|
11
|
-
def rename(options)
|
12
|
-
select(*header.rename(options))
|
13
|
-
end
|
14
|
-
|
15
|
-
def prefix(col_prefix = default_prefix)
|
16
|
-
rename(header.prefix(col_prefix).to_h)
|
17
|
-
end
|
18
|
-
|
19
|
-
def qualified
|
20
|
-
select(*qualified_columns)
|
21
|
-
end
|
22
|
-
|
23
|
-
def qualified_columns
|
24
|
-
header.qualified.to_a
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def default_prefix
|
30
|
-
Inflecto.singularize(opts[:from].first)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/spec/unit/adapter_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
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 'setting up' do
|
10
|
-
it 'works with database.yml-style hash' do
|
11
|
-
setup = ROM.setup(adapter: 'postgres', database: 'rom')
|
12
|
-
expect(setup[:default]).to eql(setup.repositories[:default])
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'accepts additional options' do
|
16
|
-
test = false
|
17
|
-
|
18
|
-
setup = ROM.setup(
|
19
|
-
adapter: 'postgres',
|
20
|
-
database: 'rom',
|
21
|
-
test: true,
|
22
|
-
after_connect: proc { test = true }
|
23
|
-
)
|
24
|
-
|
25
|
-
setup.finalize
|
26
|
-
|
27
|
-
expect(test).to be(true)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#dataset?' do
|
32
|
-
it 'returns true if a table exists' do
|
33
|
-
expect(adapter.dataset?(:users)).to be(true)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'returns false if a table does not exist' do
|
37
|
-
expect(adapter.dataset?(:not_here)).to be(false)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#disconnect' do
|
42
|
-
it 'disconnects via sequel connection' do
|
43
|
-
# FIXME: no idea how to test it in a different way
|
44
|
-
expect(adapter.connection).to receive(:disconnect)
|
45
|
-
adapter.disconnect
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/unit/config_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ROM::Config do
|
4
|
-
let(:root) { '/somewhere' }
|
5
|
-
|
6
|
-
describe '.build' do
|
7
|
-
it 'rewrites database config hash to a URI for sqlite' do
|
8
|
-
db_config = { adapter: 'sqlite', database: 'testing.sqlite', root: root }
|
9
|
-
|
10
|
-
config = ROM::Config.build(db_config)
|
11
|
-
|
12
|
-
if RUBY_ENGINE == 'jruby'
|
13
|
-
expect(config)
|
14
|
-
.to eql(default: "jdbc:sqlite:///somewhere/testing.sqlite")
|
15
|
-
else
|
16
|
-
expect(config).to eql(default: "sqlite:///somewhere/testing.sqlite")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'rewrites database config hash to a URI for mysql' do
|
21
|
-
db_config = {
|
22
|
-
adapter: 'mysql',
|
23
|
-
database: 'testing',
|
24
|
-
username: 'piotr',
|
25
|
-
hostname: 'localhost',
|
26
|
-
password: 'secret',
|
27
|
-
root: '/foo'
|
28
|
-
}
|
29
|
-
|
30
|
-
config = ROM::Config.build(db_config)
|
31
|
-
|
32
|
-
if RUBY_ENGINE == 'jruby'
|
33
|
-
expect(config)
|
34
|
-
.to eql(default: "jdbc:mysql://piotr:secret@localhost/testing")
|
35
|
-
else
|
36
|
-
expect(config)
|
37
|
-
.to eql(default: "mysql://piotr:secret@localhost/testing")
|
38
|
-
end
|
39
|
-
|
40
|
-
db_config = {
|
41
|
-
adapter: 'mysql',
|
42
|
-
database: 'testing'
|
43
|
-
}
|
44
|
-
|
45
|
-
config = ROM::Config.build(db_config)
|
46
|
-
|
47
|
-
if RUBY_ENGINE == 'jruby'
|
48
|
-
expect(config).to eql(default: "jdbc:mysql://localhost/testing")
|
49
|
-
else
|
50
|
-
expect(config).to eql(default: "mysql://localhost/testing")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|