Skip to content

Commit

Permalink
Update select.go
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebo committed Nov 22, 2024
1 parent 23b3929 commit 97765e5
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions sqlx/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,24 @@ func Select(columns ...any) *SelectStatement {
cols[i] = &Sql{col}
}

self := &SelectStatement{
return &SelectStatement{
depth: 0,
columns: cols,
}

self.setDepth(self.depth)
return self
}

func (self *SelectStatement) Column(column any) *SelectStatement {
switch v := column.(type) {
case string:
self.columns = append(self.columns, &Sql{v})
break
case Sqlizer:
v.setDepth(self.depth + 1)
self.columns = append(self.columns, v)
break
}

self.columns = append(self.columns, &Sql{column})
return self
}

func (self *SelectStatement) From(from any) *SelectStatement {
self.from = &Sql{from}
self.setDepth(self.depth)
return self
}

func (self *SelectStatement) Where(predicate any) *SelectStatement {
self.where = Where(predicate)
self.setDepth(self.depth)
return self
}

Expand All @@ -63,7 +49,6 @@ func (self *SelectStatement) And(predicates ...any) *SelectStatement {
self.where.And(predicate)
}

self.setDepth(self.depth)
return self
}

Expand All @@ -72,7 +57,6 @@ func (self *SelectStatement) Or(predicates ...any) *SelectStatement {
self.where.Or(predicate)
}

self.setDepth(self.depth)
return self
}

Expand Down Expand Up @@ -101,6 +85,7 @@ func (self *SelectStatement) As(alias string) Sqlizer {
}

func (self SelectStatement) Sql() string {
self.setDepth(self.depth)
parts := []string{"SELECT"}
parts = append(parts, self.columns.Sql())

Expand Down Expand Up @@ -140,6 +125,7 @@ func (self SelectStatement) Sql() string {
}

func (self SelectStatement) SqlPretty(indent string) string {
self.setDepth(self.depth)
parts := []string{}

if self.depth > 0 {
Expand Down

0 comments on commit 97765e5

Please sign in to comment.