arql 0.2.14 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acc076bc57fba6651a6d3b5c5232e002d0ad3c23dffb4c11b09a5f4697ec65b5
4
- data.tar.gz: 9a868a87e0d9658800de3740b6b42697cc65c07535b76c67bc88d38c37c82433
3
+ metadata.gz: d63702948cb453c9e8fe42743024faa3cb1c7102a2ba592076d7a1005f64392b
4
+ data.tar.gz: 42c4e35504a6334990283aa0cc433a507339d4dd1bfb804bb81454d57b7187eb
5
5
  SHA512:
6
- metadata.gz: 6dbaa27d969c85aea66fc13d443d91080cbfa3550a4728a20440385927a6527ff758dc23591f1b220e0b2c0f9ed5f4012609ce00c655251be64f22605f2f39c8
7
- data.tar.gz: 06cb755475b4f6cffec68aa681fea2706577f01f0c0771024f79b7f9f92a039cfb35e815ed251d50198229a908051b1c103828d773481f29d11a33c5b5417a5d
6
+ metadata.gz: 668284267a0469734710a9b5c7490116af4ebeb75de5c6754d8f9e733c409b4798a5d4b3216eb55f8d7b50569502d84fb22cc2a1bdf896d330d4ae0ce7ca4af6
7
+ data.tar.gz: bdf6f3900ba0b936cfa2a0d48dccc981215f2f2f1a6397b907d4e81de430f99d87bf2d22faa6b3f0fb16281b5a1b83ccbfd03e0f6f7b7d4783fc1090fc796b55
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.2.14)
4
+ arql (0.3.0)
5
5
  activerecord (~> 6.0.3)
6
6
  activesupport (~> 6.0.3)
7
7
  caxlsx (~> 3.0.2)
@@ -32,7 +32,7 @@ GEM
32
32
  tzinfo (~> 1.1)
33
33
  zeitwerk (~> 2.2, >= 2.2.2)
34
34
  byebug (11.1.3)
35
- caxlsx (3.0.2)
35
+ caxlsx (3.0.4)
36
36
  htmlentities (~> 4.3, >= 4.3.4)
37
37
  mimemagic (~> 0.3)
38
38
  nokogiri (~> 1.10, >= 1.10.4)
@@ -74,10 +74,10 @@ GEM
74
74
  terminal-table (1.8.0)
75
75
  unicode-display_width (~> 1.1, >= 1.1.1)
76
76
  thread_safe (0.3.6)
77
- tzinfo (1.2.8)
77
+ tzinfo (1.2.9)
78
78
  thread_safe (~> 0.1)
79
79
  unicode-display_width (1.7.0)
80
- yard (0.9.25)
80
+ yard (0.9.26)
81
81
  zeitwerk (2.4.2)
82
82
 
83
83
  PLATFORMS
@@ -88,4 +88,4 @@ DEPENDENCIES
88
88
  rake (~> 12.0)
89
89
 
90
90
  BUNDLED WITH
91
- 2.1.4
91
+ 2.2.3
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = %{Use ActiveRecord and Pry as your favorite SQL query editor.}
11
11
  spec.homepage = "https://github.com/lululau/arql"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
14
14
 
15
15
 
16
16
 
@@ -10,6 +10,7 @@ require "arql/repl"
10
10
  require "arql/ssh_proxy"
11
11
  require "arql/app"
12
12
  require "arql/cli"
13
+ require "arql/mysqldump"
13
14
 
14
15
  module Arql
15
16
  end
@@ -4,7 +4,7 @@ module Arql
4
4
  class App
5
5
 
6
6
  class << self
7
- attr_accessor :log_io, :env, :prompt, :instance
7
+ attr_accessor :log_io, :env, :prompt, :instance, :connect_options
8
8
 
9
9
  def config
10
10
  @@effective_config
@@ -27,7 +27,8 @@ module Arql
27
27
  require "arql/definition"
28
28
  @options = options
29
29
  App.env = @options.env
30
- Connection.open(connect_options)
30
+ App.connect_options = connect_options
31
+ Connection.open(App.connect_options)
31
32
  @definition = Definition.new(effective_config)
32
33
  load_initializer!
33
34
  App.instance = self
@@ -4,6 +4,9 @@ module Arql
4
4
  def open(options)
5
5
  ActiveRecord::Base.establish_connection(options)
6
6
  $C = ActiveRecord::Base.connection
7
+ $C.define_singleton_method(:dump) do |filename, no_create_db=false|
8
+ Arql::Mysqldump.new.dump_database(filename, no_create_db)
9
+ end
7
10
  end
8
11
  end
9
12
  end
@@ -35,6 +35,10 @@ module Arql
35
35
  [self].write_excel(filename, *fields, **options)
36
36
  end
37
37
 
38
+ def dump(filename, batch_size=500)
39
+ [self].dump(filename, batch_size)
40
+ end
41
+
38
42
  included do
39
43
  end
40
44
 
@@ -66,6 +70,10 @@ module Arql
66
70
  def to_create_sql
67
71
  ActiveRecord::Base.connection.exec_query("show create table #{table_name}").rows.last.last
68
72
  end
73
+
74
+ def dump(filename, no_create_table=false)
75
+ Arql::Mysqldump.new.dump_table(filename, table_name, no_create_table)
76
+ end
69
77
  end
70
78
  end
71
79
 
@@ -237,6 +245,9 @@ module Arql
237
245
  records.write_excel(filename, *fields, **options)
238
246
  end
239
247
 
248
+ def dump(filename, batch_size=500)
249
+ records.dump(filename, batch_size)
250
+ end
240
251
  end
241
252
  end
242
253
  end
@@ -127,4 +127,13 @@ class Array
127
127
  end
128
128
  end
129
129
  end
130
+
131
+ def dump(filename, batch_size=500)
132
+ File.open(File.expand_path(filename), 'w') do |file|
133
+ group_by(&:class).each do |(klass, records)|
134
+ file.puts(klass.to_upsert_sql(records, batch_size))
135
+ end
136
+ end
137
+ {size: size, file: File.expand_path(filename)}
138
+ end
130
139
  end
@@ -95,7 +95,7 @@ module Kernel
95
95
  def generate_excel(filename)
96
96
  Axlsx::Package.new do |package|
97
97
  yield(package.workbook)
98
- package.serialize(filename)
98
+ package.serialize(File.expand_path(filename))
99
99
  end
100
100
  end
101
101
 
@@ -2,4 +2,12 @@ class String
2
2
  def p
3
3
  puts self
4
4
  end
5
+
6
+ def expa
7
+ File.expand_path(self)
8
+ end
9
+
10
+ def f
11
+ expa
12
+ end
5
13
  end
@@ -0,0 +1,44 @@
1
+ module Arql
2
+ class Mysqldump
3
+
4
+ def initialize(options = nil)
5
+ options ||= App.connect_options
6
+ @options = options
7
+ if options[:socket]
8
+ port_or_sock = "-S #{options[:socket]}"
9
+ else
10
+ port_or_sock = "-P #{options[:port] || 3306}"
11
+ end
12
+ @base_dump_cmd = "mysqldump -u %{user} -h %{host} %{port_or_sock} %{password} --skip-lock-tables " % {
13
+ user: options[:username],
14
+ host: options[:host],
15
+ password: options[:password].presence.try { |e| "-p#{e}" } || '',
16
+ port_or_sock: port_or_sock
17
+ }
18
+ end
19
+
20
+ def dump_table(filename, table_name, no_create_table = false)
21
+ system dump_table_cmd(table_name, no_create_table) + " > #{filename}"
22
+ end
23
+
24
+ def dump_database(filename, no_create_db = false)
25
+ system dump_database_cmd(no_create_db) + " > #{filename}"
26
+ end
27
+
28
+ def dump_table_cmd(table_name, no_create_table = false)
29
+ @base_dump_cmd + " " + if no_create_table
30
+ "--no-create-info #{@options[:database]} #{table_name}"
31
+ else
32
+ "--add-drop-table #{@options[:database]} #{table_name}"
33
+ end
34
+ end
35
+
36
+ def dump_database_cmd(no_create_db = false)
37
+ @base_dump_cmd + " " + if no_create_db
38
+ "--no-create-db --add-drop-database --databases #{@options[:database]}"
39
+ else
40
+ "--add-drop-database --add-drop-table --databases #{@options[:database]}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.2.14"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.14
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -251,6 +251,7 @@ files:
251
251
  - lib/arql/ext/time.rb
252
252
  - lib/arql/id.rb
253
253
  - lib/arql/multi_io.rb
254
+ - lib/arql/mysqldump.rb
254
255
  - lib/arql/repl.rb
255
256
  - lib/arql/ssh_proxy.rb
256
257
  - lib/arql/ssh_proxy_patch.rb
@@ -267,14 +268,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
267
268
  requirements:
268
269
  - - ">="
269
270
  - !ruby/object:Gem::Version
270
- version: 2.3.0
271
+ version: 2.6.0
271
272
  required_rubygems_version: !ruby/object:Gem::Requirement
272
273
  requirements:
273
274
  - - ">="
274
275
  - !ruby/object:Gem::Version
275
276
  version: '0'
276
277
  requirements: []
277
- rubygems_version: 3.1.4
278
+ rubygems_version: 3.2.3
278
279
  signing_key:
279
280
  specification_version: 4
280
281
  summary: Rails ActiveRecord + Pry is the best SQL query editor