arql 0.2.12 → 0.3.1

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: 59eda4176935ad6c21bff248beac1078df7c44239f17c5febd60cd3af5617b34
4
- data.tar.gz: f6362e715937b0792285ded2d9d10dc00a1e4e9cb224ec7e6ac01ea67d08f268
3
+ metadata.gz: 7814d23bef8d728235b779a5d8ddcd76565d7240fd37b7d6d9b62e37ed851d2f
4
+ data.tar.gz: cd9f77c2a41055bd20c18ec38ae3f461b580c3bfb983b4f73bf23df9fc027408
5
5
  SHA512:
6
- metadata.gz: 50c7e6ac7e3014bc25a7b345ac126b61b79a194907d728140deef9a62ef2adc64947dc84cfad5870894005c3b1a48b7b1c96daee2708fac423ed71a207dbba96
7
- data.tar.gz: 825621c088e16302953709aa518e5d19f5064212852b65cb230f685e10b47972400eeb2e77b921fa57fb16a8eb9af743e684a60d7d7bc7cfb0e8a61551608131
6
+ metadata.gz: ef4eb1f78e9419f02155a0f27d6903adcd553ed071eec9f589a86dd69b0d2ca0a8a858865d23d85ec50284ec7dfa7eac0b2290ba9162dbe56f732545e3d81179
7
+ data.tar.gz: 69ed39eca6d84f869190b7ee8e49aa5080dcfe13c0a46341a5552a01e41bdf03a8d31099257639fa28ce2dd6d81088d060fec402c79a7c1e6f442b94eda38249
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.2.12)
5
- activerecord (~> 6.0.3)
4
+ arql (0.3.1)
5
+ activerecord (>= 6.0.3, < 6.2.0)
6
6
  activesupport (~> 6.0.3)
7
7
  caxlsx (~> 3.0.2)
8
8
  composite_primary_keys (~> 12.0.3)
@@ -10,7 +10,7 @@ PATH
10
10
  net-ssh-gateway (~> 2.0.0)
11
11
  pry (~> 0.13.1)
12
12
  pry-byebug (~> 3.9.0)
13
- pry-doc (~> 1.1.0)
13
+ pry-doc (~> 1.2.0)
14
14
  rainbow (~> 3.0.0)
15
15
  roo (~> 2.8.3)
16
16
  sqlite3 (~> 1.4)
@@ -20,65 +20,69 @@ PATH
20
20
  GEM
21
21
  remote: https://rubygems.org/
22
22
  specs:
23
- activemodel (6.0.3.4)
24
- activesupport (= 6.0.3.4)
25
- activerecord (6.0.3.4)
26
- activemodel (= 6.0.3.4)
27
- activesupport (= 6.0.3.4)
28
- activesupport (6.0.3.4)
23
+ activemodel (6.0.4.1)
24
+ activesupport (= 6.0.4.1)
25
+ activerecord (6.0.4.1)
26
+ activemodel (= 6.0.4.1)
27
+ activesupport (= 6.0.4.1)
28
+ activesupport (6.0.4.1)
29
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
30
30
  i18n (>= 0.7, < 2)
31
31
  minitest (~> 5.1)
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)
39
39
  rubyzip (>= 1.3.0, < 3)
40
40
  coderay (1.1.3)
41
- composite_primary_keys (12.0.3)
41
+ composite_primary_keys (12.0.10)
42
42
  activerecord (~> 6.0.0)
43
- concurrent-ruby (1.1.7)
43
+ concurrent-ruby (1.1.9)
44
44
  htmlentities (4.3.4)
45
- i18n (1.8.5)
45
+ i18n (1.8.10)
46
46
  concurrent-ruby (~> 1.0)
47
47
  method_source (1.0.0)
48
- mimemagic (0.3.5)
49
- mini_portile2 (2.4.0)
50
- minitest (5.14.2)
48
+ mimemagic (0.4.3)
49
+ nokogiri (~> 1)
50
+ rake
51
+ mini_portile2 (2.6.1)
52
+ minitest (5.14.4)
51
53
  mysql2 (0.5.3)
52
54
  net-ssh (6.1.0)
53
55
  net-ssh-gateway (2.0.0)
54
56
  net-ssh (>= 4.0.0)
55
- nokogiri (1.10.10)
56
- mini_portile2 (~> 2.4.0)
57
+ nokogiri (1.12.5)
58
+ mini_portile2 (~> 2.6.1)
59
+ racc (~> 1.4)
57
60
  pry (0.13.1)
58
61
  coderay (~> 1.1)
59
62
  method_source (~> 1.0)
60
63
  pry-byebug (3.9.0)
61
64
  byebug (~> 11.0)
62
65
  pry (~> 0.13.0)
63
- pry-doc (1.1.0)
66
+ pry-doc (1.2.0)
64
67
  pry (~> 0.11)
65
68
  yard (~> 0.9.11)
69
+ racc (1.6.0)
66
70
  rainbow (3.0.0)
67
71
  rake (12.3.3)
68
72
  roo (2.8.3)
69
73
  nokogiri (~> 1)
70
74
  rubyzip (>= 1.3.0, < 3.0.0)
71
- rubyzip (2.3.0)
75
+ rubyzip (2.3.2)
72
76
  sqlite3 (1.4.2)
73
77
  table_print (1.5.7)
74
78
  terminal-table (1.8.0)
75
79
  unicode-display_width (~> 1.1, >= 1.1.1)
76
80
  thread_safe (0.3.6)
77
- tzinfo (1.2.8)
81
+ tzinfo (1.2.9)
78
82
  thread_safe (~> 0.1)
79
- unicode-display_width (1.7.0)
80
- yard (0.9.25)
81
- zeitwerk (2.4.2)
83
+ unicode-display_width (1.8.0)
84
+ yard (0.9.26)
85
+ zeitwerk (2.5.1)
82
86
 
83
87
  PLATFORMS
84
88
  ruby
@@ -88,4 +92,4 @@ DEPENDENCIES
88
92
  rake (~> 12.0)
89
93
 
90
94
  BUNDLED WITH
91
- 2.1.4
95
+ 2.2.3
data/arql.gemspec CHANGED
@@ -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
 
@@ -28,13 +28,13 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'sqlite3', '~> 1.4'
29
29
  # spec.add_dependency 'activerecord-sqlserver-adapter'
30
30
  # spec.add_dependency 'activerecord-oracle_enhanced-adapter'
31
- spec.add_dependency 'activerecord', '~> 6.0.3'
31
+ spec.add_dependency 'activerecord', '>= 6.0.3', '< 6.2.0'
32
32
  spec.add_dependency 'composite_primary_keys', '~> 12.0.3'
33
33
  spec.add_dependency 'activesupport', '~> 6.0.3'
34
34
  spec.add_dependency 'net-ssh-gateway', '~> 2.0.0'
35
35
  spec.add_dependency 'pry', '~> 0.13.1'
36
36
  spec.add_dependency 'pry-byebug', '~> 3.9.0'
37
- spec.add_dependency 'pry-doc', '~> 1.1.0'
37
+ spec.add_dependency 'pry-doc', '~> 1.2.0'
38
38
  spec.add_dependency 'rainbow', '~> 3.0.0'
39
39
  spec.add_dependency 'terminal-table', '~> 1.8.0'
40
40
  spec.add_dependency 'table_print', '~> 1.5.6'
data/lib/arql/app.rb CHANGED
@@ -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
@@ -0,0 +1,244 @@
1
+ require 'active_support/concern'
2
+
3
+ module Arql
4
+ module Concerns
5
+ module GlobalDataDefinition
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+
10
+ # Example:
11
+ #
12
+ # create_table :post, id: false, primary_key: :id do |t|
13
+ # t.column :id, :bigint, precison: 19, comment: 'ID'
14
+ # t.column :name, :string, comment: '名称'
15
+ # t.column :gmt_created, :datetime, comment: '创建时间'
16
+ # t.column :gmt_modified, :datetime, comment: '最后修改时间'
17
+ # end
18
+ #
19
+ # Creates a new table with the name +table_name+. +table_name+ may either
20
+ # be a String or a Symbol.
21
+ #
22
+ # There are two ways to work with #create_table. You can use the block
23
+ # form or the regular form, like this:
24
+ #
25
+ # === Block form
26
+ #
27
+ # # create_table() passes a TableDefinition object to the block.
28
+ # # This form will not only create the table, but also columns for the
29
+ # # table.
30
+ #
31
+ # create_table(:suppliers) do |t|
32
+ # t.column :name, :string, limit: 60
33
+ # # Other fields here
34
+ # end
35
+ #
36
+ # === Block form, with shorthand
37
+ #
38
+ # # You can also use the column types as method calls, rather than calling the column method.
39
+ # create_table(:suppliers) do |t|
40
+ # t.string :name, limit: 60
41
+ # # Other fields here
42
+ # end
43
+ #
44
+ # === Regular form
45
+ #
46
+ # # Creates a table called 'suppliers' with no columns.
47
+ # create_table(:suppliers)
48
+ # # Add a column to 'suppliers'.
49
+ # add_column(:suppliers, :name, :string, {limit: 60})
50
+ #
51
+ # The +options+ hash can include the following keys:
52
+ # [<tt>:id</tt>]
53
+ # Whether to automatically add a primary key column. Defaults to true.
54
+ # Join tables for {ActiveRecord::Base.has_and_belongs_to_many}[rdoc-ref:Associations::ClassMethods#has_and_belongs_to_many] should set it to false.
55
+ #
56
+ # A Symbol can be used to specify the type of the generated primary key column.
57
+ # [<tt>:primary_key</tt>]
58
+ # The name of the primary key, if one is to be added automatically.
59
+ # Defaults to +id+. If <tt>:id</tt> is false, then this option is ignored.
60
+ #
61
+ # If an array is passed, a composite primary key will be created.
62
+ #
63
+ # Note that Active Record models will automatically detect their
64
+ # primary key. This can be avoided by using
65
+ # {self.primary_key=}[rdoc-ref:AttributeMethods::PrimaryKey::ClassMethods#primary_key=] on the model
66
+ # to define the key explicitly.
67
+ #
68
+ # [<tt>:options</tt>]
69
+ # Any extra options you want appended to the table definition.
70
+ # [<tt>:temporary</tt>]
71
+ # Make a temporary table.
72
+ # [<tt>:force</tt>]
73
+ # Set to true to drop the table before creating it.
74
+ # Set to +:cascade+ to drop dependent objects as well.
75
+ # Defaults to false.
76
+ # [<tt>:if_not_exists</tt>]
77
+ # Set to true to avoid raising an error when the table already exists.
78
+ # Defaults to false.
79
+ # [<tt>:as</tt>]
80
+ # SQL to use to generate the table. When this option is used, the block is
81
+ # ignored, as are the <tt>:id</tt> and <tt>:primary_key</tt> options.
82
+ #
83
+ # ====== Add a backend specific option to the generated SQL (MySQL)
84
+ #
85
+ # create_table(:suppliers, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4')
86
+ #
87
+ # generates:
88
+ #
89
+ # CREATE TABLE suppliers (
90
+ # id bigint auto_increment PRIMARY KEY
91
+ # ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
92
+ #
93
+ # ====== Rename the primary key column
94
+ #
95
+ # create_table(:objects, primary_key: 'guid') do |t|
96
+ # t.column :name, :string, limit: 80
97
+ # end
98
+ #
99
+ # generates:
100
+ #
101
+ # CREATE TABLE objects (
102
+ # guid bigint auto_increment PRIMARY KEY,
103
+ # name varchar(80)
104
+ # )
105
+ #
106
+ # ====== Change the primary key column type
107
+ #
108
+ # create_table(:tags, id: :string) do |t|
109
+ # t.column :label, :string
110
+ # end
111
+ #
112
+ # generates:
113
+ #
114
+ # CREATE TABLE tags (
115
+ # id varchar PRIMARY KEY,
116
+ # label varchar
117
+ # )
118
+ #
119
+ # ====== Create a composite primary key
120
+ #
121
+ # create_table(:orders, primary_key: [:product_id, :client_id]) do |t|
122
+ # t.belongs_to :product
123
+ # t.belongs_to :client
124
+ # end
125
+ #
126
+ # generates:
127
+ #
128
+ # CREATE TABLE order (
129
+ # product_id bigint NOT NULL,
130
+ # client_id bigint NOT NULL
131
+ # );
132
+ #
133
+ # ALTER TABLE ONLY "orders"
134
+ # ADD CONSTRAINT orders_pkey PRIMARY KEY (product_id, client_id);
135
+ #
136
+ # ====== Do not add a primary key column
137
+ #
138
+ # create_table(:categories_suppliers, id: false) do |t|
139
+ # t.column :category_id, :bigint
140
+ # t.column :supplier_id, :bigint
141
+ # end
142
+ #
143
+ # generates:
144
+ #
145
+ # CREATE TABLE categories_suppliers (
146
+ # category_id bigint,
147
+ # supplier_id bigint
148
+ # )
149
+ #
150
+ # ====== Create a temporary table based on a query
151
+ #
152
+ # create_table(:long_query, temporary: true,
153
+ # as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id")
154
+ #
155
+ # generates:
156
+ #
157
+ # CREATE TEMPORARY TABLE long_query AS
158
+ # SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id
159
+ #
160
+ # See also TableDefinition#column for details on how to create columns.
161
+ def create_table(table_name, **options, &blk)
162
+ ActiveRecord::Base.connection.create_table(table_name, **options, &blk)
163
+ end
164
+
165
+ # Creates a new join table with the name created using the lexical order of the first two
166
+ # arguments. These arguments can be a String or a Symbol.
167
+ #
168
+ # # Creates a table called 'assemblies_parts' with no id.
169
+ # create_join_table(:assemblies, :parts)
170
+ #
171
+ # You can pass an +options+ hash which can include the following keys:
172
+ # [<tt>:table_name</tt>]
173
+ # Sets the table name, overriding the default.
174
+ # [<tt>:column_options</tt>]
175
+ # Any extra options you want appended to the columns definition.
176
+ # [<tt>:options</tt>]
177
+ # Any extra options you want appended to the table definition.
178
+ # [<tt>:temporary</tt>]
179
+ # Make a temporary table.
180
+ # [<tt>:force</tt>]
181
+ # Set to true to drop the table before creating it.
182
+ # Defaults to false.
183
+ #
184
+ # Note that #create_join_table does not create any indices by default; you can use
185
+ # its block form to do so yourself:
186
+ #
187
+ # create_join_table :products, :categories do |t|
188
+ # t.index :product_id
189
+ # t.index :category_id
190
+ # end
191
+ #
192
+ # ====== Add a backend specific option to the generated SQL (MySQL)
193
+ #
194
+ # create_join_table(:assemblies, :parts, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8')
195
+ #
196
+ # generates:
197
+ #
198
+ # CREATE TABLE assemblies_parts (
199
+ # assembly_id bigint NOT NULL,
200
+ # part_id bigint NOT NULL,
201
+ # ) ENGINE=InnoDB DEFAULT CHARSET=utf8
202
+ #
203
+ def create_join_table(table_1, table_2, column_options: {}, **options)
204
+ ActiveRecord::Base.connection.create_join_table(table_1, table_2, column_options, **options)
205
+ end
206
+
207
+ # Drops a table from the database.
208
+ #
209
+ # [<tt>:force</tt>]
210
+ # Set to +:cascade+ to drop dependent objects as well.
211
+ # Defaults to false.
212
+ # [<tt>:if_exists</tt>]
213
+ # Set to +true+ to only drop the table if it exists.
214
+ # Defaults to false.
215
+ #
216
+ # Although this command ignores most +options+ and the block if one is given,
217
+ # it can be helpful to provide these in a migration's +change+ method so it can be reverted.
218
+ # In that case, +options+ and the block will be used by #create_table.
219
+ def drop_table(table_name, **options)
220
+ ActiveRecord::Base.connection.drop_table(table_name, **options)
221
+ end
222
+
223
+ # Drops the join table specified by the given arguments.
224
+ # See #create_join_table for details.
225
+ #
226
+ # Although this command ignores the block if one is given, it can be helpful
227
+ # to provide one in a migration's +change+ method so it can be reverted.
228
+ # In that case, the block will be used by #create_join_table.
229
+ def drop_join_table(table_1, table_2, **options)
230
+ ActiveRecord::Base.connection.drop_join_table(table_1, table_2, **options)
231
+ end
232
+
233
+ # Renames a table.
234
+ #
235
+ # rename_table('octopuses', 'octopi')
236
+ #
237
+ def rename_table(table_name, new_name)
238
+ ActiveRecord::Base.connection.rename_table(table_name, new_name)
239
+ end
240
+
241
+ end
242
+ end
243
+ end
244
+ end