diff options
Diffstat (limited to 'query.zig')
| -rw-r--r-- | query.zig | 17 |
1 files changed, 16 insertions, 1 deletions
| @@ -112,7 +112,18 @@ pub const ParsedQuery = struct { | |||
| 112 | '}' => { | 112 | '}' => { |
| 113 | state = .start; | 113 | state = .start; |
| 114 | 114 | ||
| 115 | const typ = parseType(current_bind_marker_type[0..current_bind_marker_type_pos]); | 115 | const type_info_string = current_bind_marker_type[0..current_bind_marker_type_pos]; |
| 116 | // Handles optional types | ||
| 117 | const typ = if (type_info_string[0] == '?') blk: { | ||
| 118 | const child_type = parseType(type_info_string[1..]); | ||
| 119 | break :blk @Type(std.builtin.TypeInfo{ | ||
| 120 | .Optional = .{ | ||
| 121 | .child = child_type, | ||
| 122 | }, | ||
| 123 | }); | ||
| 124 | } else blk: { | ||
| 125 | break :blk parseType(type_info_string); | ||
| 126 | }; | ||
| 116 | 127 | ||
| 117 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = typ; | 128 | parsed_query.bind_markers[parsed_query.nb_bind_markers].typed = typ; |
| 118 | parsed_query.nb_bind_markers += 1; | 129 | parsed_query.nb_bind_markers += 1; |
| @@ -252,6 +263,10 @@ test "parsed query: bind markers types" { | |||
| 252 | .query = "foobar " ++ prefix, | 263 | .query = "foobar " ++ prefix, |
| 253 | .expected_marker = .{ .typed = null }, | 264 | .expected_marker = .{ .typed = null }, |
| 254 | }, | 265 | }, |
| 266 | .{ | ||
| 267 | .query = "foobar " ++ prefix ++ "{?[]const u8}", | ||
| 268 | .expected_marker = .{ .typed = ?[]const u8 }, | ||
| 269 | }, | ||
| 255 | }; | 270 | }; |
| 256 | 271 | ||
| 257 | inline for (testCases) |tc| { | 272 | inline for (testCases) |tc| { |