Add support for FETCH FIRST clause.

This commit is contained in:
go-jet 2024-02-07 11:07:50 +01:00
parent e03773a79e
commit e51ddd5506
3 changed files with 145 additions and 3 deletions

View file

@ -53,6 +53,7 @@ type SelectStatement interface {
ORDER_BY(orderByClauses ...OrderByClause) SelectStatement
LIMIT(limit int64) SelectStatement
OFFSET(offset int64) SelectStatement
FETCH_FIRST(count IntegerExpression) fetchExpand
FOR(lock RowLock) SelectStatement
UNION(rhs SelectStatement) setStatement
@ -72,9 +73,18 @@ func SELECT(projection Projection, projections ...Projection) SelectStatement {
func newSelectStatement(table ReadableTable, projections []Projection) SelectStatement {
newSelect := &selectStatementImpl{}
newSelect.ExpressionStatement = jet.NewExpressionStatementImpl(Dialect, jet.SelectStatementType, newSelect, &newSelect.Select,
&newSelect.From, &newSelect.Where, &newSelect.GroupBy, &newSelect.Having, &newSelect.Window, &newSelect.OrderBy,
&newSelect.Limit, &newSelect.Offset, &newSelect.For)
newSelect.ExpressionStatement = jet.NewExpressionStatementImpl(Dialect, jet.SelectStatementType, newSelect,
&newSelect.Select,
&newSelect.From,
&newSelect.Where,
&newSelect.GroupBy,
&newSelect.Having,
&newSelect.Window,
&newSelect.OrderBy,
&newSelect.Limit,
&newSelect.Offset,
&newSelect.Fetch,
&newSelect.For)
newSelect.Select.ProjectionList = projections
if table != nil {
@ -101,6 +111,7 @@ type selectStatementImpl struct {
OrderBy jet.ClauseOrderBy
Limit jet.ClauseLimit
Offset jet.ClauseOffset
Fetch jet.ClauseFetch
For jet.ClauseFor
}
@ -150,6 +161,14 @@ func (s *selectStatementImpl) OFFSET(offset int64) SelectStatement {
return s
}
func (s *selectStatementImpl) FETCH_FIRST(count IntegerExpression) fetchExpand {
s.Fetch.Count = count
return fetchExpand{
selectStatement: s,
}
}
func (s *selectStatementImpl) FOR(lock RowLock) SelectStatement {
s.For.Lock = lock
return s
@ -188,3 +207,19 @@ func readableTablesToSerializerList(tables []ReadableTable) []jet.Serializer {
}
return ret
}
type fetchExpand struct {
selectStatement *selectStatementImpl
}
func (f fetchExpand) ROWS_ONLY() SelectStatement {
f.selectStatement.Fetch.WithTies = false
return f.selectStatement
}
func (f fetchExpand) ROWS_WITH_TIES() SelectStatement {
f.selectStatement.Fetch.WithTies = true
return f.selectStatement
}