arel_extensions 1.4.2 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +21 -21
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -10
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -27
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -42
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +29 -59
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +191 -422
- data/lib/arel_extensions/visitors/mysql.rb +212 -350
- data/lib/arel_extensions/visitors/oracle.rb +178 -220
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -256
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -298
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -224
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -711
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +34 -43
- data/.github/workflows/publish.yml +0 -29
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -399
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -89
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -33
- data/gemfiles/rails6_1.gemfile +0 -33
- data/gemfiles/rails7.gemfile +0 -33
- data/gemfiles/rails7_1.gemfile +0 -33
- data/gemfiles/rails7_2.gemfile +0 -33
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -74
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,23 +1,20 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
|
-
module
|
5
|
+
module WthAr
|
6
|
+
|
6
7
|
class InsertManagerTest < Minitest::Test
|
7
|
-
def
|
8
|
+
def setup_db
|
8
9
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
9
|
-
if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
10
|
-
@env_db = (RUBY_PLATFORM == 'java' ?
|
11
|
-
skip "Platform not supported
|
10
|
+
if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
|
11
|
+
@env_db = (RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
|
12
|
+
skip "Platform not supported"
|
12
13
|
else
|
13
14
|
@env_db = ENV['DB']
|
14
15
|
end
|
15
16
|
ActiveRecord::Base.establish_connection(@env_db.try(:to_sym) || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
16
|
-
|
17
|
-
ActiveRecord.default_timezone = :utc
|
18
|
-
else
|
19
|
-
ActiveRecord::Base.default_timezone = :utc
|
20
|
-
end
|
17
|
+
ActiveRecord::Base.default_timezone = :utc
|
21
18
|
@cnx = ActiveRecord::Base.connection
|
22
19
|
Arel::Table.engine = ActiveRecord::Base
|
23
20
|
if File.exist?("init/#{@env_db}.sql")
|
@@ -26,17 +23,14 @@ module ArelExtensions
|
|
26
23
|
@cnx.execute(sql) rescue $stderr << "can't create functions\n"
|
27
24
|
end
|
28
25
|
end
|
29
|
-
|
30
|
-
|
31
|
-
def setup_db
|
32
|
-
@cnx.drop_table(:user_tests) rescue nil
|
26
|
+
@cnx.drop_table(:user_tests) rescue nil
|
33
27
|
@cnx.create_table :user_tests do |t|
|
34
28
|
t.column :age, :integer
|
35
29
|
t.column :name, :string
|
36
30
|
t.column :comments, :text
|
37
31
|
t.column :created_at, :date
|
38
32
|
t.column :updated_at, :datetime
|
39
|
-
t.column :score, :decimal, precision
|
33
|
+
t.column :score, :decimal, :precision => 20, :scale => 10
|
40
34
|
end
|
41
35
|
if @env_db == 'oracle'
|
42
36
|
@cnx.execute(%q[CREATE OR REPLACE trigger user_tests_trg
|
@@ -55,18 +49,17 @@ END;])
|
|
55
49
|
end
|
56
50
|
|
57
51
|
def setup
|
58
|
-
connect_db
|
59
52
|
setup_db
|
60
53
|
@table = Arel::Table.new(:user_tests)
|
61
|
-
@cols =
|
54
|
+
@cols = ['id', 'name', 'comments', 'created_at']
|
62
55
|
@data = [
|
63
|
-
[23, 'nom1',
|
64
|
-
[25, 'nom2',
|
56
|
+
[23, 'nom1', "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.", '2016-01-01'],
|
57
|
+
[25, 'nom2', "sdfdsfdsfsdf", '2016-01-02']
|
65
58
|
]
|
66
|
-
@cols2 =
|
59
|
+
@cols2 = ['name', 'comments', 'created_at']
|
67
60
|
@data2 = [
|
68
|
-
['nom3',
|
69
|
-
|
61
|
+
['nom3', "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.", '2016-01-01'],
|
62
|
+
['nom4', "sdfdsfdsfsdf", '2016-01-04']
|
70
63
|
]
|
71
64
|
end
|
72
65
|
|
@@ -76,15 +69,16 @@ END;])
|
|
76
69
|
|
77
70
|
# Math Functions
|
78
71
|
def test_bulk_insert
|
79
|
-
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
|
72
|
+
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
|
80
73
|
insert_manager.bulk_insert(@cols, @data)
|
81
74
|
@cnx.execute(insert_manager.to_sql)
|
82
|
-
assert_equal 2, User.count,
|
83
|
-
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
|
75
|
+
assert_equal 2, User.count, "insertions failed"
|
76
|
+
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
|
84
77
|
insert_manager.bulk_insert(@cols2, @data2)
|
85
78
|
@cnx.execute(insert_manager.to_sql)
|
86
|
-
assert_equal 4, User.count,
|
79
|
+
assert_equal 4, User.count, "insertions failed"
|
87
80
|
end
|
81
|
+
|
88
82
|
end
|
89
83
|
end
|
90
84
|
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
|
-
module
|
4
|
+
module WthAr
|
5
|
+
|
5
6
|
describe 'the sqlite visitor' do
|
7
|
+
|
6
8
|
before do
|
7
9
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
8
10
|
ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
9
|
-
|
10
|
-
ActiveRecord.default_timezone = :utc
|
11
|
-
else
|
12
|
-
ActiveRecord::Base.default_timezone = :utc
|
13
|
-
end
|
11
|
+
ActiveRecord::Base.default_timezone = :utc
|
14
12
|
@cnx = ActiveRecord::Base.connection
|
15
13
|
Arel::Table.engine = ActiveRecord::Base
|
16
14
|
@cnx.drop_table(:users) rescue nil
|
17
|
-
@cnx.drop_table(:products) rescue nil
|
15
|
+
@cnx.drop_table(:products) rescue nil
|
18
16
|
@cnx.create_table :users do |t|
|
19
17
|
t.column :age, :integer
|
20
18
|
t.column :name, :string
|
@@ -27,23 +25,24 @@ module ArelExtensions
|
|
27
25
|
t.column :price, :decimal
|
28
26
|
end
|
29
27
|
@table = Arel::Table.new(:users)
|
30
|
-
@cols =
|
28
|
+
@cols = ['id', 'name', 'comments', 'created_at']
|
31
29
|
@data = [
|
32
|
-
[23, 'nom1',
|
33
|
-
[25, 'nom2',
|
30
|
+
[23, 'nom1', "sdfdsfdsfsdf", '2016-01-01'],
|
31
|
+
[25, 'nom2', "sdfdsfdsfsdf", '2016-01-01']
|
34
32
|
]
|
35
33
|
end
|
36
34
|
after do
|
37
35
|
@cnx.drop_table(:users)
|
38
36
|
end
|
39
37
|
|
40
|
-
it
|
41
|
-
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
|
38
|
+
it "should import large set of data" do
|
39
|
+
insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
|
42
40
|
insert_manager.bulk_insert(@cols, @data)
|
43
|
-
|
44
|
-
|
45
|
-
SELECT 23 AS 'id', 'nom1' AS 'name', 'sdfdsfdsfsdf' AS 'comments', '2016-01-01' AS 'created_at' UNION ALL SELECT 25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
|
41
|
+
sql = insert_manager.to_sql
|
42
|
+
sql.must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at") SELECT 23 AS 'id', 'nom1' AS 'name', 'sdfdsfdsfsdf' AS 'comments', '2016-01-01' AS 'created_at' UNION ALL SELECT 25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
|
46
43
|
end
|
44
|
+
|
47
45
|
end
|
46
|
+
|
48
47
|
end
|
49
|
-
end
|
48
|
+
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
|
-
module
|
4
|
+
module WthAr
|
5
|
+
|
5
6
|
describe 'the sqlite visitor can do maths' do
|
7
|
+
|
6
8
|
before do
|
7
9
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
8
10
|
ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
9
|
-
|
10
|
-
ActiveRecord.default_timezone = :utc
|
11
|
-
else
|
12
|
-
ActiveRecord::Base.default_timezone = :utc
|
13
|
-
end
|
11
|
+
ActiveRecord::Base.default_timezone = :utc
|
14
12
|
Arel::Table.engine = ActiveRecord::Base
|
15
13
|
@cnx = ActiveRecord::Base.connection
|
16
|
-
@cnx.drop_table(:users) rescue nil
|
17
|
-
@cnx.drop_table(:products) rescue nil
|
14
|
+
@cnx.drop_table(:users) rescue nil
|
15
|
+
@cnx.drop_table(:products) rescue nil
|
18
16
|
@cnx.create_table :users do |t|
|
19
17
|
t.column :age, :integer
|
20
18
|
t.column :name, :string
|
@@ -28,15 +26,15 @@ module ArelExtensions
|
|
28
26
|
end
|
29
27
|
class User < ActiveRecord::Base
|
30
28
|
end
|
31
|
-
d = Date.new(2016, 5,
|
32
|
-
User.create age
|
33
|
-
User.create age
|
34
|
-
User.create age
|
35
|
-
User.create age
|
36
|
-
User.create age
|
37
|
-
@laure = User.create age
|
38
|
-
User.create age
|
39
|
-
@neg = User.create age
|
29
|
+
d = Date.new(2016, 5,23)
|
30
|
+
User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
|
31
|
+
User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
|
32
|
+
User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
|
33
|
+
User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
|
34
|
+
User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
|
35
|
+
@laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
|
36
|
+
User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62
|
37
|
+
@neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
|
40
38
|
@table = Arel::Table.new(:users)
|
41
39
|
@age = @table[:age]
|
42
40
|
end
|
@@ -45,20 +43,22 @@ module ArelExtensions
|
|
45
43
|
@cnx.drop_table(:products)
|
46
44
|
end
|
47
45
|
|
48
|
-
it
|
49
|
-
#
|
50
|
-
assert_equal 20, User.where(id
|
51
|
-
assert_equal 14, User.where(id
|
46
|
+
it "should do maths" do
|
47
|
+
#ABS
|
48
|
+
assert_equal 20, User.where(:id => @neg.id).select(@age.abs.as("res")).first.res
|
49
|
+
assert_equal 14, User.where(:id => @laure.id).select((@age - 39).abs.as("res")).first.res
|
52
50
|
|
53
|
-
#
|
51
|
+
#CEIL # require extensions
|
54
52
|
|
55
53
|
# RAND
|
56
|
-
|
57
|
-
|
54
|
+
# puts User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).to_sql if User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count == 0
|
55
|
+
# assert_equal 5, User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count
|
58
56
|
assert 42 != User.select(Arel.rand.as('res')).first.res
|
59
57
|
assert 0 <= User.select(Arel.rand.abs.as('res')).first.res
|
60
58
|
assert_equal 8, User.order(Arel.rand).limit(50).count
|
61
59
|
end
|
60
|
+
|
62
61
|
end
|
62
|
+
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
@@ -1,18 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
|
-
module
|
5
|
+
module WthAr
|
6
|
+
|
6
7
|
describe 'the mysql visitor can do string operations' do
|
8
|
+
|
7
9
|
before do
|
8
10
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
9
11
|
ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-mysql" : :mysql))
|
10
|
-
|
11
|
-
|
12
|
-
else
|
13
|
-
ActiveRecord::Base.default_timezone = :utc
|
14
|
-
end
|
15
|
-
begin
|
12
|
+
ActiveRecord::Base.default_timezone = :utc
|
13
|
+
begin
|
16
14
|
@cnx = ActiveRecord::Base.connection
|
17
15
|
rescue => e
|
18
16
|
puts "\n#{e.inspect}"
|
@@ -21,7 +19,7 @@ module ArelExtensions
|
|
21
19
|
end
|
22
20
|
Arel::Table.engine = ActiveRecord::Base
|
23
21
|
@cnx.drop_table(:users) rescue nil
|
24
|
-
@cnx.drop_table(:products) rescue nil
|
22
|
+
@cnx.drop_table(:products) rescue nil
|
25
23
|
@cnx.create_table :users do |t|
|
26
24
|
t.column :age, :integer
|
27
25
|
t.column :name, :string
|
@@ -35,16 +33,16 @@ module ArelExtensions
|
|
35
33
|
end
|
36
34
|
class User < ActiveRecord::Base
|
37
35
|
end
|
38
|
-
d = Date.new(2016, 5,
|
39
|
-
@lucas = User.create age
|
40
|
-
sophie = User.create age
|
41
|
-
@sophie = User.where(id
|
42
|
-
User.create age
|
43
|
-
User.create age
|
44
|
-
User.create age
|
45
|
-
@laure = User.create age
|
46
|
-
User.create age
|
47
|
-
@neg = User.create age
|
36
|
+
d = Date.new(2016, 5,23)
|
37
|
+
@lucas = User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
|
38
|
+
sophie = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
|
39
|
+
@sophie = User.where(:id => sophie.id)
|
40
|
+
User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
|
41
|
+
User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
|
42
|
+
User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
|
43
|
+
@laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
|
44
|
+
User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62
|
45
|
+
@neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
|
48
46
|
@table = Arel::Table.new(:users)
|
49
47
|
@name = @table[:name]
|
50
48
|
end
|
@@ -52,24 +50,28 @@ module ArelExtensions
|
|
52
50
|
@cnx.drop_table(:users)
|
53
51
|
end
|
54
52
|
|
55
|
-
it
|
53
|
+
it "should do string operations" do
|
56
54
|
# concat
|
57
55
|
d = Date.new(1997, 6, 15)
|
58
|
-
assert_equal
|
59
|
-
assert_equal
|
60
|
-
assert_equal
|
61
|
-
assert_equal
|
62
|
-
assert_equal
|
63
|
-
assert_equal
|
64
|
-
#
|
56
|
+
assert_equal "SophiePhan", @sophie.select((@name + "Phan").as("res")).first.res
|
57
|
+
assert_equal "Sophie2", @sophie.select((@name + 2).as("res")).first.res
|
58
|
+
assert_equal "Sophie1997-06-15", @sophie.select((@name + d).as("res")).first.res
|
59
|
+
assert_equal "Sophie15", @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
|
60
|
+
assert_equal "SophieSophie", @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
|
61
|
+
assert_equal "Sophie2016-05-23", @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
|
62
|
+
#concat Integer
|
65
63
|
assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
|
66
|
-
assert_equal 1, User.where((User.arel_table[:age] +
|
64
|
+
assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
|
67
65
|
assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
|
68
66
|
|
69
67
|
# Replace
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
68
|
+
assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
|
69
|
+
assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
|
70
|
+
|
71
|
+
#
|
72
72
|
end
|
73
|
+
|
73
74
|
end
|
75
|
+
|
74
76
|
end
|
75
|
-
end
|
77
|
+
end
|
@@ -1,20 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
require 'date'
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
|
-
module
|
5
|
+
module WthAr
|
6
|
+
|
6
7
|
describe 'the sqlite visitor can do string operations' do
|
8
|
+
|
7
9
|
before do
|
8
10
|
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
9
11
|
ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
10
|
-
|
11
|
-
ActiveRecord.default_timezone = :utc
|
12
|
-
else
|
13
|
-
ActiveRecord::Base.default_timezone = :utc
|
14
|
-
end
|
12
|
+
ActiveRecord::Base.default_timezone = :utc
|
15
13
|
@cnx = ActiveRecord::Base.connection
|
16
14
|
Arel::Table.engine = ActiveRecord::Base
|
17
|
-
@cnx.drop_table(:users) rescue nil
|
15
|
+
@cnx.drop_table(:users) rescue nil
|
18
16
|
@cnx.create_table :users do |t|
|
19
17
|
t.column :age, :integer
|
20
18
|
t.column :name, :string
|
@@ -28,16 +26,16 @@ module ArelExtensions
|
|
28
26
|
end
|
29
27
|
class User < ActiveRecord::Base
|
30
28
|
end
|
31
|
-
d = Date.new(2016, 5,
|
32
|
-
@lucas = User.create! age
|
33
|
-
sophie = User.create age
|
34
|
-
@sophie = User.where(id
|
35
|
-
User.create! age
|
36
|
-
User.create! age
|
37
|
-
User.create! age
|
38
|
-
@laure = User.create age
|
39
|
-
User.create! age
|
40
|
-
@neg = User.create age
|
29
|
+
d = Date.new(2016, 5,23)
|
30
|
+
@lucas = User.create! :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
|
31
|
+
sophie = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
|
32
|
+
@sophie = User.where(:id => sophie.id)
|
33
|
+
User.create! :age => 20, :name => "Camille", :created_at => d, :score => 20.16
|
34
|
+
User.create! :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
|
35
|
+
User.create! :age => 23, :name => "Myung", :created_at => d, :score => 20.16
|
36
|
+
@laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
|
37
|
+
User.create! :age => nil, :name => "Test", :created_at => d, :score => 1.62
|
38
|
+
@neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
|
41
39
|
@table = Arel::Table.new(:users)
|
42
40
|
@name = @table[:name]
|
43
41
|
end
|
@@ -45,24 +43,30 @@ module ArelExtensions
|
|
45
43
|
@cnx.drop_table(:users)
|
46
44
|
end
|
47
45
|
|
48
|
-
it
|
46
|
+
it "should do string operations" do
|
49
47
|
# concat
|
50
48
|
d = Date.new(1997, 6, 15)
|
51
|
-
assert_equal
|
52
|
-
assert_equal
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
57
|
-
#
|
49
|
+
assert_equal "SophiePhan", @sophie.select((@name + "Phan").as("res")).first.res
|
50
|
+
assert_equal "Sophie2", @sophie.select((@name + 2).as("res")).first.res
|
51
|
+
assert_equal "Sophie1997-06-15", @sophie.select((@name + d).as("res")).first.res
|
52
|
+
assert_equal "Sophie15", @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
|
53
|
+
assert_equal "SophieSophie", @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
|
54
|
+
assert_equal "Sophie2016-05-23", @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
|
55
|
+
#concat Integer
|
58
56
|
assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
|
59
|
-
assert_equal 1, User.where((User.arel_table[:age] +
|
57
|
+
assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
|
60
58
|
assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
|
61
59
|
|
60
|
+
|
61
|
+
|
62
62
|
# Replace
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
63
|
+
assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
|
64
|
+
assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
|
65
|
+
|
66
|
+
#
|
65
67
|
end
|
68
|
+
|
66
69
|
end
|
70
|
+
|
67
71
|
end
|
68
|
-
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yann Azoury
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activerecord
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 6.0.0.rc2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 6.0.0.rc2
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: minitest
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,20 +40,34 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '5.9'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rdoc
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '4.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '4.0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rake
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
46
60
|
requirements:
|
47
61
|
- - "~>"
|
48
62
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
63
|
+
version: '11'
|
50
64
|
type: :development
|
51
65
|
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
68
|
- - "~>"
|
55
69
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
70
|
+
version: '11'
|
57
71
|
description: Adds new features to Arel
|
58
72
|
email:
|
59
73
|
- yann.azoury@faveod.com
|
@@ -67,61 +81,45 @@ extra_rdoc_files:
|
|
67
81
|
- functions.html
|
68
82
|
files:
|
69
83
|
- ".codeclimate.yml"
|
70
|
-
- ".github/workflows/publish.yml"
|
71
|
-
- ".github/workflows/release.yml"
|
72
|
-
- ".github/workflows/ruby.yml"
|
73
84
|
- ".gitignore"
|
74
85
|
- ".rubocop.yml"
|
75
|
-
-
|
86
|
+
- ".travis.yml"
|
87
|
+
- ".travis/oracle/download.js"
|
88
|
+
- ".travis/oracle/download.sh"
|
89
|
+
- ".travis/oracle/download_ojdbc.js"
|
90
|
+
- ".travis/oracle/install.sh"
|
91
|
+
- ".travis/setup_accounts.sh"
|
92
|
+
- ".travis/sqlite3/extension-functions.sh"
|
76
93
|
- Gemfile
|
77
94
|
- MIT-LICENSE.txt
|
78
|
-
- NEWS.md
|
79
95
|
- README.md
|
80
96
|
- Rakefile
|
81
97
|
- SQL_Challenges.md
|
82
98
|
- TODO
|
83
99
|
- appveyor.yml
|
84
100
|
- arel_extensions.gemspec
|
85
|
-
- bin/build
|
86
|
-
- bin/compose
|
87
|
-
- bin/publish
|
88
|
-
- dev/arelx.dockerfile
|
89
|
-
- dev/compose.yaml
|
90
|
-
- dev/postgres.dockerfile
|
91
|
-
- dev/rbenv
|
92
101
|
- functions.html
|
93
102
|
- gemfiles/rails3.gemfile
|
94
|
-
- gemfiles/
|
95
|
-
- gemfiles/
|
103
|
+
- gemfiles/rails4.gemfile
|
104
|
+
- gemfiles/rails5_0.gemfile
|
96
105
|
- gemfiles/rails5_1_4.gemfile
|
97
106
|
- gemfiles/rails5_2.gemfile
|
98
|
-
- gemfiles/rails6.gemfile
|
99
|
-
- gemfiles/rails6_1.gemfile
|
100
|
-
- gemfiles/rails7.gemfile
|
101
|
-
- gemfiles/rails7_1.gemfile
|
102
|
-
- gemfiles/rails7_2.gemfile
|
103
|
-
- gemspecs/arel_extensions-v1.gemspec
|
104
|
-
- gemspecs/arel_extensions-v2.gemspec
|
105
|
-
- generate_gems.sh
|
106
107
|
- init/mssql.sql
|
107
108
|
- init/mysql.sql
|
108
109
|
- init/oracle.sql
|
109
110
|
- init/postgresql.sql
|
110
111
|
- init/sqlite.sql
|
111
112
|
- lib/arel_extensions.rb
|
112
|
-
- lib/arel_extensions/aliases.rb
|
113
113
|
- lib/arel_extensions/attributes.rb
|
114
114
|
- lib/arel_extensions/boolean_functions.rb
|
115
115
|
- lib/arel_extensions/common_sql_functions.rb
|
116
116
|
- lib/arel_extensions/comparators.rb
|
117
117
|
- lib/arel_extensions/date_duration.rb
|
118
|
-
- lib/arel_extensions/helpers.rb
|
119
118
|
- lib/arel_extensions/insert_manager.rb
|
120
119
|
- lib/arel_extensions/math.rb
|
121
120
|
- lib/arel_extensions/math_functions.rb
|
122
121
|
- lib/arel_extensions/nodes.rb
|
123
122
|
- lib/arel_extensions/nodes/abs.rb
|
124
|
-
- lib/arel_extensions/nodes/aggregate_function.rb
|
125
123
|
- lib/arel_extensions/nodes/blank.rb
|
126
124
|
- lib/arel_extensions/nodes/case.rb
|
127
125
|
- lib/arel_extensions/nodes/cast.rb
|
@@ -135,7 +133,6 @@ files:
|
|
135
133
|
- lib/arel_extensions/nodes/find_in_set.rb
|
136
134
|
- lib/arel_extensions/nodes/floor.rb
|
137
135
|
- lib/arel_extensions/nodes/format.rb
|
138
|
-
- lib/arel_extensions/nodes/formatted_date.rb
|
139
136
|
- lib/arel_extensions/nodes/formatted_number.rb
|
140
137
|
- lib/arel_extensions/nodes/function.rb
|
141
138
|
- lib/arel_extensions/nodes/is_null.rb
|
@@ -150,13 +147,10 @@ files:
|
|
150
147
|
- lib/arel_extensions/nodes/rand.rb
|
151
148
|
- lib/arel_extensions/nodes/repeat.rb
|
152
149
|
- lib/arel_extensions/nodes/replace.rb
|
153
|
-
- lib/arel_extensions/nodes/rollup.rb
|
154
150
|
- lib/arel_extensions/nodes/round.rb
|
155
|
-
- lib/arel_extensions/nodes/select.rb
|
156
151
|
- lib/arel_extensions/nodes/soundex.rb
|
157
152
|
- lib/arel_extensions/nodes/std.rb
|
158
153
|
- lib/arel_extensions/nodes/substring.rb
|
159
|
-
- lib/arel_extensions/nodes/sum.rb
|
160
154
|
- lib/arel_extensions/nodes/then.rb
|
161
155
|
- lib/arel_extensions/nodes/trim.rb
|
162
156
|
- lib/arel_extensions/nodes/union.rb
|
@@ -170,7 +164,6 @@ files:
|
|
170
164
|
- lib/arel_extensions/tasks.rb
|
171
165
|
- lib/arel_extensions/version.rb
|
172
166
|
- lib/arel_extensions/visitors.rb
|
173
|
-
- lib/arel_extensions/visitors/convert_format.rb
|
174
167
|
- lib/arel_extensions/visitors/ibm_db.rb
|
175
168
|
- lib/arel_extensions/visitors/mssql.rb
|
176
169
|
- lib/arel_extensions/visitors/mysql.rb
|
@@ -179,8 +172,8 @@ files:
|
|
179
172
|
- lib/arel_extensions/visitors/postgresql.rb
|
180
173
|
- lib/arel_extensions/visitors/sqlite.rb
|
181
174
|
- lib/arel_extensions/visitors/to_sql.rb
|
182
|
-
- test/arelx_test_helper.rb
|
183
175
|
- test/database.yml
|
176
|
+
- test/helper.rb
|
184
177
|
- test/real_db_test.rb
|
185
178
|
- test/support/alter_system_user_password.sql
|
186
179
|
- test/support/create_oracle_enhanced_users.sql
|
@@ -197,8 +190,6 @@ files:
|
|
197
190
|
- test/with_ar/test_math_sqlite.rb
|
198
191
|
- test/with_ar/test_string_mysql.rb
|
199
192
|
- test/with_ar/test_string_sqlite.rb
|
200
|
-
- version_v1.rb
|
201
|
-
- version_v2.rb
|
202
193
|
homepage: https://github.com/Faveod/arel-extensions
|
203
194
|
licenses:
|
204
195
|
- MIT
|
@@ -216,11 +207,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
207
|
version: '0'
|
217
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
209
|
requirements:
|
219
|
-
- - "
|
210
|
+
- - ">"
|
220
211
|
- !ruby/object:Gem::Version
|
221
|
-
version:
|
212
|
+
version: 1.3.1
|
222
213
|
requirements: []
|
223
|
-
rubygems_version: 3.
|
214
|
+
rubygems_version: 3.0.2
|
224
215
|
signing_key:
|
225
216
|
specification_version: 4
|
226
217
|
summary: Extending Arel
|