Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jan 12, 2024
1 parent 52a5a8b commit 7021619
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 3 additions & 8 deletions desc/create_table_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func BuildCreateTableQuery(td *Table) string {
query.WriteString(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (", td.Name))

// Loop over the columns and append their definitions to the query
for i, col := range td.Columns {
for i, col := range td.ListColumnsWithoutPresenter() {
if col.Presenter {
continue // skip presenter columns.
}
Expand Down Expand Up @@ -46,14 +46,9 @@ func BuildCreateTableQuery(td *Table) string {
query.WriteString(fmt.Sprintf(" CHECK (%s)", col.CheckConstraint))
}

// Add a comma separator if this is not the last column
// Add a comma separator if this is not the last column.
if i < len(td.Columns)-1 {
nextIsPresenter := false
nextIndex := i + 1
nextIsPresenter = len(td.Columns)-1 >= nextIndex && td.Columns[nextIndex].Presenter
if !nextIsPresenter {
query.WriteString(", ")
}
query.WriteString(", ")
}
}

Expand Down
14 changes: 14 additions & 0 deletions desc/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ func (td *Table) listColumnsForSelectWithoutGenerated() []*Column {
return columns
}

// ListColumnsWithoutPresenter returns the columns of the table definition except the presenter ones.
func (td *Table) ListColumnsWithoutPresenter() []*Column {
columns := make([]*Column, 0, len(td.Columns))
for _, c := range td.Columns {
if c.Presenter {
continue
}

columns = append(columns, c)
}

return columns
}

// ListColumnNames returns the column names of the table definition.
func (td *Table) ListColumnNames() []string {
names := make([]string, 0, len(td.Columns))
Expand Down

0 comments on commit 7021619

Please sign in to comment.