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.Table.Columns()
return i.Table.columns()
}
func (i *ClauseInsert) Serialize(statementType StatementType, out *SqlBuilder) error {

View file

@ -6,9 +6,9 @@ type Column interface {
Name() string
TableName() string
SetTableName(table string)
SetSubQuery(subQuery SelectTable)
DefaultAlias() string
setTableName(table string)
setSubQuery(subQuery SelectTable)
defaultAlias() string
}
// Column is common column interface for all types of columns.
@ -46,15 +46,15 @@ func (c *columnImpl) TableName() string {
return c.tableName
}
func (c *columnImpl) SetTableName(table string) {
func (c *columnImpl) setTableName(table string) {
c.tableName = table
}
func (c *columnImpl) SetSubQuery(subQuery SelectTable) {
func (c *columnImpl) setSubQuery(subQuery SelectTable) {
c.subQuery = subQuery
}
func (c *columnImpl) DefaultAlias() string {
func (c *columnImpl) defaultAlias() string {
if c.tableName != "" {
return c.tableName + "." + c.name
}
@ -65,7 +65,7 @@ func (c *columnImpl) DefaultAlias() string {
func (c *columnImpl) serializeForOrderBy(statement StatementType, out *SqlBuilder) error {
if statement == SetStatementType {
// 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
}
@ -81,7 +81,7 @@ func (c columnImpl) serializeForProjection(statement StatementType, out *SqlBuil
}
out.WriteString("AS")
out.WriteAlias(c.DefaultAlias())
out.WriteAlias(c.defaultAlias())
return nil
}
@ -91,7 +91,7 @@ func (c columnImpl) serialize(statement StatementType, out *SqlBuilder, options
if c.subQuery != nil {
out.WriteIdentifier(c.subQuery.Alias())
out.WriteByte('.')
out.WriteIdentifier(c.DefaultAlias(), true)
out.WriteIdentifier(c.defaultAlias(), true)
} else {
if c.tableName != "" {
out.WriteIdentifier(c.tableName)
@ -110,7 +110,7 @@ type IColumnList interface {
Projection
Column
Columns() []ColumnExpression
columns() []ColumnExpression
}
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
type columnListImpl []ColumnExpression
func (cl columnListImpl) Columns() []ColumnExpression {
func (cl columnListImpl) columns() []ColumnExpression {
return cl
}
@ -153,6 +153,6 @@ func (cl columnListImpl) Name() string { return "" }
// TableName is placeholder for ColumnList to implement Column interface
func (cl columnListImpl) TableName() string { return "" }
func (cl columnListImpl) SetTableName(name string) {}
func (cl columnListImpl) SetSubQuery(subQuery SelectTable) {}
func (cl columnListImpl) DefaultAlias() string { return "" }
func (cl columnListImpl) setTableName(name string) {}
func (cl columnListImpl) setSubQuery(subQuery SelectTable) {}
func (cl columnListImpl) defaultAlias() string { return "" }

View file

@ -7,7 +7,7 @@ func TestColumn(t *testing.T) {
column.ExpressionInterfaceImpl.Parent = &column
assertClauseSerialize(t, column, "col")
column.SetTableName("table1")
column.setTableName("table1")
assertClauseSerialize(t, column, "table1.col")
assertProjectionSerialize(t, &column, `table1.col AS "table1.col"`)
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 {
newBoolColumn := BoolColumn(i.name)
newBoolColumn.SetTableName(i.tableName)
newBoolColumn.SetSubQuery(subQuery)
newBoolColumn.setTableName(i.tableName)
newBoolColumn.setSubQuery(subQuery)
return newBoolColumn
}
@ -54,8 +54,8 @@ type floatColumnImpl struct {
func (i *floatColumnImpl) fromImpl(subQuery SelectTable) Projection {
newFloatColumn := FloatColumn(i.name)
newFloatColumn.SetTableName(i.tableName)
newFloatColumn.SetSubQuery(subQuery)
newFloatColumn.setTableName(i.tableName)
newFloatColumn.setSubQuery(subQuery)
return newFloatColumn
}
@ -93,8 +93,8 @@ type integerColumnImpl struct {
func (i *integerColumnImpl) fromImpl(subQuery SelectTable) Projection {
newIntColumn := IntegerColumn(i.name)
newIntColumn.SetTableName(i.tableName)
newIntColumn.SetSubQuery(subQuery)
newIntColumn.setTableName(i.tableName)
newIntColumn.setSubQuery(subQuery)
return newIntColumn
}
@ -131,8 +131,8 @@ type stringColumnImpl struct {
func (i *stringColumnImpl) fromImpl(subQuery SelectTable) Projection {
newStrColumn := StringColumn(i.name)
newStrColumn.SetTableName(i.tableName)
newStrColumn.SetSubQuery(subQuery)
newStrColumn.setTableName(i.tableName)
newStrColumn.setSubQuery(subQuery)
return newStrColumn
}
@ -167,8 +167,8 @@ type timeColumnImpl struct {
func (i *timeColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimeColumn := TimeColumn(i.name)
newTimeColumn.SetTableName(i.tableName)
newTimeColumn.SetSubQuery(subQuery)
newTimeColumn.setTableName(i.tableName)
newTimeColumn.setSubQuery(subQuery)
return newTimeColumn
}
@ -203,8 +203,8 @@ type timezColumnImpl struct {
func (i *timezColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimezColumn := TimezColumn(i.name)
newTimezColumn.SetTableName(i.tableName)
newTimezColumn.SetSubQuery(subQuery)
newTimezColumn.setTableName(i.tableName)
newTimezColumn.setSubQuery(subQuery)
return newTimezColumn
}
@ -240,8 +240,8 @@ type timestampColumnImpl struct {
func (i *timestampColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimestampColumn := TimestampColumn(i.name)
newTimestampColumn.SetTableName(i.tableName)
newTimestampColumn.SetSubQuery(subQuery)
newTimestampColumn.setTableName(i.tableName)
newTimestampColumn.setSubQuery(subQuery)
return newTimestampColumn
}
@ -277,8 +277,8 @@ type timestampzColumnImpl struct {
func (i *timestampzColumnImpl) fromImpl(subQuery SelectTable) Projection {
newTimestampzColumn := TimestampzColumn(i.name)
newTimestampzColumn.SetTableName(i.tableName)
newTimestampzColumn.SetSubQuery(subQuery)
newTimestampzColumn.setTableName(i.tableName)
newTimestampzColumn.setSubQuery(subQuery)
return newTimestampzColumn
}
@ -314,8 +314,8 @@ type dateColumnImpl struct {
func (i *dateColumnImpl) fromImpl(subQuery SelectTable) Projection {
newDateColumn := DateColumn(i.name)
newDateColumn.SetTableName(i.tableName)
newDateColumn.SetSubQuery(subQuery)
newDateColumn.setTableName(i.tableName)
newDateColumn.setSubQuery(subQuery)
return newDateColumn
}

View file

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

View file

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