Add support for VALUES statement.
This commit is contained in:
parent
3fcbbec427
commit
8d112f7db8
41 changed files with 1296 additions and 131 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package sqlite
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/jet"
|
||||
)
|
||||
|
||||
|
|
@ -23,6 +24,9 @@ func newDialect() jet.Dialect {
|
|||
return "?"
|
||||
},
|
||||
ReservedWords: reservedWords2,
|
||||
ValuesDefaultColumnName: func(index int) string {
|
||||
return fmt.Sprintf("column%d", index+1)
|
||||
},
|
||||
}
|
||||
|
||||
return jet.NewDialect(mySQLDialectParams)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ var (
|
|||
OR = jet.OR
|
||||
)
|
||||
|
||||
// ROW is construct one row from a list of expressions.
|
||||
var ROW = jet.WRAP
|
||||
// ROW function is used to create a tuple value that consists of a set of expressions or column values.
|
||||
func ROW(expressions ...Expression) RowExpression {
|
||||
return jet.WRAP(Dialect, expressions...)
|
||||
}
|
||||
|
||||
// ------------------ Mathematical functions ---------------//
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func (s *selectStatementImpl) LOCK_IN_SHARE_MODE() SelectStatement {
|
|||
}
|
||||
|
||||
func (s *selectStatementImpl) AsTable(alias string) SelectTable {
|
||||
return newSelectTable(s, alias)
|
||||
return newSelectTable(s, alias, nil)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ type selectTableImpl struct {
|
|||
readableTableInterfaceImpl
|
||||
}
|
||||
|
||||
func newSelectTable(selectStmt jet.SerializerHasProjections, alias string) SelectTable {
|
||||
func newSelectTable(selectStmt jet.SerializerHasProjections, alias string, columnAliases []jet.ColumnExpression) SelectTable {
|
||||
subQuery := &selectTableImpl{
|
||||
SelectTable: jet.NewSelectTable(selectStmt, alias),
|
||||
SelectTable: jet.NewSelectTable(selectStmt, alias, columnAliases),
|
||||
}
|
||||
|
||||
subQuery.readableTableInterfaceImpl.parent = subQuery
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (s *setStatementImpl) OFFSET(offset int64) setStatement {
|
|||
}
|
||||
|
||||
func (s *setStatementImpl) AsTable(alias string) SelectTable {
|
||||
return newSelectTable(s, alias)
|
||||
return newSelectTable(s, alias, nil)
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
|||
26
sqlite/values.go
Normal file
26
sqlite/values.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package sqlite
|
||||
|
||||
import "github.com/go-jet/jet/v2/internal/jet"
|
||||
|
||||
type values struct {
|
||||
jet.Values
|
||||
}
|
||||
|
||||
// VALUES is a table value constructor that computes a set of one or more rows as a temporary constant table.
|
||||
// Each row is defined by the ROW constructor, which takes one or more expressions.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// VALUES(
|
||||
// ROW(Int32(204), Float32(1.21)),
|
||||
// ROW(Int32(207), Float32(1.02)),
|
||||
// )
|
||||
func VALUES(rows ...RowExpression) values {
|
||||
return values{Values: jet.Values(rows)}
|
||||
}
|
||||
|
||||
// AS assigns an alias to the temporary VALUES table, allowing it to be referenced
|
||||
// within SQL FROM clauses, just like a regular table.
|
||||
func (v values) AS(alias string) SelectTable {
|
||||
return newSelectTable(v, alias, nil)
|
||||
}
|
||||
|
|
@ -6,8 +6,8 @@ import "github.com/go-jet/jet/v2/internal/jet"
|
|||
type CommonTableExpression interface {
|
||||
SelectTable
|
||||
|
||||
AS(statement jet.SerializerStatement) CommonTableExpression
|
||||
AS_NOT_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression
|
||||
AS(statement jet.SerializerHasProjections) CommonTableExpression
|
||||
AS_NOT_MATERIALIZED(statement jet.SerializerHasProjections) CommonTableExpression
|
||||
// ALIAS is used to create another alias of the CTE, if a CTE needs to appear multiple times in the main query.
|
||||
ALIAS(alias string) SelectTable
|
||||
|
||||
|
|
@ -42,13 +42,13 @@ func CTE(name string, columns ...jet.ColumnExpression) CommonTableExpression {
|
|||
}
|
||||
|
||||
// AS is used to define a CTE query
|
||||
func (c *commonTableExpression) AS(statement jet.SerializerStatement) CommonTableExpression {
|
||||
func (c *commonTableExpression) AS(statement jet.SerializerHasProjections) CommonTableExpression {
|
||||
c.CommonTableExpression.Statement = statement
|
||||
return c
|
||||
}
|
||||
|
||||
// AS_NOT_MATERIALIZED is used to define not materialized CTE query
|
||||
func (c *commonTableExpression) AS_NOT_MATERIALIZED(statement jet.SerializerStatement) CommonTableExpression {
|
||||
func (c *commonTableExpression) AS_NOT_MATERIALIZED(statement jet.SerializerHasProjections) CommonTableExpression {
|
||||
c.CommonTableExpression.NotMaterialized = true
|
||||
c.CommonTableExpression.Statement = statement
|
||||
return c
|
||||
|
|
@ -60,7 +60,7 @@ func (c *commonTableExpression) internalCTE() *jet.CommonTableExpression {
|
|||
|
||||
// ALIAS is used to create another alias of the CTE, if a CTE needs to appear multiple times in the main query.
|
||||
func (c *commonTableExpression) ALIAS(name string) SelectTable {
|
||||
return newSelectTable(c, name)
|
||||
return newSelectTable(c, name, nil)
|
||||
}
|
||||
|
||||
func toInternalCTE(ctes []CommonTableExpression) []*jet.CommonTableExpression {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue