@@ -6,46 +6,46 @@ module Mysql2Codegen
6
6
GetAuthorSql = %q(SELECT id, name, bio FROM authors
7
7
WHERE id = ? LIMIT 1)
8
8
9
- GetAuthorRow = Data . define ( :id , :name , :bio )
9
+ GetAuthorRow = Struct . new ( :id , :name , :bio )
10
10
11
- GetAuthorArgs = Data . define ( :id )
11
+ GetAuthorArgs = Struct . new ( :id )
12
12
13
13
ListAuthorsSql = %q(SELECT id, name, bio FROM authors
14
14
ORDER BY name)
15
15
16
- ListAuthorsRow = Data . define ( :id , :name , :bio )
16
+ ListAuthorsRow = Struct . new ( :id , :name , :bio )
17
17
18
18
CreateAuthorSql = %q(INSERT INTO authors (
19
19
name, bio
20
20
) VALUES (
21
21
?, ?
22
22
))
23
23
24
- CreateAuthorArgs = Data . define ( :name , :bio )
24
+ CreateAuthorArgs = Struct . new ( :name , :bio )
25
25
26
26
UpdateAuthorSql = %q(UPDATE authors
27
27
SET bio = ?
28
28
WHERE id = ?)
29
29
30
- UpdateAuthorArgs = Data . define ( :bio , :id )
30
+ UpdateAuthorArgs = Struct . new ( :bio , :id )
31
31
32
32
CreateAuthorReturnIdSql = %q(INSERT INTO authors (
33
33
name, bio
34
34
) VALUES (
35
35
?, ?
36
36
))
37
37
38
- CreateAuthorReturnIdArgs = Data . define ( :name , :bio )
38
+ CreateAuthorReturnIdArgs = Struct . new ( :name , :bio )
39
39
40
40
DeleteAuthorSql = %q(DELETE FROM authors
41
41
WHERE id = ?)
42
42
43
- DeleteAuthorArgs = Data . define ( :id )
43
+ DeleteAuthorArgs = Struct . new ( :id )
44
44
45
45
TestSql = %q(SELECT c_bit, c_tinyint, c_bool, c_boolean, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_serial, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, c_date, c_time, c_datetime, c_timestamp, c_year, c_char, c_nchar, c_national_char, c_varchar, c_binary, c_varbinary, c_tinyblob, c_tinytext, c_blob, c_text, c_mediumblob, c_mediumtext, c_longblob, c_longtext, c_json FROM node_mysql_types
46
46
LIMIT 1)
47
47
48
- TestRow = Data . define (
48
+ TestRow = Struct . new (
49
49
:c_bit ,
50
50
:c_tinyint ,
51
51
:c_bool ,
@@ -92,14 +92,14 @@ def initialize(connection_pool_params, mysql2_params)
92
92
93
93
def get_author ( get_author_args )
94
94
@pool . with do |client |
95
- query_params = [ get_author_args . id ]
95
+ query_params = [ get_author_args . id ]
96
96
stmt = client . prepare ( GetAuthorSql )
97
97
result = stmt . execute ( *query_params )
98
98
row = result . first
99
99
return nil if row . nil?
100
100
entity = GetAuthorRow . new (
101
- row [ 'id' ] ,
102
- row [ 'name' ] ,
101
+ row [ 'id' ]
102
+ row [ 'name' ]
103
103
row [ 'bio' ]
104
104
)
105
105
return entity
@@ -113,8 +113,8 @@ def list_authors
113
113
entities = [ ]
114
114
result . each do |row |
115
115
entities << ListAuthorsRow . new (
116
- row [ 'id' ] ,
117
- row [ 'name' ] ,
116
+ row [ 'id' ]
117
+ row [ 'name' ]
118
118
row [ 'bio' ]
119
119
)
120
120
end
@@ -124,23 +124,23 @@ def list_authors
124
124
125
125
def create_author ( create_author_args )
126
126
@pool . with do |client |
127
- query_params = [ create_author_args . name , create_author_args . bio ]
127
+ query_params = [ create_author_args . name , create_author_args . bio ]
128
128
stmt = client . prepare ( CreateAuthorSql )
129
129
stmt . execute ( *query_params )
130
130
end
131
131
end
132
132
133
133
def update_author ( update_author_args )
134
134
@pool . with do |client |
135
- query_params = [ update_author_args . bio , update_author_args . id ]
135
+ query_params = [ update_author_args . bio , update_author_args . id ]
136
136
stmt = client . prepare ( UpdateAuthorSql )
137
137
stmt . execute ( *query_params )
138
138
end
139
139
end
140
140
141
141
def create_author_return_id ( create_author_return_id_args )
142
142
@pool . with do |client |
143
- query_params = [ create_author_return_id_args . name , create_author_return_id_args . bio ]
143
+ query_params = [ create_author_return_id_args . name , create_author_return_id_args . bio ]
144
144
stmt = client . prepare ( CreateAuthorReturnIdSql )
145
145
stmt . execute ( *query_params )
146
146
return client . last_id
@@ -149,7 +149,7 @@ def create_author_return_id(create_author_return_id_args)
149
149
150
150
def delete_author ( delete_author_args )
151
151
@pool . with do |client |
152
- query_params = [ delete_author_args . id ]
152
+ query_params = [ delete_author_args . id ]
153
153
stmt = client . prepare ( DeleteAuthorSql )
154
154
stmt . execute ( *query_params )
155
155
end
@@ -162,42 +162,42 @@ def test
162
162
row = result . first
163
163
return nil if row . nil?
164
164
entity = TestRow . new (
165
- row [ 'c_bit' ] ,
166
- row [ 'c_tinyint' ] ,
167
- row [ 'c_bool' ] ,
168
- row [ 'c_boolean' ] ,
169
- row [ 'c_smallint' ] ,
170
- row [ 'c_mediumint' ] ,
171
- row [ 'c_int' ] ,
172
- row [ 'c_integer' ] ,
173
- row [ 'c_bigint' ] ,
174
- row [ 'c_serial' ] ,
175
- row [ 'c_decimal' ] ,
176
- row [ 'c_dec' ] ,
177
- row [ 'c_numeric' ] ,
178
- row [ 'c_fixed' ] ,
179
- row [ 'c_float' ] ,
180
- row [ 'c_double' ] ,
181
- row [ 'c_double_precision' ] ,
182
- row [ 'c_date' ] ,
183
- row [ 'c_time' ] ,
184
- row [ 'c_datetime' ] ,
185
- row [ 'c_timestamp' ] ,
186
- row [ 'c_year' ] ,
187
- row [ 'c_char' ] ,
188
- row [ 'c_nchar' ] ,
189
- row [ 'c_national_char' ] ,
190
- row [ 'c_varchar' ] ,
191
- row [ 'c_binary' ] ,
192
- row [ 'c_varbinary' ] ,
193
- row [ 'c_tinyblob' ] ,
194
- row [ 'c_tinytext' ] ,
195
- row [ 'c_blob' ] ,
196
- row [ 'c_text' ] ,
197
- row [ 'c_mediumblob' ] ,
198
- row [ 'c_mediumtext' ] ,
199
- row [ 'c_longblob' ] ,
200
- row [ 'c_longtext' ] ,
165
+ row [ 'c_bit' ]
166
+ row [ 'c_tinyint' ]
167
+ row [ 'c_bool' ]
168
+ row [ 'c_boolean' ]
169
+ row [ 'c_smallint' ]
170
+ row [ 'c_mediumint' ]
171
+ row [ 'c_int' ]
172
+ row [ 'c_integer' ]
173
+ row [ 'c_bigint' ]
174
+ row [ 'c_serial' ]
175
+ row [ 'c_decimal' ]
176
+ row [ 'c_dec' ]
177
+ row [ 'c_numeric' ]
178
+ row [ 'c_fixed' ]
179
+ row [ 'c_float' ]
180
+ row [ 'c_double' ]
181
+ row [ 'c_double_precision' ]
182
+ row [ 'c_date' ]
183
+ row [ 'c_time' ]
184
+ row [ 'c_datetime' ]
185
+ row [ 'c_timestamp' ]
186
+ row [ 'c_year' ]
187
+ row [ 'c_char' ]
188
+ row [ 'c_nchar' ]
189
+ row [ 'c_national_char' ]
190
+ row [ 'c_varchar' ]
191
+ row [ 'c_binary' ]
192
+ row [ 'c_varbinary' ]
193
+ row [ 'c_tinyblob' ]
194
+ row [ 'c_tinytext' ]
195
+ row [ 'c_blob' ]
196
+ row [ 'c_text' ]
197
+ row [ 'c_mediumblob' ]
198
+ row [ 'c_mediumtext' ]
199
+ row [ 'c_longblob' ]
200
+ row [ 'c_longtext' ]
201
201
row [ 'c_json' ]
202
202
)
203
203
return entity
0 commit comments