@@ -7,14 +7,14 @@ module PgCodegen
7
7
GetAuthorSql = %q(SELECT id, name, bio FROM authors
8
8
WHERE id = $1 LIMIT 1)
9
9
10
- GetAuthorRow = Struct . new ( :id , :name , :bio )
10
+ GetAuthorRow = Data . define ( :id , :name , :bio )
11
11
12
- GetAuthorArgs = Struct . new ( :id )
12
+ GetAuthorArgs = Data . define ( :id )
13
13
14
14
ListAuthorsSql = %q(SELECT id, name, bio FROM authors
15
15
ORDER BY name)
16
16
17
- ListAuthorsRow = Struct . new ( :id , :name , :bio )
17
+ ListAuthorsRow = Data . define ( :id , :name , :bio )
18
18
19
19
CreateAuthorSql = %q(INSERT INTO authors (
20
20
name, bio
@@ -23,19 +23,19 @@ module PgCodegen
23
23
)
24
24
RETURNING id, name, bio)
25
25
26
- CreateAuthorRow = Struct . new ( :id , :name , :bio )
26
+ CreateAuthorRow = Data . define ( :id , :name , :bio )
27
27
28
- CreateAuthorArgs = Struct . new ( :name , :bio )
28
+ CreateAuthorArgs = Data . define ( :name , :bio )
29
29
30
30
DeleteAuthorSql = %q(DELETE FROM authors
31
31
WHERE id = $1)
32
32
33
- DeleteAuthorArgs = Struct . new ( :id )
33
+ DeleteAuthorArgs = Data . define ( :id )
34
34
35
35
TestSql = %q(SELECT c_bit, c_smallint, c_boolean, c_integer, c_bigint, c_serial, c_decimal, c_numeric, c_real, c_double_precision, c_date, c_time, c_timestamp, c_char, c_varchar, c_bytea, c_text, c_json FROM node_postgres_types
36
36
LIMIT 1)
37
37
38
- TestRow = Struct . new (
38
+ TestRow = Data . define (
39
39
:c_bit ,
40
40
:c_smallint ,
41
41
:c_boolean ,
@@ -58,9 +58,7 @@ module PgCodegen
58
58
59
59
class QuerySql
60
60
def initialize ( connection_pool_params , pg_params )
61
- @pool = ConnectionPool . new (
62
- **connection_pool_params
63
- ) {
61
+ @pool = ConnectionPool . new ( **connection_pool_params ) {
64
62
client = PG . connect ( **pg_params )
65
63
client . type_map_for_results = PG ::BasicTypeMapForResults . new client
66
64
client
@@ -78,11 +76,7 @@ def get_author(get_author_args)
78
76
result = client . exec_prepared ( 'get_author' , query_params )
79
77
row = result . first
80
78
return nil if row . nil?
81
- entity = GetAuthorRow . new (
82
- row [ 'id' ]
83
- row [ 'name' ]
84
- row [ 'bio' ]
85
- )
79
+ entity = GetAuthorRow . new ( row [ 'id' ] , row [ 'name' ] , row [ 'bio' ] )
86
80
return entity
87
81
end
88
82
end
@@ -96,11 +90,7 @@ def list_authors
96
90
result = client . exec_prepared ( 'list_authors' )
97
91
entities = [ ]
98
92
result . each do |row |
99
- entities << ListAuthorsRow . new (
100
- row [ 'id' ]
101
- row [ 'name' ]
102
- row [ 'bio' ]
103
- )
93
+ entities << ListAuthorsRow . new ( row [ 'id' ] , row [ 'name' ] , row [ 'bio' ] )
104
94
end
105
95
return entities
106
96
end
@@ -116,11 +106,7 @@ def create_author(create_author_args)
116
106
result = client . exec_prepared ( 'create_author' , query_params )
117
107
row = result . first
118
108
return nil if row . nil?
119
- entity = CreateAuthorRow . new (
120
- row [ 'id' ]
121
- row [ 'name' ]
122
- row [ 'bio' ]
123
- )
109
+ entity = CreateAuthorRow . new ( row [ 'id' ] , row [ 'name' ] , row [ 'bio' ] )
124
110
return entity
125
111
end
126
112
end
@@ -146,23 +132,23 @@ def test
146
132
row = result . first
147
133
return nil if row . nil?
148
134
entity = TestRow . new (
149
- row [ 'c_bit' ]
150
- row [ 'c_smallint' ]
151
- row [ 'c_boolean' ]
152
- row [ 'c_integer' ]
153
- row [ 'c_bigint' ]
154
- row [ 'c_serial' ]
155
- row [ 'c_decimal' ]
156
- row [ 'c_numeric' ]
157
- row [ 'c_real' ]
158
- row [ 'c_double_precision' ]
159
- row [ 'c_date' ]
160
- row [ 'c_time' ]
161
- row [ 'c_timestamp' ]
162
- row [ 'c_char' ]
163
- row [ 'c_varchar' ]
164
- row [ 'c_bytea' ]
165
- row [ 'c_text' ]
135
+ row [ 'c_bit' ] ,
136
+ row [ 'c_smallint' ] ,
137
+ row [ 'c_boolean' ] ,
138
+ row [ 'c_integer' ] ,
139
+ row [ 'c_bigint' ] ,
140
+ row [ 'c_serial' ] ,
141
+ row [ 'c_decimal' ] ,
142
+ row [ 'c_numeric' ] ,
143
+ row [ 'c_real' ] ,
144
+ row [ 'c_double_precision' ] ,
145
+ row [ 'c_date' ] ,
146
+ row [ 'c_time' ] ,
147
+ row [ 'c_timestamp' ] ,
148
+ row [ 'c_char' ] ,
149
+ row [ 'c_varchar' ] ,
150
+ row [ 'c_bytea' ] ,
151
+ row [ 'c_text' ] ,
166
152
row [ 'c_json' ]
167
153
)
168
154
return entity
0 commit comments