listen_sql 0.1.0 → 0.1.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 +4 -4
- data/exe/exec_sql +3 -21
- data/exe/listen_sql +5 -4
- data/lib/listen_sql/version.rb +1 -1
- data/lib/listen_sql.rb +19 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c54c83fcbf2176382bb77c8fc0c1b93a620ee5e
|
4
|
+
data.tar.gz: aae8823e8e3147e3d2043465d7a1af699062e101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fede8c8451607716012a5fc9f64b64f75e49c6f4e34c984285779d41b6e3fd2dbb5cfa0474639d6a2f2d07789d77f5f3b1e6d21000c2c9504f8c82b84cddef09
|
7
|
+
data.tar.gz: a47a5b39da00fbf5f13a6d28ccb4dc286e67d34382ee366f0a51e06ae255058863511c4da41f80c9b0a1666548daf62cf42855bcc9d77749eab3ae891869039e
|
data/exe/exec_sql
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'listen_sql'
|
5
5
|
|
6
6
|
def usage(message=nil)
|
7
7
|
text = <<-TEXT
|
@@ -26,27 +26,9 @@ def usage(message=nil)
|
|
26
26
|
puts text
|
27
27
|
end
|
28
28
|
|
29
|
-
def exec_sql(db_name, file, color: true)
|
30
|
-
puts "File: #{file}"
|
31
|
-
puts "Time: #{Time.now}"
|
32
|
-
|
33
|
-
# Show original SQL
|
34
|
-
puts "SQL: "
|
35
|
-
sql = File.read(file)
|
36
|
-
puts(color ? CodeRay.scan(sql, :sql).terminal : sql)
|
37
|
-
|
38
|
-
# Show Resultset
|
39
|
-
puts "Rows: "
|
40
|
-
puts `psql #{db_name} < #{Shellwords.escape file}`
|
41
|
-
end
|
42
|
-
|
43
|
-
def stop(message)
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
29
|
if $0 == __FILE__
|
48
30
|
db_name = ARGV.shift || usage('DBNAME should be first argument or set PGDATABASE in ENV!')
|
49
31
|
src = ARGV.shift || usage('SRC should be second argument!')
|
50
32
|
no_color = ARGV.detect{|a| a == '--no-color'}
|
51
|
-
exec_sql(db_name, src, color: !no_color)
|
33
|
+
ListenSql.exec_sql(db_name, src, color: !no_color)
|
52
34
|
end
|
data/exe/listen_sql
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
# Listens for any SQL file changes and executes them using the default PSQL
|
4
4
|
# settings.
|
5
5
|
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'listen_sql'
|
6
8
|
require 'listen'
|
7
|
-
require 'shellwords'
|
8
|
-
require 'coderay'
|
9
|
-
load File.join(__dir__, 'exec_sql')
|
10
9
|
|
11
10
|
def usage(message=nil)
|
12
11
|
text = <<-TEXT
|
@@ -28,11 +27,13 @@ db_name = ARGV.shift || ENV['PGDATABASE'] || usage('DBNAME should be second argu
|
|
28
27
|
|
29
28
|
listener = Listen.to(dir, only: /\.sql$/) do |modified, _|
|
30
29
|
modified.each do |file|
|
31
|
-
exec_sql(db_name, file, color: true)
|
30
|
+
ListenSql.exec_sql(db_name, file, color: true)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
34
|
if $0 == __FILE__
|
36
35
|
listener.start # not blocking
|
36
|
+
puts "Watching for changes to #{dir}"
|
37
|
+
puts "<CTRL-C> to quit"
|
37
38
|
sleep
|
38
39
|
end
|
data/lib/listen_sql/version.rb
CHANGED
data/lib/listen_sql.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'listen_sql/version'
|
2
|
+
|
3
|
+
require 'shellwords'
|
4
|
+
require 'coderay'
|
2
5
|
|
3
6
|
module ListenSql
|
4
|
-
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def exec_sql(db_name, file, color: true)
|
10
|
+
puts "File: #{file}"
|
11
|
+
puts "Time: #{Time.now}"
|
12
|
+
|
13
|
+
# Show original SQL
|
14
|
+
puts "SQL: "
|
15
|
+
sql = File.read(file)
|
16
|
+
puts(color ? CodeRay.scan(sql, :sql).terminal : sql)
|
17
|
+
|
18
|
+
# Show Resultset
|
19
|
+
puts "Rows: "
|
20
|
+
puts `psql #{db_name} < #{Shellwords.escape file}`
|
21
|
+
end
|
5
22
|
end
|