arql 0.1.16 → 0.1.21
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/README.md +4 -0
- data/lib/arql/definition.rb +17 -0
- data/lib/arql/ext/array.rb +25 -0
- data/lib/arql/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e66f429bfd374a86cada3192de5f27eb639a393297d9c3ccffcc778e9fba960
|
4
|
+
data.tar.gz: e62183c3d4372a3388aa1252ea0da0ac691abe0cd89c93bc647266ff1851b21b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1affdb82cfdc85929ee9a7dc14156feee185fc4cd2e27a07b9353b61d765ec397f328f82381970eaa0f0b923692fb7e568a1cd4dab8ecd4ec799d20a62303936
|
7
|
+
data.tar.gz: c7e5a7c9f47d36ef21c2eed2fd9534bd8ff14025334bc5a10288da42ec99099f19959f935ee736d4b750ded186ca5f9f72d2840510adeca88e8761d88d688529
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -282,6 +282,10 @@ ARQL ❯ Person.all.to_a.to_insert_sql
|
|
282
282
|
=> "INSERT INTO `person` (`id`,`name`,`age`,`gender`,`grade`,`blood_type`) VALUES (1, 'Jack', 30, NULL, NULL, NULL), (2, 'Jack', 11, 1, NULL, NULL), (3, 'Jack', 12, 1, NULL, NULL), (4, 'Jack', 30, 1, NULL, NULL), (5, 'Jack', 12, 2, NULL, NULL), (6, 'Jack', 2, 2, 2, NULL), (7, 'Jack', 3, 2, 2, NULL), (8, 'Jack', 30, 2, 2, 'AB'), (9, 'Jack', 30, 2, 2, 'AB'), (10, 'Jack', 30, 2, 2, 'AB'), (11, 'Jackson', 30, 2, 2, 'AB') ON DUPLICATE KEY UPDATE `id`=`id`;"
|
283
283
|
```
|
284
284
|
|
285
|
+
#### to_create_sql
|
286
|
+
|
287
|
+
You can call `to_create_sql` on any ActiveRecord model class to get create table SQL of the model class / table.
|
288
|
+
|
285
289
|
#### t
|
286
290
|
|
287
291
|
You can call `t` method on any ActiveRecord model instance to print a pretty table of attributes names and values of the object.
|
data/lib/arql/definition.rb
CHANGED
@@ -26,6 +26,9 @@ module Arql
|
|
26
26
|
self.class.to_upsert_sql([self])
|
27
27
|
end
|
28
28
|
|
29
|
+
included do
|
30
|
+
end
|
31
|
+
|
29
32
|
class_methods do
|
30
33
|
def t
|
31
34
|
table_name = Commands::Table::get_table_name(name)
|
@@ -50,6 +53,10 @@ module Arql
|
|
50
53
|
ActiveRecord::InsertAll.new(self, group.map(&:attributes), on_duplicate: on_duplicate).send(:to_sql) + ';'
|
51
54
|
end.join("\n")
|
52
55
|
end
|
56
|
+
|
57
|
+
def to_create_sql
|
58
|
+
ActiveRecord::Base.connection.exec_query("show create table #{table_name}").rows.last.last
|
59
|
+
end
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
@@ -159,5 +166,15 @@ module Arql
|
|
159
166
|
end
|
160
167
|
end
|
161
168
|
end
|
169
|
+
|
170
|
+
::ActiveRecord::Relation.class_eval do
|
171
|
+
def t
|
172
|
+
records.t
|
173
|
+
end
|
174
|
+
|
175
|
+
def v
|
176
|
+
records.v
|
177
|
+
end
|
178
|
+
end
|
162
179
|
end
|
163
180
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -13,6 +13,31 @@ class Array
|
|
13
13
|
end.join("\n")
|
14
14
|
end
|
15
15
|
|
16
|
+
def t(*attrs)
|
17
|
+
if attrs.present? && present? && first.is_a?(ActiveRecord::Base)
|
18
|
+
puts Terminal::Table.new { |t|
|
19
|
+
t << attrs
|
20
|
+
t << :separator
|
21
|
+
each do |e|
|
22
|
+
t << e.attributes.values_at(*attrs.map(&:to_s))
|
23
|
+
end
|
24
|
+
}
|
25
|
+
else
|
26
|
+
table = Terminal::Table.new { |t|
|
27
|
+
v.each { |row| t << (row || :separator)}
|
28
|
+
}.to_s
|
29
|
+
|
30
|
+
terminal_width = `tput cols`.to_i
|
31
|
+
if table.first.size > terminal_width
|
32
|
+
table = table.lines.map(&:chomp)
|
33
|
+
puts table[0..2].join("\n")
|
34
|
+
puts table[3..-1].join("\n#{'-' * terminal_width}\n")
|
35
|
+
else
|
36
|
+
puts table
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
16
41
|
def v
|
17
42
|
return self unless present?
|
18
43
|
t = []
|
data/lib/arql/version.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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -257,7 +257,7 @@ homepage: https://github.com/lululau/arql
|
|
257
257
|
licenses:
|
258
258
|
- MIT
|
259
259
|
metadata: {}
|
260
|
-
post_install_message:
|
260
|
+
post_install_message:
|
261
261
|
rdoc_options: []
|
262
262
|
require_paths:
|
263
263
|
- lib
|
@@ -273,7 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
275
|
rubygems_version: 3.1.2
|
276
|
-
signing_key:
|
276
|
+
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Rails ActiveRecord + Pry is the best SQL query editor
|
279
279
|
test_files: []
|