Hide private methods.

This commit is contained in:
go-jet 2019-08-12 11:33:46 +02:00
parent e02e08a6ba
commit 74288d5418
6 changed files with 54 additions and 43 deletions

View file

@ -316,7 +316,7 @@ func (i *ClauseInsert) GetColumns() []Column {
return i.Columns return i.Columns
} }
return i.Table.Columns() return i.Table.columns()
} }
func (i *ClauseInsert) Serialize(statementType StatementType, out *SqlBuilder) error { func (i *ClauseInsert) Serialize(statementType StatementType, out *SqlBuilder) error {

View file

@ -6,9 +6,9 @@ type Column interface {
Name() string Name() string
TableName() string TableName() string
SetTableName(table string) setTableName(table string)
SetSubQuery(subQuery SelectTable) setSubQuery(subQuery SelectTable)
DefaultAlias() string defaultAlias() string
} }
// Column is common column interface for all types of columns. // Column is common column interface for all types of columns.
@ -46,15 +46,15 @@ func (c *columnImpl) TableName() string {
return c.tableName return c.tableName
} }
func (c *columnImpl) SetTableName(table string) { func (c *columnImpl) setTableName(table string) {
c.tableName = table c.tableName = table
} }
func (c *columnImpl) SetSubQuery(subQuery SelectTable) { func (c *columnImpl) setSubQuery(subQuery SelectTable) {
c.subQuery = subQuery c.subQuery = subQuery
} }
func (c *columnImpl) DefaultAlias() string { func (c *columnImpl) defaultAlias() string {
if c.tableName != "" { if c.tableName != "" {
return c.tableName + "." + c.name return c.tableName + "." + c.name
} }
@ -65,7 +65,7 @@ func (c *columnImpl) DefaultAlias() string {
func (c *columnImpl) serializeForOrderBy(statement StatementType, out *SqlBuilder) error { func (c *columnImpl) serializeForOrderBy(statement StatementType, out *SqlBuilder) error {
if statement == SetStatementType { if statement == SetStatementType {
// set Statement (UNION, EXCEPT ...) can reference only select projections in order by clause // set Statement (UNION, EXCEPT ...) can reference only select projections in order by clause
out.WriteAlias(c.DefaultAlias()) //always quote out.WriteAlias(c.defaultAlias()) //always quote
return nil return nil
} }
@ -81,7 +81,7 @@ func (c columnImpl) serializeForProjection(statement StatementType, out *SqlBuil
} }
out.WriteString("AS") out.WriteString("AS")
out.WriteAlias(c.DefaultAlias()) out.WriteAlias(c.defaultAlias())
return nil return nil
} }
@ -91,7 +91,7 @@ func (c columnImpl) serialize(statement StatementType, out *SqlBuilder, options
if c.subQuery != nil { if c.subQuery != nil {
out.WriteIdentifier(c.subQuery.Alias()) out.WriteIdentifier(c.subQuery.Alias())
out.WriteByte('.') out.WriteByte('.')
out.WriteIdentifier(c.DefaultAlias(), true) out.WriteIdentifier(c.defaultAlias(), true)
} else { } else {
if c.tableName != "" { if c.tableName != "" {
out.WriteIdentifier(c.tableName) out.WriteIdentifier(c.tableName)
@ -110,7 +110,7 @@ type IColumnList interface {
Projection Projection
Column Column
Columns() []ColumnExpression columns() []ColumnExpression
} }
func ColumnList(columns ...ColumnExpression) IColumnList { func ColumnList(columns ...ColumnExpression) IColumnList {
@ -120,7 +120,7 @@ func ColumnList(columns ...ColumnExpression) IColumnList {
// ColumnList is redefined type to support list of columns as single Projection // ColumnList is redefined type to support list of columns as single Projection
type columnListImpl []ColumnExpression type columnListImpl []ColumnExpression
func (cl columnListImpl) Columns() []ColumnExpression { func (cl columnListImpl) columns() []ColumnExpression {
return cl return cl
} }
@ -153,6 +153,6 @@ func (cl columnListImpl) Name() string { return "" }
// TableName is placeholder for ColumnList to implement Column interface // TableName is placeholder for ColumnList to implement Column interface
func (cl columnListImpl) TableName() string { return "" } func (cl columnListImpl) TableName() string { return "" }
func (cl columnListImpl) SetTableName(name string) {} func (cl columnListImpl) setTableName(name string) {}
func (cl columnListImpl) SetSubQuery(subQuery SelectTable) {} func (cl columnListImpl) setSubQuery(subQuery SelectTable) {}
func (cl columnListImpl) DefaultAlias() string { return "" } func (cl columnListImpl) defaultAlias() string { return "" }

View file

@ -7,7 +7,7 @@ func TestColumn(t *testing.T) {
column.ExpressionInterfaceImpl.Parent = &column column.ExpressionInterfaceImpl.Parent = &column
assertClauseSerialize(t, column, "col") assertClauseSerialize(t, column, "col")
column.SetTableName("table1") column.setTableName("table1")
assertClauseSerialize(t, column, "table1.col") assertClauseSerialize(t, column, "table1.col")
assertProjectionSerialize(t, &column, `table1.col AS "table1.col"`) assertProjectionSerialize(t, &column, `table1.col AS "table1.col"`)
assertProjectionSerialize(t, column.AS("alias1"), `table1.col AS "alias1"`) assertProjectionSerialize(t, column.AS("alias1"), `table1.col AS "alias1"`)

View file

@ -16,8 +16,8 @@ type boolColumnImpl struct {
func (i *boolColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *boolColumnImpl) fromImpl(subQuery SelectTable) Projection {
newBoolColumn := BoolColumn(i.name) newBoolColumn := BoolColumn(i.name)
newBoolColumn.SetTableName(i.tableName) newBoolColumn.setTableName(i.tableName)
newBoolColumn.SetSubQuery(subQuery) newBoolColumn.setSubQuery(subQuery)
return newBoolColumn return newBoolColumn
} }
@ -54,8 +54,8 @@ type floatColumnImpl struct {
func (i *floatColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *floatColumnImpl) fromImpl(subQuery SelectTable) Projection {
newFloatColumn := FloatColumn(i.name) newFloatColumn := FloatColumn(i.name)
newFloatColumn.SetTableName(i.tableName) newFloatColumn.setTableName(i.tableName)
newFloatColumn.SetSubQuery(subQuery) newFloatColumn.setSubQuery(subQuery)
return newFloatColumn return newFloatColumn
} }
@ -93,8 +93,8 @@ type integerColumnImpl struct {
func (i *integerColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *integerColumnImpl) fromImpl(subQuery SelectTable) Projection {
newIntColumn := IntegerColumn(i.name) newIntColumn := IntegerColumn(i.name)
newIntColumn.SetTableName(i.tableName) newIntColumn.setTableName(i.tableName)
newIntColumn.SetSubQuery(subQuery) newIntColumn.setSubQuery(subQuery)
return newIntColumn return newIntColumn
} }
@ -131,8 +131,8 @@ type stringColumnImpl struct {
func (i *stringColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *stringColumnImpl) fromImpl(subQuery SelectTable) Projection {
newStrColumn := StringColumn(i.name) newStrColumn := StringColumn(i.name)
newStrColumn.SetTableName(i.tableName) newStrColumn.setTableName(i.tableName)
newStrColumn.SetSubQuery(subQuery) newStrColumn.setSubQuery(subQuery)
return newStrColumn return newStrColumn
} }
@ -167,8 +167,8 @@ type timeColumnImpl struct {
func (i *timeColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *timeColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimeColumn := TimeColumn(i.name) newTimeColumn := TimeColumn(i.name)
newTimeColumn.SetTableName(i.tableName) newTimeColumn.setTableName(i.tableName)
newTimeColumn.SetSubQuery(subQuery) newTimeColumn.setSubQuery(subQuery)
return newTimeColumn return newTimeColumn
} }
@ -203,8 +203,8 @@ type timezColumnImpl struct {
func (i *timezColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *timezColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimezColumn := TimezColumn(i.name) newTimezColumn := TimezColumn(i.name)
newTimezColumn.SetTableName(i.tableName) newTimezColumn.setTableName(i.tableName)
newTimezColumn.SetSubQuery(subQuery) newTimezColumn.setSubQuery(subQuery)
return newTimezColumn return newTimezColumn
} }
@ -240,8 +240,8 @@ type timestampColumnImpl struct {
func (i *timestampColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *timestampColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimestampColumn := TimestampColumn(i.name) newTimestampColumn := TimestampColumn(i.name)
newTimestampColumn.SetTableName(i.tableName) newTimestampColumn.setTableName(i.tableName)
newTimestampColumn.SetSubQuery(subQuery) newTimestampColumn.setSubQuery(subQuery)
return newTimestampColumn return newTimestampColumn
} }
@ -277,8 +277,8 @@ type timestampzColumnImpl struct {
func (i *timestampzColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *timestampzColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimestampzColumn := TimestampzColumn(i.name) newTimestampzColumn := TimestampzColumn(i.name)
newTimestampzColumn.SetTableName(i.tableName) newTimestampzColumn.setTableName(i.tableName)
newTimestampzColumn.SetSubQuery(subQuery) newTimestampzColumn.setSubQuery(subQuery)
return newTimestampzColumn return newTimestampzColumn
} }
@ -314,8 +314,8 @@ type dateColumnImpl struct {
func (i *dateColumnImpl) fromImpl(subQuery SelectTable) Projection { func (i *dateColumnImpl) fromImpl(subQuery SelectTable) Projection {
newDateColumn := DateColumn(i.name) newDateColumn := DateColumn(i.name)
newDateColumn.SetTableName(i.tableName) newDateColumn.setTableName(i.tableName)
newDateColumn.SetSubQuery(subQuery) newDateColumn.setSubQuery(subQuery)
return newDateColumn return newDateColumn
} }

View file

@ -11,7 +11,7 @@ type SerializerTable interface {
} }
type TableInterface interface { type TableInterface interface {
Columns() []Column columns() []Column
SchemaName() string SchemaName() string
TableName() string TableName() string
AS(alias string) AS(alias string)
@ -27,7 +27,7 @@ func NewTable(schemaName, name string, columns ...ColumnExpression) TableImpl {
} }
for _, c := range columns { for _, c := range columns {
c.SetTableName(name) c.setTableName(name)
} }
return t return t
@ -44,7 +44,7 @@ func (t *TableImpl) AS(alias string) {
t.alias = alias t.alias = alias
for _, c := range t.columnList { for _, c := range t.columnList {
c.SetTableName(alias) c.setTableName(alias)
} }
} }
@ -56,7 +56,7 @@ func (t *TableImpl) TableName() string {
return t.name return t.name
} }
func (t *TableImpl) Columns() []Column { func (t *TableImpl) columns() []Column {
ret := []Column{} ret := []Column{}
for _, col := range t.columnList { for _, col := range t.columnList {
@ -114,6 +114,9 @@ func NewJoinTableImpl(lhs Serializer, rhs Serializer, joinType JoinType, onCondi
} }
func (t *JoinTableImpl) SchemaName() string { func (t *JoinTableImpl) SchemaName() string {
if table, ok := t.lhs.(TableInterface); ok {
return table.SchemaName()
}
return "" return ""
} }
@ -122,8 +125,16 @@ func (t *JoinTableImpl) TableName() string {
} }
func (t *JoinTableImpl) Columns() []Column { func (t *JoinTableImpl) Columns() []Column {
//return append(t.lhs.columns(), t.rhs.columns()...) var ret []Column
panic("Unimplemented")
if lhsTable, ok := t.lhs.(TableInterface); ok {
ret = append(ret, lhsTable.columns()...)
}
if rhsTable, ok := t.rhs.(TableInterface); ok {
ret = append(ret, rhsTable.columns()...)
}
return ret
} }
func (t *JoinTableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) { func (t *JoinTableImpl) serialize(statement StatementType, out *SqlBuilder, options ...SerializeOption) (err error) {
@ -180,7 +191,7 @@ func UnwindColumns(column1 Column, columns ...Column) []Column {
columnList := []Column{} columnList := []Column{}
if val, ok := column1.(IColumnList); ok { if val, ok := column1.(IColumnList); ok {
for _, col := range val.Columns() { for _, col := range val.columns() {
columnList = append(columnList, col) columnList = append(columnList, col)
} }
columnList = append(columnList, columns...) columnList = append(columnList, columns...)
@ -197,7 +208,7 @@ func UnwidColumnList(columns []Column) []Column {
for _, col := range columns { for _, col := range columns {
if columnList, ok := col.(IColumnList); ok { if columnList, ok := col.(IColumnList); ok {
for _, c := range columnList.Columns() { for _, c := range columnList.columns() {
ret = append(ret, c) ret = append(ret, c)
} }
} else { } else {

View file

@ -146,7 +146,7 @@ func UnwindRowFromModel(columns []Column, data interface{}) []Serializer {
structField := structValue.FieldByName(structFieldName) structField := structValue.FieldByName(structFieldName)
if !structField.IsValid() { if !structField.IsValid() {
panic("missing struct field for column : " + column.Name()) panic("missing struct field for column : " + columnName)
} }
var field interface{} var field interface{}