arql 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3180e4c8b35e489b880dd97da124ee8f3879ee68407059f9225b6fb25442a752
4
- data.tar.gz: 1092f95cfad6cd95cde554771ae1b8c23b43bc30e7de65ed75a06a3af9d59565
3
+ metadata.gz: dfa69341937ac1de34d54c8d3506759fd4979d59cc4d52333726cd8ba04fb346
4
+ data.tar.gz: 4e65c0ea33d4c45c52e166839fdd777280d62d8b0c7127f8cb75760c0cfd230d
5
5
  SHA512:
6
- metadata.gz: e072ba0a087c5e4d7a9b241ed78c22c2cf414173230ce29b92221af987e5f0f4ff9caa2005f219fac9c40f95b08801dbde1cb0295eddb807b70113b1f10d4ece
7
- data.tar.gz: c8cec8884c51d10d8a2d3bc2673ab15dbd5c02f3b30b472a7765b91f5d1f4c6bd9c87b00f2acaeff01e3845b6e0edb79ecf84b79802a51f91034cc14f3895404
6
+ metadata.gz: 3c1ac9cbcf12be0ca4c48040a7f7e007b72f09932ef26ec4a4b40ac168a10ce04771a8587bfc25800b21166975204a986c6c2265269dfe2953bc90cf16608c7f
7
+ data.tar.gz: efe8de33f0365fcf871c0a160ddabeb4064e216a63fee7b9918af715d60dfd099e1881a124f8277d95e8ccb5c79df43eadfd660fa75f09f8f41c37806ce2e2f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.4.0)
4
+ arql (0.4.1)
5
5
  activerecord (>= 6.1.5, < 7.1.0)
6
6
  activesupport (>= 6.1.5, < 7.1.0)
7
7
  caxlsx (~> 3.3.0)
data/README-zh_CN.org CHANGED
@@ -338,55 +338,6 @@
338
338
  l -c no|num # 只显示字段名、字段注释中包含 no 或 num 的字段信息
339
339
  #+END_EXAMPLE
340
340
 
341
- **** =t=
342
-
343
- =t= 命令接受一个表名或模型类名作为参数,打印表的定义信息,例如:
344
-
345
- 执行 =t Person= 命令会打印 =person= 表的定义信息:
346
-
347
- #+begin_example
348
- Table: person
349
- +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
350
- | PK | Name | SQL Type | Ruby Type | Limit | Precision | Scale | Default | Nullable | Comment |
351
- +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
352
- | Y | id | int(11) unsigned | integer | 4 | | | | false | |
353
- | | name | varchar(64) | string | 64 | | | | true | |
354
- | | age | int(11) | integer | 4 | | | | true | |
355
- | | gender | int(4) | integer | 4 | | | | true | |
356
- | | grade | int(4) | integer | 4 | | | | true | |
357
- | | blood_type | varchar(4) | string | 4 | | | | true | |
358
- +----|------------|------------------|-----------|-------|-----------|-------|---------|----------|---------+
359
- #+end_example
360
-
361
- 另外, =t= 同时也是模型类的一个类方法,执行 =Person.t= 会同样会打印出上述信息。
362
-
363
- 其中:
364
-
365
- - =PK= : 是否为主键
366
- - =Name= : 列名
367
- - =SQL Type= : 数据库类型
368
- - =Ruby Type= : Ruby 类型
369
- - =Limit= : 长度限制
370
- - =Precision= : 精度
371
- - =Scale= : 小数位数
372
- - =Default= : 默认值
373
- - =Nullable= : 是否可为空
374
- - =Comment= : 注释
375
-
376
- **** =vd=
377
-
378
- =t= 命令在终端中以表格的形式打印表的定义信息,缺点是如果表的列数过多,会导致表格这行,不方便查看。而 =vd=
379
- (visidata) 是一个使用 Python 编写的终端数据分析工具,可以在终端中以表格的形式打印表的定义信息,但是支持水平滚动,方
380
- 便查看。
381
-
382
- 如果要使用 Arql 的 =vd= 命令,需要先安装 =visidata=:
383
-
384
- #+begin_src sh
385
- pipx install visidata
386
- #+end_src
387
-
388
- =vd= 命令和用法和 =t= 命令基本相同,另外, =Array= / =ActiveRecord::Base= 等对象也可以使用 =vd= 方法。
389
-
390
341
  **** =show-sql= / =hide-sql=
391
342
 
392
343
  这对命令可以切换 Pry REPL 中 SQL 日志的显示。
@@ -823,17 +774,13 @@
823
774
  =t= 方法还可以在包含 ActiveRecord 实例的数组上调用,也可以在 =ActiveRecord::Relation= / =ActiveRecord::Result= / =Ransack::Search= 对象上调用。
824
775
 
825
776
  #+begin_example
826
- ARQL ❯ Person.last.t
827
- +----------------|-----------------|------------------|---------+
828
- | Attribute Name | Attribute Value | SQL Type | Comment |
829
- +----------------|-----------------|------------------|---------+
830
- | id | 11 | int(11) unsigned | |
831
- | name | Jackson | varchar(64) | |
832
- | age | 30 | int(11) | |
833
- | gender | 2 | int(4) | |
834
- | grade | 2 | int(4) | |
835
- | blood_type | AB | varchar(4) | |
836
- +----------------|-----------------|------------------|---------+
777
+ ARQL ❯ Person.last(2).t
778
+ +----+----------+--------+----------------------------------+-------+------+---------------------------+---------------------------+
779
+ | id | name | gender | id_no | phone | note | gmt_created | gmt_modified |
780
+ +----+----------+--------+----------------------------------+-------+------+---------------------------+---------------------------+
781
+ | 90 | Zhangsan | M | f09288fb381cc47dd2e56389cf15f0bf | | | 2021-04-26 15:32:05 +0800 | 2021-04-26 15:32:05 +0800 |
782
+ | 91 | Lisi | F | fb6fea4b23b1d3c54739774946246e4c | | | 2021-04-26 15:32:05 +0800 | 2021-04-26 15:32:05 +0800 |
783
+ +----+----------+--------+----------------------------------+-------+------+---------------------------+---------------------------+
837
784
  #+end_example
838
785
 
839
786
  作为数组和「类数组」对象实例方法时, =t= 方法可以接受多个用于过滤属性的参数,参数的类型可以是:
@@ -841,10 +788,10 @@
841
788
  + 字符串或 Symbol,对属性进行字面量匹配
842
789
  + 正则表达式,对属性进行正则匹配
843
790
 
844
- 例如, 只显示 =name=, =age= 以及所有名称包含 =time= 字样的属性:
791
+ 例如, 只显示 =name=, =gender= 以及所有名称包含 =time= 字样的属性:
845
792
 
846
793
  #+begin_example
847
- ARQL ❯ Person.last(10).t('name', :age, /time/i)
794
+ ARQL ❯ Person.last(2).t('name', :gender, /time/i)
848
795
  #+end_example
849
796
 
850
797
  作为数组和「类数组」对象的实例方法的 =t= 还可以接受以下三个选项:
@@ -852,7 +799,7 @@
852
799
  + =:except= 选项,用于指定不显示的属性名,值可以是字符串或正则表达式,例如:
853
800
  #+BEGIN_EXAMPLE
854
801
  Person.last(10).t(except: 'id')
855
- Student.where(condition).t(except: /id|name/)
802
+ Student.where(condition).t(except: /id|gender/)
856
803
  #+END_EXAMPLE
857
804
  + =:compact= 选项,用于指定是否紧凑显示,值可以是 =true= 或 =false= ,如果启用紧凑显示,那些值全部为 =NULL= 的列将不
858
805
  会显示,这对于查看那些数据稀疏的表很有帮助,例如:
@@ -990,95 +937,6 @@
990
937
  id = ID.uuid # 生成一个 UUID
991
938
  #+END_EXAMPLE
992
939
 
993
- *** $C 全局变量
994
-
995
- Arql 将 =ActiveRecord::Base.connection= 对象赋值给全局可用的 =$C= 全局变量,它代表当前的数据库连接。
996
-
997
- 上文中的 =q= 方法实际上是 =$C.exec_query= 方法, =$C= 对象的其他方法也很有用:
998
-
999
- **** 创建表
1000
- #+begin_example
1001
- ARQL ❯ $C.create_table :post, id: false, primary_key: :id do |t|
1002
- ARQL ❯ t.column :id, :bigint, precison: 19, comment: 'ID'
1003
- ARQL ❯ t.column :name, :string, comment: '名称'
1004
- ARQL ❯ t.column :gmt_created, :datetime, comment: '创建时间'
1005
- ARQL ❯ t.column :gmt_modified, :datetime, comment: '最后修改时间'
1006
- ARQL ❯ end
1007
- #+end_example
1008
-
1009
- =create_table= 同样也被加入到 =Kernel= 下面,所以也可以直接调用 =create_table= 方法:
1010
-
1011
- #+begin_example
1012
- ARQL ❯ create_table :post, id: false, primary_key: :id do |t|
1013
- ARQL ❯ t.column :id, :bigint, precison: 19, comment: 'ID'
1014
- ARQL ❯ t.column :name, :string, comment: '名称'
1015
- ARQL ❯ t.column :gmt_created, :datetime, comment: '创建时间'
1016
- ARQL ❯ t.column :gmt_modified, :datetime, comment: '最后修改时间'
1017
- ARQL ❯ end
1018
- #+end_example
1019
-
1020
- **** 添加字段
1021
-
1022
- #+begin_example
1023
- $C.add_column :post, :note, :string, comment: '备注'
1024
- #+end_example
1025
-
1026
- =add_column= 也被加入到模型类的类方法中,所以也可以直接在模型类上调用 =add_column= 方法:
1027
-
1028
- #+begin_example
1029
- Post.add_column :note, :string, comment: '备注'
1030
- #+end_example
1031
-
1032
- **** 修改字段
1033
-
1034
- #+begin_example
1035
- $C.change_column :post, :note, :text, comment: '备注'
1036
- #+end_example
1037
-
1038
- =change_column= 也被加入到模型类的类方法中,所以也可以直接在模型类上调用 =change_column= 方法:
1039
-
1040
- #+begin_example
1041
- Post.change_column :note, :text, comment: '备注'
1042
- #+end_example
1043
-
1044
- **** 删除字段
1045
-
1046
- #+begin_example
1047
- $C.remove_column :post, :note
1048
- #+end_example
1049
-
1050
- =remove_column= 也被加入到模型类的类方法中,所以也可以直接在模型类上调用 =remove_column= 方法:
1051
-
1052
- #+begin_example
1053
- Post.remove_column :note
1054
- #+end_example
1055
-
1056
- **** 删除表
1057
-
1058
- #+begin_example
1059
- $C.drop_table :post
1060
- #+end_example
1061
-
1062
- =drop_table= 也被加入到模型类的类方法中,所以也可以直接在模型类上调用 =drop_table= 方法:
1063
-
1064
- #+begin_example
1065
- Post.drop_table
1066
- #+end_example
1067
-
1068
- **** 添加索引
1069
-
1070
- #+begin_example
1071
- ARQL ❯ $C.add_index :post, :name
1072
- ARQL ❯ $C.add_index(:accounts, [:branch_id, :party_id], unique: true, name: 'by_branch_party')
1073
- #+end_example
1074
-
1075
- =add_index= 也被加入到模型类的类方法中,所以也可以直接在模型类上调用 =add_index= 方法:
1076
-
1077
- #+begin_example
1078
- Post.add_index :name
1079
- Post.add_index [:branch_id, :party_id], unique: true, name: 'by_branch_party'
1080
- #+end_example
1081
-
1082
940
  *** 读写 Excel 和 CSV 文件
1083
941
 
1084
942
  Arql 集成了 =roo= 和 =caxlsx= 两个 Excel 库,提供了用于解析和生成 Excel 文件的方法。同时,Arql 也提供了用于读写 CSV 文件的方法。
@@ -1272,16 +1130,6 @@
1272
1130
  =no_create_table= 参数指定是否在 SQL 文件中包含创建表的语句,默认值为 =false= 。
1273
1131
 
1274
1132
 
1275
- **** 在全局连接对象 =$C= 上调用 dump 方法
1276
-
1277
- #+BEGIN_EXAMPLE
1278
- ARQL ❯ $C.dump 'path/to/dump.sql', no_create_db: false
1279
- #+END_EXAMPLE
1280
-
1281
- 这个方法会通过 mysqldump 命令把当前数据库中的所有表的数据导出到 SQL 文件中。
1282
-
1283
- =no_create_db= 参数指定是否在 SQL 文件中包含创建数据库的语句,默认值为 =false= 。
1284
-
1285
1133
  *** Plot
1286
1134
 
1287
1135
  Arql 集成了 Ruby 的 =youplot= 库,为 =Array= 添加了一些可以用来绘制图表的方法: