Encode json values implicitly in the sql queries according the golang json package spec.
This commit is contained in:
parent
9616bb5cfe
commit
17646ca99c
54 changed files with 1446 additions and 744 deletions
|
|
@ -18,10 +18,45 @@ func (a *alias) fromImpl(subQuery SelectTable) Projection {
|
|||
// Generated columns have default aliasing.
|
||||
tableName, columnName := extractTableAndColumnName(a.alias)
|
||||
|
||||
column := NewColumnImpl(columnName, tableName, nil)
|
||||
column.subQuery = subQuery
|
||||
newDummyColumn := newDummyColumnForExpression(a.expression, columnName)
|
||||
newDummyColumn.setTableName(tableName)
|
||||
newDummyColumn.setSubQuery(subQuery)
|
||||
|
||||
return &column
|
||||
return newDummyColumn
|
||||
}
|
||||
|
||||
// This function is used to create dummy columns when exporting sub-query columns using subQuery.AllColumns()
|
||||
// In most case we don't care about type of the column, except when sub-query columns are used as SELECT_JSON projection.
|
||||
// We need to know type to encode value for json unmarshal. At the moment only bool, time and blob columns are of interest,
|
||||
// so we don't have to support every column type.
|
||||
func newDummyColumnForExpression(exp Expression, name string) ColumnExpression {
|
||||
|
||||
switch exp.(type) {
|
||||
case BoolExpression:
|
||||
return BoolColumn(name)
|
||||
case IntegerExpression:
|
||||
return IntegerColumn(name)
|
||||
case FloatExpression:
|
||||
return FloatColumn(name)
|
||||
case BlobExpression:
|
||||
return BlobColumn(name)
|
||||
case DateExpression:
|
||||
return DateColumn(name)
|
||||
case TimeExpression:
|
||||
return TimeColumn(name)
|
||||
case TimezExpression:
|
||||
return TimezColumn(name)
|
||||
case TimestampExpression:
|
||||
return TimestampColumn(name)
|
||||
case TimestampzExpression:
|
||||
return TimestampzColumn(name)
|
||||
case IntervalExpression:
|
||||
return IntervalColumn(name)
|
||||
case StringExpression:
|
||||
return StringColumn(name)
|
||||
}
|
||||
|
||||
return StringColumn(name)
|
||||
}
|
||||
|
||||
func (a *alias) serializeForProjection(statement StatementType, out *SQLBuilder) {
|
||||
|
|
@ -31,7 +66,14 @@ func (a *alias) serializeForProjection(statement StatementType, out *SQLBuilder)
|
|||
out.WriteAlias(a.alias)
|
||||
}
|
||||
|
||||
func (a *alias) serializeForJsonObj(statement StatementType, out *SQLBuilder) {
|
||||
func (a *alias) serializeForJsonObjEntry(statement StatementType, out *SQLBuilder) {
|
||||
out.WriteJsonObjKey(a.alias)
|
||||
a.expression.serialize(statement, out)
|
||||
a.expression.serializeForJsonValue(statement, out)
|
||||
}
|
||||
|
||||
func (a *alias) serializeForRowToJsonProjection(statement StatementType, out *SQLBuilder) {
|
||||
a.expression.serializeForJsonValue(statement, out)
|
||||
|
||||
out.WriteString("AS")
|
||||
out.WriteAlias(a.alias)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue