pg_json 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. data/bin/pg_json +41 -14
  2. metadata +1 -1
data/bin/pg_json CHANGED
@@ -4,27 +4,55 @@ require "sequel"
4
4
 
5
5
  DB = Sequel.connect "postgres://#{ARGV.slice!(0)}", :logger => nil, :max_connections => 1
6
6
 
7
- def unquoted(type)
7
+ def simple(type, &block)
8
+
9
+ block = lambda do
10
+ "data::text"
11
+ end unless block
12
+
8
13
  puts <<-EOF
9
14
  create or replace function to_json(data #{type}) returns text as $$
10
15
  begin
11
- return (case when data is null then 'null' else data::text end);
16
+ return (case when data is null then 'null' else #{block.call} end);
12
17
  end;
13
18
  $$ language plpgsql;
14
19
  EOF
15
20
  array(type)
16
21
  end
17
22
 
18
- def quoted(type)
19
- puts <<-EOF
20
- create or replace function to_json(data #{type}) returns text as $$
21
- begin
22
- return (case when data is null then 'null' else '"'||data::text||'"' end);
23
- end;
24
- $$ language plpgsql;
25
- EOF
26
- array(type)
23
+ simple :integer
24
+ simple :float
25
+ simple :text do
26
+ "'"'||data::text||'"'"
27
27
  end
28
+ simple :date do
29
+ "'"'||to_char(data, 'YYYY-MM-DD')::text||'"'"
30
+ end
31
+ simple :time do
32
+ "'"'||to_char(data, 'HH24:MI:SS')::text||'"'"
33
+ end
34
+
35
+ # def unquoted(type)
36
+ # puts <<-EOF
37
+ # create or replace function to_json(data #{type}) returns text as $$
38
+ # begin
39
+ # return (case when data is null then 'null' else data::text end);
40
+ # end;
41
+ # $$ language plpgsql;
42
+ # EOF
43
+ # array(type)
44
+ # end
45
+ #
46
+ # def quoted(type)
47
+ # puts <<-EOF
48
+ # create or replace function to_json(data #{type}) returns text as $$
49
+ # begin
50
+ # return (case when data is null then 'null' else '"'||data::text||'"' end);
51
+ # end;
52
+ # $$ language plpgsql;
53
+ # EOF
54
+ # array(type)
55
+ # end
28
56
 
29
57
  def composite(type)
30
58
  sql = <<-SQL
@@ -80,7 +108,6 @@ $$ language plpgsql;
80
108
  EOF
81
109
  end
82
110
 
83
- while entry = ARGV.slice!(0)
84
- typeFun, typeName = entry.split(":")
85
- send(typeFun.to_sym, typeName.to_sym)
111
+ while composite = ARGV.slice!(0)
112
+ send :composite, composite.to_sym
86
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: