|
6 | 6 | "strings" |
7 | 7 |
|
8 | 8 | "github.com/sqlc-dev/sqlc/internal/config" |
9 | | - "github.com/sqlc-dev/sqlc/internal/engine/sqlite" |
10 | 9 | "github.com/sqlc-dev/sqlc/internal/source" |
11 | 10 | "github.com/sqlc-dev/sqlc/internal/sql/ast" |
12 | 11 | "github.com/sqlc-dev/sqlc/internal/sql/astutils" |
@@ -150,17 +149,11 @@ func (c *Compiler) expandStmt(qc *QueryCatalog, raw *ast.RawStmt, node ast.Node) |
150 | 149 | if counts[cname] > 1 { |
151 | 150 | cname = tableName + "." + cname |
152 | 151 | } |
153 | | - // Under SQLite, neither json nor jsonb are real data types, and |
154 | | - // rather just of type blob, so database drivers just return |
155 | | - // whatever raw binary is stored as values. This is a problem |
156 | | - // for jsonb, which is considered an internal format to SQLite |
157 | | - // and no attempt should be made to parse it outside of the |
158 | | - // database itself. For jsonb columns in SQLite, wrap returned |
159 | | - // columns in `json(col)` to coerce the internal binary format |
160 | | - // to JSON parsable by the user-space application. |
161 | | - if _, ok := c.parser.(*sqlite.Parser); ok && column.DataType == "jsonb" { |
162 | | - cname = "json(" + cname + ")" |
163 | | - } |
| 152 | + |
| 153 | + // This is important for SQLite in particular which needs to |
| 154 | + // wrap jsonb column values with `json(colname)` so they're in a |
| 155 | + // publicly usable format (i.e. not jsonb). |
| 156 | + cname = c.selector.ColumnExpr(cname, column.DataType) |
164 | 157 | cols = append(cols, cname) |
165 | 158 | } |
166 | 159 | } |
|
0 commit comments