alf-sequel 0.14.0 → 0.15.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.
- data/Gemfile +10 -7
- data/Gemfile.lock +26 -14
- data/README.md +45 -3
- data/lib/alf/sequel.rb +1 -0
- data/lib/alf/sequel/cog.rb +23 -75
- data/lib/alf/sequel/compiler.rb +8 -198
- data/lib/alf/sequel/connection.rb +5 -1
- data/lib/alf/sequel/connection/connection_methods.rb +4 -2
- data/lib/alf/sequel/connection/schema_methods.rb +2 -6
- data/lib/alf/sequel/connection/update_methods.rb +1 -1
- data/lib/alf/sequel/loader.rb +1 -0
- data/lib/alf/sequel/translator.rb +198 -0
- data/lib/alf/sequel/unit_of_work/insert.rb +10 -4
- data/lib/alf/sequel/unit_of_work/update.rb +3 -3
- data/lib/alf/sequel/version.rb +1 -1
- data/spec/connection/test_heading.rb +1 -1
- data/spec/{fixtures/sap.db → sap.db} +0 -0
- data/spec/spec_helper.rb +48 -6
- data/spec/unit_of_work/delete/test_delete.rb +2 -2
- data/spec/unit_of_work/insert/test_run.rb +12 -14
- data/spec/unit_of_work/update/test_run.rb +1 -1
- data/tasks/bench.rake +40 -0
- data/tasks/test.rake +3 -3
- metadata +29 -29
- data/lib/alf/sequel/compiler/predicate.rb +0 -76
- data/spec/alf.db +0 -0
- data/spec/compiler/test_clip.rb +0 -40
- data/spec/compiler/test_compact.rb +0 -18
- data/spec/compiler/test_extend.rb +0 -16
- data/spec/compiler/test_frame.rb +0 -89
- data/spec/compiler/test_intersect.rb +0 -18
- data/spec/compiler/test_join.rb +0 -26
- data/spec/compiler/test_leaf_operand.rb +0 -24
- data/spec/compiler/test_matching.rb +0 -34
- data/spec/compiler/test_not_matching.rb +0 -34
- data/spec/compiler/test_page.rb +0 -86
- data/spec/compiler/test_predicate.rb +0 -141
- data/spec/compiler/test_project.rb +0 -64
- data/spec/compiler/test_rename.rb +0 -26
- data/spec/compiler/test_restrict.rb +0 -48
- data/spec/compiler/test_sort.rb +0 -18
- data/spec/compiler/test_union.rb +0 -18
- data/spec/compiler_helper.rb +0 -34
- data/spec/fixtures/sap.rb +0 -43
- data/tasks/fixtures.rake +0 -12
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "restrict" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'with a native predicate' do
|
9
|
-
let(:expr){ restrict(suppliers, proc{ status > 20 }) }
|
10
|
-
|
11
|
-
it{ should be_a(Engine::Filter) }
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when the operand is fully compilable' do
|
15
|
-
let(:expr){ restrict(suppliers, :name => "Jones") }
|
16
|
-
|
17
|
-
specify{
|
18
|
-
subject.sql.should eq("SELECT * FROM `suppliers` AS 't1' WHERE (`t1`.`name` = 'Jones')")
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when the operand is a IN (values)' do
|
23
|
-
let(:expr){ restrict(suppliers, Predicate.in(:city, ["London", "Paris"])) }
|
24
|
-
|
25
|
-
specify{
|
26
|
-
subject.sql.should eq("SELECT * FROM `suppliers` AS 't1' WHERE (`t1`.`city` IN ('London', 'Paris'))")
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when the operand is a NOT IN (values)' do
|
31
|
-
let(:expr){ restrict(suppliers, !Predicate.in(:city, ["London", "Paris"])) }
|
32
|
-
|
33
|
-
specify{
|
34
|
-
subject.sql.should eq("SELECT * FROM `suppliers` AS 't1' WHERE (`t1`.`city` NOT IN ('London', 'Paris'))")
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when the operand is a renaming' do
|
39
|
-
let(:expr){ restrict(rename(suppliers, :name => :sname), :sname => "Jones") }
|
40
|
-
|
41
|
-
specify{
|
42
|
-
subject.sql.should eq("SELECT * FROM (SELECT `t1`.`name` AS 'sname', `t1`.`sid` AS 'sid', `t1`.`status` AS 'status', `t1`.`city` AS 'city' FROM `suppliers` AS 't1') AS 't2' WHERE (`t2`.`sname` = 'Jones')")
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/compiler/test_sort.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "sort" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'when the operand is fully compilable' do
|
9
|
-
let(:expr){ sort(suppliers, [ [:name, :asc], [:status, :desc] ]) }
|
10
|
-
|
11
|
-
specify{
|
12
|
-
subject.sql.should eq("SELECT * FROM `suppliers` AS 't1' ORDER BY `t1`.`name` ASC, `t1`.`status` DESC")
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/compiler/test_union.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'compiler_helper'
|
2
|
-
module Alf
|
3
|
-
module Sequel
|
4
|
-
describe Compiler, "union" do
|
5
|
-
|
6
|
-
subject{ compile(expr) }
|
7
|
-
|
8
|
-
context 'when the operand is fully compilable' do
|
9
|
-
let(:expr){ union(suppliers, supplies) }
|
10
|
-
|
11
|
-
specify do
|
12
|
-
subject.sql.should eq("SELECT * FROM (SELECT * FROM `suppliers` AS 't1' UNION SELECT * FROM `supplies` AS 't2') AS 't3'")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/compiler_helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
|
3
|
-
module CompilerHelpers
|
4
|
-
include Alf::Lang::Functional
|
5
|
-
|
6
|
-
def suppliers
|
7
|
-
Alf::Algebra.named_operand(:suppliers, sap)
|
8
|
-
end
|
9
|
-
|
10
|
-
def supplies
|
11
|
-
Alf::Algebra.named_operand(:supplies, sap)
|
12
|
-
end
|
13
|
-
|
14
|
-
def parts
|
15
|
-
Alf::Algebra.named_operand(:parts, sap)
|
16
|
-
end
|
17
|
-
|
18
|
-
def _context
|
19
|
-
sap
|
20
|
-
end
|
21
|
-
|
22
|
-
def an_operand
|
23
|
-
Alf::Algebra::Operand::Fake.new(sap)
|
24
|
-
end
|
25
|
-
|
26
|
-
def compile(expr)
|
27
|
-
Alf::Sequel::Compiler.new.call(expr)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
RSpec.configure do |c|
|
33
|
-
c.include CompilerHelpers
|
34
|
-
end
|
data/spec/fixtures/sap.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
class SAP
|
2
|
-
|
3
|
-
def self.create!(sequel_db)
|
4
|
-
sequel_db = ::Sequel.connect(sequel_db) unless sequel_db.is_a?(::Sequel::Database)
|
5
|
-
sequel_db.tap do |db|
|
6
|
-
db.create_table(:suppliers) do
|
7
|
-
primary_key :sid
|
8
|
-
String :name
|
9
|
-
Integer :status
|
10
|
-
String :city
|
11
|
-
index :name, :unique => true
|
12
|
-
end
|
13
|
-
db.create_table(:parts) do
|
14
|
-
primary_key :pid
|
15
|
-
String :name
|
16
|
-
String :color
|
17
|
-
Float :weight
|
18
|
-
String :city
|
19
|
-
end
|
20
|
-
db.create_table(:supplies) do
|
21
|
-
Integer :sid
|
22
|
-
Integer :pid
|
23
|
-
Integer :qty
|
24
|
-
primary_key [:sid, :pid]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
Alf.connect(sequel_db) do |alf_db|
|
28
|
-
ex = Alf.examples
|
29
|
-
alf_db.relvar(:suppliers).affect ex.query{
|
30
|
-
(extend suppliers, :sid => lambda{ (sid.match /\d+/)[0].to_i })
|
31
|
-
}
|
32
|
-
alf_db.relvar(:parts).affect ex.query{
|
33
|
-
(extend parts, :pid => lambda{ (pid.match /\d+/)[0].to_i })
|
34
|
-
}
|
35
|
-
alf_db.relvar(:supplies).affect ex.query{
|
36
|
-
(extend supplies, :sid => lambda{ (sid.match /\d+/)[0].to_i },
|
37
|
-
:pid => lambda{ (pid.match /\d+/)[0].to_i })
|
38
|
-
}
|
39
|
-
end
|
40
|
-
sequel_db
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/tasks/fixtures.rake
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
task :fixtures do
|
2
|
-
require 'path'
|
3
|
-
require "sequel"
|
4
|
-
require 'alf-sequel'
|
5
|
-
require_relative '../spec/fixtures/sap'
|
6
|
-
|
7
|
-
path = Path.relative("../spec/fixtures/sap.db")
|
8
|
-
path.unlink if path.exist?
|
9
|
-
path.parent.mkdir_p unless path.parent.exist?
|
10
|
-
|
11
|
-
SAP.create! Alf::Sequel::Adapter.sequel_db(path)
|
12
|
-
end
|