arql 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/arql/definition.rb +29 -0
- data/lib/arql/ext/array.rb +15 -0
- data/lib/arql/ext.rb +1 -0
- data/lib/arql/version.rb +1 -1
- data/lib/arql.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50c397f035d89506f745002163459930acf16862c71aba29f61e3843da9fefef
|
4
|
+
data.tar.gz: b4dce80cde7add1ec3aafbb54e9d12736bc5e0d661f0f28aebcaf66c3bbc98a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c60d3e7cd72361b59239c26967079e9c9baa0f28ff16caec7b20074d3a08636670e41afc7290fea95bfe00bc8ca4e78586aa89a996974c37364dc99c1e8c4855
|
7
|
+
data.tar.gz: 64f66abb0e4494b3f2b49b6972af3aab5a5e030f5b9ee9f51e074136a01eeeb2b8647aacad7c8d7501f5ea1c195d9100b93040a634c4db4e552d23d141df046c
|
data/Gemfile.lock
CHANGED
data/lib/arql/definition.rb
CHANGED
@@ -1,4 +1,32 @@
|
|
1
1
|
module Arql
|
2
|
+
module Extension
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def to_insert_sql
|
6
|
+
self.class.to_insert_sql([self])
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_upsert_sql
|
10
|
+
self.class.to_upsert_sql([self])
|
11
|
+
end
|
12
|
+
|
13
|
+
class_methods do
|
14
|
+
def to_insert_sql(records, batch_size=1)
|
15
|
+
to_sql(records, :skip, batch_size)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_upsert_sql(records, batch_size=1)
|
19
|
+
to_sql(records, :update, batch_size)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_sql(records, on_duplicate, batch_size)
|
23
|
+
records.in_groups_of(batch_size, false).map do |group|
|
24
|
+
ActiveRecord::InsertAll.new(self, group.map(&:attributes), on_duplicate: on_duplicate).send(:to_sql) + ';'
|
25
|
+
end.join("\n")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
2
30
|
class Definition
|
3
31
|
class << self
|
4
32
|
def models
|
@@ -15,6 +43,7 @@ module Arql
|
|
15
43
|
const_name = 'Modul' if const_name == 'Module'
|
16
44
|
const_name = 'Clazz' if const_name == 'Class'
|
17
45
|
Class.new(ActiveRecord::Base) do
|
46
|
+
include Arql::Extension
|
18
47
|
self.primary_key = pkey
|
19
48
|
self.table_name = table_name
|
20
49
|
self.inheritance_column = nil
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Array
|
2
|
+
def to_insert_sql(batch_size=500)
|
3
|
+
raise 'All element should be an ActiveRecord instance object' unless all? { |e| e.is_a?(ActiveRecord::Base) }
|
4
|
+
group_by(&:class).map do |(klass, records)|
|
5
|
+
klass.to_insert_sql(records, batch_size)
|
6
|
+
end.join("\n")
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_upsert_sql(batch_size=500)
|
10
|
+
raise 'All element should be an ActiveRecord instance object' unless all? { |e| e.is_a?(ActiveRecord::Base) }
|
11
|
+
group_by(&:class).map do |(klass, records)|
|
12
|
+
klass.to_upsert_sql(records, batch_size)
|
13
|
+
end.join("\n")
|
14
|
+
end
|
15
|
+
end
|
data/lib/arql/ext.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'arql/ext/array'
|
data/lib/arql/version.rb
CHANGED
data/lib/arql.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -178,6 +178,8 @@ files:
|
|
178
178
|
- lib/arql/commands/table.rb
|
179
179
|
- lib/arql/connection.rb
|
180
180
|
- lib/arql/definition.rb
|
181
|
+
- lib/arql/ext.rb
|
182
|
+
- lib/arql/ext/array.rb
|
181
183
|
- lib/arql/id.rb
|
182
184
|
- lib/arql/multi_io.rb
|
183
185
|
- lib/arql/repl.rb
|