Add support for SELECT_JSON statements.

This commit is contained in:
go-jet 2025-02-21 19:55:01 +01:00
parent 7047de44a9
commit 7b16e432ff
46 changed files with 2732 additions and 307 deletions

View file

@ -3,6 +3,7 @@ package jet
// Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.
type Projection interface {
serializeForProjection(statement StatementType, out *SQLBuilder)
serializeForJsonObj(statement StatementType, out *SQLBuilder)
fromImpl(subQuery SelectTable) Projection
}
@ -28,6 +29,10 @@ func (pl ProjectionList) serializeForProjection(statement StatementType, out *SQ
SerializeProjectionList(statement, pl, out)
}
func (pl ProjectionList) serializeForJsonObj(statement StatementType, out *SQLBuilder) {
SerializeProjectionListJsonObj(statement, pl, out)
}
// As will create new projection list where each column is wrapped with a new table alias.
// tableAlias should be in the form 'name' or 'name.*', or it can be an empty string, which will remove existing table alias.
// For instance: If projection list has a column 'Artist.Name', and tableAlias is 'Musician.*', returned projection list will
@ -79,3 +84,10 @@ func (pl ProjectionList) Except(toExclude ...Column) ProjectionList {
return ret
}
// JsonProjectionList redefines []Projection so projections can be serialized as json object key/values
type JsonProjectionList []Projection
func (j JsonProjectionList) serialize(statement StatementType, out *SQLBuilder, options ...SerializeOption) {
SerializeProjectionListJsonObj(statement, j, out)
}