arql 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d8fb2d02931fdd0af7a9eec6b20db222f6f2fff93e0c506186316157987a443f
4
+ data.tar.gz: ae61f43b49612c316a82aac8e0c63dfc70c34527026c62201397f267ace5c188
5
+ SHA512:
6
+ metadata.gz: 8deb0c597de52fe5d1dd24f7eaa60c07133d7c0d583eb93f746b416d660a5911f556820b1937cb5f0d2d9667de3a53a1b8057e7bc6ad36321eb96b0e93f454e2
7
+ data.tar.gz: 77ba16537c3fa67c65518db3e5fbca9fa012452c2135a0d26ffabbb47ec9c65f6a3de1c052a98553b65640d9c534467a77ef5993013cb9f3d265c830db70e613
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at liuxiang@ktjr.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in arql.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arql (0.1.30)
5
+ activerecord (~> 6.0.3)
6
+ activesupport (~> 6.0.3)
7
+ mysql2 (~> 0.5.3)
8
+ net-ssh-gateway (~> 2.0.0)
9
+ pry (~> 0.13.1)
10
+ pry-byebug (~> 3.9.0)
11
+ pry-doc (~> 1.1.0)
12
+ rainbow (~> 3.0.0)
13
+ sqlite3 (~> 1.4)
14
+ table_print (~> 1.5.6)
15
+ terminal-table (~> 1.8.0)
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ activemodel (6.0.3.1)
21
+ activesupport (= 6.0.3.1)
22
+ activerecord (6.0.3.1)
23
+ activemodel (= 6.0.3.1)
24
+ activesupport (= 6.0.3.1)
25
+ activesupport (6.0.3.1)
26
+ concurrent-ruby (~> 1.0, >= 1.0.2)
27
+ i18n (>= 0.7, < 2)
28
+ minitest (~> 5.1)
29
+ tzinfo (~> 1.1)
30
+ zeitwerk (~> 2.2, >= 2.2.2)
31
+ byebug (11.1.3)
32
+ coderay (1.1.2)
33
+ concurrent-ruby (1.1.6)
34
+ i18n (1.8.2)
35
+ concurrent-ruby (~> 1.0)
36
+ method_source (1.0.0)
37
+ minitest (5.14.1)
38
+ mysql2 (0.5.3)
39
+ net-ssh (6.0.2)
40
+ net-ssh-gateway (2.0.0)
41
+ net-ssh (>= 4.0.0)
42
+ pry (0.13.1)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
45
+ pry-byebug (3.9.0)
46
+ byebug (~> 11.0)
47
+ pry (~> 0.13.0)
48
+ pry-doc (1.1.0)
49
+ pry (~> 0.11)
50
+ yard (~> 0.9.11)
51
+ rainbow (3.0.0)
52
+ rake (12.3.3)
53
+ sqlite3 (1.4.2)
54
+ table_print (1.5.6)
55
+ terminal-table (1.8.0)
56
+ unicode-display_width (~> 1.1, >= 1.1.1)
57
+ thread_safe (0.3.6)
58
+ tzinfo (1.2.7)
59
+ thread_safe (~> 0.1)
60
+ unicode-display_width (1.7.0)
61
+ yard (0.9.25)
62
+ zeitwerk (2.3.0)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ arql!
69
+ rake (~> 12.0)
70
+
71
+ BUNDLED WITH
72
+ 2.1.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Liu Xiang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,456 @@
1
+ # Arql
2
+
3
+ Arql is a simple utility gem which combines Rails ActiveRecord and Pry together, with additional helpful Pry commands. It defines model clases automatically from DB table informations.
4
+ You can use this utility as your SQL editor and querier if you are a Ruby guy.
5
+
6
+ ## Installation
7
+
8
+ Execute:
9
+
10
+ $ gem install arql
11
+
12
+ If system permission problems occurs, try with sudo:
13
+
14
+ $ sudo gem install arql
15
+
16
+ ## Usage
17
+
18
+ ### Command line options
19
+
20
+ ```
21
+ Usage: arql [options] [ruby file]
22
+
23
+ If neither [ruby file] nor -e option specified, and STDIN is not a tty, a Pry REPL will be launched,
24
+ otherwise the specified ruby file or -e option value or ruby code read from STDIN will be run, and no REPL launched
25
+
26
+ -c, --conf=CONFIG_FILE Specify config file, default is $HOME/.arql.yml, or $HOME/.arql.d/init.yml.
27
+ -i, --initializer=INITIALIZER Specify initializer ruby file, default is $HOME/.arql.rb, or $HOME/.arql.d/init.rb.
28
+ -e, --env=ENVIRON Specify config environment.
29
+ -a, --db-adapter=DB_ADAPTER Specify database Adapter, default is mysql2
30
+ -h, --db-host=DB_HOST Specify database host
31
+ -p, --db-port=DB_PORT Specify database port
32
+ -d, --db-name=DB_NAME Specify database name
33
+ -u, --db-user=DB_USER Specify database user
34
+ -P, --db-password=DB_PASSWORD Specify database password
35
+ -n, --db-encoding=DB_ENCODING Specify database encoding, default is utf8
36
+ -o, --db-pool=DB_POOL Specify database pool size, default is 5
37
+ -H, --ssh-host=SSH_HOST Specify SSH host
38
+ -O, --ssh-port=SSH_PORT Specify SSH port
39
+ -U, --ssh-user=SSH_USER Specify SSH user
40
+ -W, --ssh-password=SSH_PASSWORD Specify SSH password
41
+ -LSSH_LOCAL_PORT, Specify local SSH proxy port
42
+ --ssh-local-port
43
+ -E, --eval=CODE evaluate CODE
44
+ -S, --show-sql Show SQL on STDOUT
45
+ -w, --write-sql=OUTPUT Write SQL to OUTPUT file
46
+ -A, --append-sql=OUTPUT Append SQL to OUTPUT file
47
+ --help
48
+ Prints this help
49
+ ```
50
+
51
+ #### -c, --config=CONFIG_FILE
52
+
53
+ Specify location of config file, default is `$HOME/.arql.yml`, or `$HOME/.arql.d/init.yml`.
54
+
55
+ The config file typically is as same as a Rails database config file, but with several additional config options, e.g. `ssh` options, etc.
56
+
57
+ See `Config File` section.
58
+
59
+ #### -i, --initializer=INITIALIZER
60
+
61
+ Specify a Ruby source file to be evaluated after ActiveRecord models are defined, default is `$HOME/.arql.rb`, or `$HOME/.arql.d/init.rb` if exists.
62
+
63
+ #### -e, --env=ENVIRON
64
+
65
+ Specify an environment name which should be defined in config file.
66
+
67
+ #### -E, --eval=CODE
68
+
69
+ Specify a Ruby code fragment to be evaluated, if this option was specified, no Pry REPL will be launched.
70
+
71
+ #### -S, --show-sql
72
+
73
+ arql does not show SQL log by default, use this option to turn it on.
74
+
75
+ #### -w, --write-sql=OUTPUT
76
+
77
+ You can also let arql write SQL logs into a file use this option.
78
+
79
+ #### -A, --append-sql-OUTOUT
80
+
81
+ Like `-w`, but without file content truncation.
82
+
83
+ #### DB options
84
+
85
+ Options described in this section typically should be configured in the config file, these options are just shortcuts of
86
+ the corresponding configurations in case of that you want modify some configuration items on CLI directly.
87
+
88
+ ##### -a, --db-adapter=DB_ADAPTER
89
+
90
+ Specify DB adapter, available values:
91
+
92
+ + `mysql2`
93
+ + `postgresql`
94
+ + `sqlite3`
95
+ + `sqlserver`
96
+ + `oracle_enhanced`
97
+
98
+ ##### -h, --db-host=DB_HOST
99
+
100
+ Specify DB host
101
+
102
+ ##### -p, --db-port=DB_PORT
103
+
104
+ Specify DB port
105
+
106
+ ##### -d, --db-name=DB_NAME
107
+
108
+ Specify DB name
109
+
110
+ ##### -u, --db-user=DB_USER
111
+
112
+ Specify DB username
113
+
114
+ ##### -P, --db-password=DB_PASSWORD
115
+
116
+ Specify DB password
117
+
118
+ ##### -n, --db-encoding=DB_ENCODING
119
+
120
+ Specify DB character encoding, default is `utf8`
121
+
122
+ ##### -o, --db-pool=DB_POOL
123
+
124
+ Specify size of DB connection pool, default is `5`
125
+
126
+ ##### -H, --ssh-host=SSH_HOST
127
+
128
+ Specify ssh host for ssh proxy
129
+
130
+ ##### -O, --ssh-port=SSH_PORT
131
+
132
+ Specify ssh port for ssh proxy
133
+
134
+ ##### -U, --ssh-user=SSH_USER
135
+
136
+ Specify ssh username for ssh proxy
137
+
138
+ ##### -W, --ssh-password=SSH_PASSWORD
139
+
140
+ Specify ssh password for ssh proxy
141
+
142
+ ##### -LSSH_LOCAL_PORT
143
+
144
+ Specify local port for ssh proxy, default is a _random_ port
145
+
146
+ ### Config file
147
+
148
+ The config file typically is as same as a Rails database config file, but with several additional config options.
149
+
150
+ #### Additional configurations
151
+
152
+ 1. `created_at`: An array contains customized column names for the ActiveRecord `created_at` field, default value is `created_at`, value of the column will be filled with current time stamp when created if specified
153
+ 2. `updated_at`: An array contains customized column names for the ActiveRecord `updated_at` field, default value is `updated_at`, value of the column will be filled with current time stamp when updated if specified
154
+ 3. `ssh.host`: host of ssh proxy
155
+ 4. `ssh.port`: port of ssh proxy
156
+ 5. `ssh.user`: username of ssh proxy
157
+ 6. `ssh.password`: password of ssh proxy
158
+ 7. `ssh.local_port`: local port of ssh proxy
159
+
160
+ #### Config Example
161
+
162
+ ```
163
+ default: &default
164
+ adapter: mysql2
165
+ encoding: utf8
166
+ created_at: ["gmt_created"]
167
+ updated_at: ["gmt_modified"]
168
+
169
+ local:
170
+ <<: *default
171
+ username: root
172
+ database: blog
173
+ password:
174
+ socket: /tmp/mysql.sock
175
+
176
+ dev:
177
+ <<: *default
178
+ host: devdb.mycompany.com
179
+ port: 3306
180
+ username: root
181
+ password: 123456
182
+ database: blog
183
+ ssh:
184
+ host: dev.mycompany.com
185
+ port: 22
186
+ user: deploy
187
+ password: 12345678
188
+ local_port: 3307
189
+ ```
190
+
191
+ ### Use as a REPL
192
+
193
+ If neither [ruby file] nor -e option specified, and STDIN is not a tty, a Pry REPL will be launched with pry-byebug loaded.
194
+
195
+ Arql provides some Pry commands:
196
+
197
+ #### info
198
+
199
+ The `info` command prints current DB connection information and SSH proxy information, e.g.:
200
+
201
+ ```
202
+ Database Connection Information:
203
+ Host:
204
+ Port:
205
+ Username: root
206
+ Password:
207
+ Database: test
208
+ Adapter: mysql2
209
+ Encoding: utf8
210
+ Pool Size: 5
211
+ ```
212
+
213
+ #### m
214
+
215
+ The `m` command print all table names with corresponding model class, and abbr class names, e.g.:
216
+
217
+ ```
218
+ +-----------------|----------------|------+
219
+ | Table Name | Model Class | Abbr |
220
+ +-----------------|----------------|------+
221
+ | all_songs | AllSongs | AS |
222
+ | datetypes | Datetypes | D |
223
+ | hello | Hello | H |
224
+ | permission | Permission | P |
225
+ | permission_role | PermissionRole | PR |
226
+ | person | Person | |
227
+ | role | Role | R |
228
+ | role_user | RoleUser | RU |
229
+ | test | Test | T |
230
+ | user | User | U |
231
+ +-----------------|----------------|------+
232
+ ```
233
+
234
+ The `m` command has an alias: `l`
235
+
236
+ #### t
237
+
238
+ Given a table name or model class, the `t` command prints the table's definition information.
239
+
240
+ ```
241
+ Table: person
242
+ +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
243
+ | PK | Name | SQL Type | Ruby Type | Limit | Precision | Scale | Default | Nullable | Comment |
244
+ +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
245
+ | Y | id | int(11) unsigned | integer | 4 | | | | false | |
246
+ | | name | varchar(64) | string | 64 | | | | true | |
247
+ | | age | int(11) | integer | 4 | | | | true | |
248
+ | | gender | int(4) | integer | 4 | | | | true | |
249
+ | | grade | int(4) | integer | 4 | | | | true | |
250
+ | | blood_type | varchar(4) | string | 4 | | | | true | |
251
+ +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
252
+ ```
253
+
254
+ #### show-sql / hide-sql
255
+
256
+ This pair of commands toggle display of SQL logs in Pry REPL.
257
+
258
+ #### reconnect
259
+
260
+ The `reconnect` command just simply reconnects current DB connection.
261
+
262
+ #### redefine
263
+
264
+ The `redefine` command redefines ActiveRecord model classes from DB tables informations.
265
+
266
+ ### Use as code interpreter
267
+
268
+ If a ruby file is specified as command line argument, or the `-e` option is specified, or STDIN is a tty, then no Pry
269
+ REPL will be launched, instead, it evaluates the file or code fragment specified, just after model class definition is
270
+ done. You can think this usage as the `runner` sub-command of `rails` command.
271
+
272
+ ### Additional extension methods
273
+
274
+ #### to_insert_sql / to_upsert_sql
275
+
276
+ You can call `to_insert_sql` / `to_upsert_sql` on any ActiveRecord model instance to get a insert or upsert SQL of the object.
277
+
278
+ These tow methods are also available on any array object which contains only ActiveRecord model instance objects.
279
+
280
+ ```
281
+ ARQL ❯ Person.all.to_a.to_insert_sql
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
+ ```
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
+
289
+ #### t
290
+
291
+ You can call `t` method on any ActiveRecord model instance to print a pretty table of attributes names and values of the object.
292
+
293
+ ```
294
+ ARQL ❯ Person.last.t
295
+ +----------------|-----------------|------------------|---------+
296
+ | Attribute Name | Attribute Value | SQL Type | Comment |
297
+ +----------------|-----------------|------------------|---------+
298
+ | id | 11 | int(11) unsigned | |
299
+ | name | Jackson | varchar(64) | |
300
+ | age | 30 | int(11) | |
301
+ | gender | 2 | int(4) | |
302
+ | grade | 2 | int(4) | |
303
+ | blood_type | AB | varchar(4) | |
304
+ +----------------|-----------------|------------------|---------+
305
+ ```
306
+
307
+ #### v
308
+
309
+ The `v` method is for integration with Emacs org babel.
310
+
311
+ #### v for ActiveRecord instances
312
+
313
+ Call `v` method on any ActiveRecord model instance to print an Array which first element is `['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']`, and the second is `nil`, and the rest elements are attribute names and values of the object. In Emacs org-mode, is `:result` type is `value`(the default), this return value will be rendered as a pretty table.
314
+
315
+ ```
316
+ ARQL ❯ Person.last.v
317
+ => [["Attribute Name", "Attribute Value", "SQL Type", "Comment"],
318
+ nil,
319
+ ["id", 11, "int(11) unsigned", ""],
320
+ ["name", "Jackson", "varchar(64)", ""],
321
+ ["age", 30, "int(11)", ""],
322
+ ["gender", 2, "int(4)", ""],
323
+ ["grade", 2, "int(4)", ""],
324
+ ["blood_type", "AB", "varchar(4)", ""]]
325
+ ```
326
+
327
+ #### v for array
328
+
329
+ The `v` method is also available for arrays:
330
+
331
+ #### Array which only contains ActiveRecord instances
332
+
333
+ ```
334
+ ARQL ❯ Person.all.to_a.v
335
+ => [["id", "name", "age", "gender", "grade", "blood_type"],
336
+ nil,
337
+ [1, "Jack", 30, nil, nil, nil],
338
+ [2, "Jack", 11, 1, nil, nil],
339
+ [3, "Jack", 12, 1, nil, nil],
340
+ [4, "Jack", 30, 1, nil, nil],
341
+ [5, "Jack", 12, 2, nil, nil],
342
+ [6, "Jack", 2, 2, 2, nil],
343
+ [7, "Jack", 3, 2, 2, nil],
344
+ [8, "Jack", 30, 2, 2, "AB"],
345
+ [9, "Jack", 30, 2, 2, "AB"],
346
+ [10, "Jack", 30, 2, 2, "AB"],
347
+ [11, "Jackson", 30, 2, 2, "AB"]]
348
+ ```
349
+
350
+ #### Array which only contains same-structured Hash objects
351
+
352
+ ```
353
+ ARQL ❯ arr = [{name: 'Jack', age: 10}, {name: 'Lucy', age: 20}]
354
+ => [{:name=>"Jack", :age=>10}, {:name=>"Lucy", :age=>20}]
355
+ ARQL ❯ arr.v
356
+ => [[:name, :age], nil, ["Jack", 10], ["Lucy", 20]]
357
+ ```
358
+
359
+ #### sql
360
+
361
+ Use `sql` method to execute raw SQL statements:
362
+
363
+ ```
364
+ ARQL ❯ rs = sql 'select count(0) from person;'
365
+ => #<ActiveRecord::Result:0x00007fd1f8026ad0 @column_types={}, @columns=["count(0)"], @hash_rows=nil, @rows=[[11]]>
366
+ ARQL ❯ rs.rows
367
+ => [[11]]
368
+ ```
369
+
370
+ #### JSON convertion and prints
371
+
372
+ Call `j` on any object to get JSON presentation of it, and `jj` to get pretty-printed JSON presentation.
373
+
374
+ Use `jp` to print JSON, `jjp` to pretty print.
375
+
376
+ #### String#p
377
+
378
+ The `p` methods is defined as:
379
+
380
+ ```
381
+ class String
382
+ def p
383
+ puts self
384
+ end
385
+ end
386
+ ```
387
+
388
+ #### $C
389
+
390
+ Arql assigns `ActiveRecord::Base.connection` object to the global available `$C`
391
+
392
+ The `sql` method in above description is actually `$C.exec_query` in fact, and other methods of `$C` is also pretty helpful:
393
+
394
+ ##### Create a table
395
+
396
+ ```
397
+ ARQL ❯ $C.create_table :post, id: false, primary_key: :id do |t|
398
+ ARQL ❯ t.column :id, :bigint, precison: 19, comment: 'ID'
399
+ ARQL ❯ t.column :name, :string, comment: '名称'
400
+ ARQL ❯ t.column :gmt_created, :datetime, comment: '创建时间'
401
+ ARQL ❯ t.column :gmt_modified, :datetime, comment: '最后修改时间'
402
+ ARQL ❯ end
403
+ ```
404
+
405
+ ##### Add a column
406
+
407
+ ```
408
+ $C.add_column :post, :note, :string, comment: '备注'
409
+ ```
410
+
411
+ ##### Modify a column
412
+
413
+ ```
414
+ $C.change_column :post, :note, :text, comment: '备注'
415
+ ```
416
+
417
+ ##### Delete a column
418
+
419
+ ```
420
+ $C.remove_column :post, :note
421
+ ```
422
+ ##### Delete a table
423
+
424
+ ```
425
+ $C.drop_table :post
426
+ ```
427
+
428
+ ##### Add an index
429
+
430
+ ```
431
+ ARQL ❯ $C.add_index :post, :name
432
+ ARQL ❯ $C.add_index(:accounts, [:branch_id, :party_id], unique: true, name: 'by_branch_party')
433
+ ```
434
+
435
+ ### Use with Emacs org babel
436
+
437
+ Here is a [ob-arql](https://github.com/lululau/spacemacs-layers/blob/master/ob-arql/local/ob-arql/ob-arql.el) for integration with Emacs org babel.
438
+
439
+ ## Development
440
+
441
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
442
+
443
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
444
+
445
+ ## Contributing
446
+
447
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lululau/arql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/lululau/arql/blob/master/CODE_OF_CONDUCT.md).
448
+
449
+
450
+ ## License
451
+
452
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
453
+
454
+ ## Code of Conduct
455
+
456
+ Everyone interacting in the Arql project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lululau/arql/blob/master/CODE_OF_CONDUCT.md).