snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
94
internal/engine/dolphin/utils.go
Normal file
94
internal/engine/dolphin/utils.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package dolphin
|
||||
|
||||
import (
|
||||
pcast "github.com/sqlc-dev/marino/ast"
|
||||
"github.com/sqlc-dev/marino/mysql"
|
||||
|
||||
"github.com/sqlc-dev/sqlc/internal/sql/ast"
|
||||
)
|
||||
|
||||
func (c *cc) parseTableName(n *pcast.TableName) *ast.TableName {
|
||||
return &ast.TableName{
|
||||
Schema: c.identifier(n.Schema.String()),
|
||||
Name: c.identifier(n.Name.String()),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cc) toList(node pcast.Node) *ast.List {
|
||||
var items []ast.Node
|
||||
switch n := node.(type) {
|
||||
case *pcast.TableName:
|
||||
if schema := n.Schema.String(); schema != "" {
|
||||
items = append(items, c.NewIdentifier(schema))
|
||||
}
|
||||
items = append(items, c.NewIdentifier(n.Name.String()))
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
return &ast.List{Items: items}
|
||||
}
|
||||
|
||||
func isNotNull(n *pcast.ColumnDef) bool {
|
||||
for i := range n.Options {
|
||||
if n.Options[i].Tp == pcast.ColumnOptionNotNull {
|
||||
return true
|
||||
}
|
||||
if n.Options[i].Tp == pcast.ColumnOptionPrimaryKey {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func convertToRangeVarList(list *ast.List, result *ast.List) {
|
||||
if len(list.Items) == 0 {
|
||||
return
|
||||
}
|
||||
switch rel := list.Items[0].(type) {
|
||||
|
||||
// Special case for joins in updates
|
||||
case *ast.JoinExpr:
|
||||
left, ok := rel.Larg.(*ast.RangeVar)
|
||||
if !ok {
|
||||
if list, check := rel.Larg.(*ast.List); check {
|
||||
convertToRangeVarList(list, result)
|
||||
} else if subselect, check := rel.Larg.(*ast.RangeSubselect); check {
|
||||
// Handle subqueries in JOIN clauses
|
||||
result.Items = append(result.Items, subselect)
|
||||
} else {
|
||||
panic("expected range var")
|
||||
}
|
||||
}
|
||||
if left != nil {
|
||||
result.Items = append(result.Items, left)
|
||||
}
|
||||
|
||||
right, ok := rel.Rarg.(*ast.RangeVar)
|
||||
if !ok {
|
||||
if list, check := rel.Rarg.(*ast.List); check {
|
||||
convertToRangeVarList(list, result)
|
||||
} else if subselect, check := rel.Rarg.(*ast.RangeSubselect); check {
|
||||
// Handle subqueries in JOIN clauses
|
||||
result.Items = append(result.Items, subselect)
|
||||
} else {
|
||||
panic("expected range var")
|
||||
}
|
||||
}
|
||||
if right != nil {
|
||||
result.Items = append(result.Items, right)
|
||||
}
|
||||
|
||||
case *ast.RangeVar:
|
||||
result.Items = append(result.Items, rel)
|
||||
|
||||
case *ast.RangeSubselect:
|
||||
result.Items = append(result.Items, rel)
|
||||
|
||||
default:
|
||||
panic("expected range var")
|
||||
}
|
||||
}
|
||||
|
||||
func isUnsigned(n *pcast.ColumnDef) bool {
|
||||
return mysql.HasUnsignedFlag(n.Tp.GetFlag())
|
||||
}
|
||||
Reference in New Issue
Block a user