dba 2.0.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +16 -0
- data/dba.gemspec +1 -1
- data/lib/dba/command.rb +12 -0
- data/lib/dba/database.rb +12 -2
- data/lib/dba/dump.rb +2 -0
- data/lib/dba/load.rb +3 -1
- data/lib/dba/sample.rb +1 -1
- data/lib/dba/shell.rb +1 -5
- data/lib/dba.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff91c96a26c84120b2294eaceafbc9cd97d50ae7b8138ed08657efe355fe905b
|
4
|
+
data.tar.gz: 1e25615aea3aab8f5820f790d038363ea2854488e950d3925e48953d1055006c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b77b8fe626319fe20ac77cb31bb5bd2ed349438ea76ef6472b7367e22a804d1027a99744bde3ad2e32e7104f88a52b125a49f32c40223095281f648f150c8f64
|
7
|
+
data.tar.gz: 21d2f2a661aacc27375c7e9031c1057471ca627f0fb1bcb2c47dc051096e9d15d507d186854bb2fbac2b9851ba63ef2c807d7f91814ecd9490c564c6e073bdf1
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# 2.2.0
|
2
|
+
|
3
|
+
* Fixed compatibility with psych 4+
|
4
|
+
|
5
|
+
* The sample command now excludes nil/null values
|
6
|
+
|
7
|
+
|
8
|
+
# 2.1.0
|
9
|
+
|
10
|
+
* Fixed arity check for commands with optional arguments
|
11
|
+
|
12
|
+
* Added support for .jsonl extension to dump and load commands
|
13
|
+
|
14
|
+
* Added support for .ndjson extension to dump and load commands
|
15
|
+
|
16
|
+
|
1
17
|
# 2.0.0
|
2
18
|
|
3
19
|
* **Required ruby version is now 2.5.0**
|
data/dba.gemspec
CHANGED
data/lib/dba/command.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
class DBA::Command
|
2
|
+
def self.arity_check(args)
|
3
|
+
parameters = instance_method(:call).parameters
|
4
|
+
|
5
|
+
required, optional = parameters.partition { |(type, name)| type == :req }
|
6
|
+
|
7
|
+
expected = optional.empty? ? required.size : (required.size .. required.size + optional.size)
|
8
|
+
|
9
|
+
unless expected === args.size
|
10
|
+
raise DBA::Error, "incorrect number of arguments (given #{args.size}, expected #{expected})"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
2
14
|
def initialize(database)
|
3
15
|
self.database = database
|
4
16
|
end
|
data/lib/dba/database.rb
CHANGED
@@ -64,12 +64,22 @@ module DBA::Database
|
|
64
64
|
File.exist?('.env')
|
65
65
|
end
|
66
66
|
|
67
|
+
def database_config_path
|
68
|
+
File.join('config', 'database.yml')
|
69
|
+
end
|
70
|
+
|
67
71
|
def database_config?
|
68
|
-
File.exist?(
|
72
|
+
File.exist?(database_config_path)
|
69
73
|
end
|
70
74
|
|
71
75
|
def database_config
|
72
|
-
|
76
|
+
source = ERB.new(File.read(database_config_path)).result
|
77
|
+
|
78
|
+
if YAML.respond_to?(:unsafe_load)
|
79
|
+
YAML.unsafe_load(source)
|
80
|
+
else
|
81
|
+
YAML.load(source)
|
82
|
+
end
|
73
83
|
end
|
74
84
|
|
75
85
|
def development_database_args
|
data/lib/dba/dump.rb
CHANGED
data/lib/dba/load.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
class DBA::Load < DBA::Command
|
4
4
|
ADAPTERS = {
|
5
5
|
'.csv' => :CSV,
|
6
|
+
'.jsonl' => :LDJSON,
|
6
7
|
'.ldjson' => :LDJSON,
|
8
|
+
'.ndjson' => :LDJSON,
|
7
9
|
'.yml' => :YAML,
|
8
10
|
'.yaml' => :YAML
|
9
11
|
}
|
@@ -26,7 +28,7 @@ class DBA::Load < DBA::Command
|
|
26
28
|
|
27
29
|
def file_list(path)
|
28
30
|
if File.directory?(path)
|
29
|
-
Dir.glob(File.join(path, '*.{csv,ldjson,yml,yaml}'))
|
31
|
+
Dir.glob(File.join(path, '*.{csv,jsonl,ldjson,ndjson,yml,yaml}'))
|
30
32
|
else
|
31
33
|
[path]
|
32
34
|
end
|
data/lib/dba/sample.rb
CHANGED
@@ -5,7 +5,7 @@ class DBA::Sample < DBA::Command
|
|
5
5
|
column_name = column.to_sym if column
|
6
6
|
|
7
7
|
if column_name
|
8
|
-
dataset = database[table_name].distinct.select(column_name)
|
8
|
+
dataset = database[table_name].exclude(column_name => nil).distinct.select(column_name)
|
9
9
|
dataset.from_self.order(random_function).limit(20).each do |row|
|
10
10
|
puts row[column_name]
|
11
11
|
end
|
data/lib/dba/shell.rb
CHANGED
@@ -16,11 +16,7 @@ module DBA::Shell
|
|
16
16
|
|
17
17
|
command = DBA.const_get(command)
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
if arity >= 0 && args.size != arity
|
22
|
-
raise DBA::Error, "incorrect number of args (given #{args.size}, expected #{arity})"
|
23
|
-
end
|
19
|
+
command.arity_check(args)
|
24
20
|
|
25
21
|
database = DBA::Database.connect
|
26
22
|
|
data/lib/dba.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.10
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: See description
|