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:
68
internal/core/operator.go
Normal file
68
internal/core/operator.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/sqlc-dev/sqlc/internal/core/catalogdb"
|
||||
)
|
||||
|
||||
type OperatorSpec struct {
|
||||
Name string
|
||||
NamespaceOID int64
|
||||
DialectOID int64
|
||||
LeftTypeOID int64
|
||||
RightTypeOID int64
|
||||
ResultTypeOID int64
|
||||
ProcOID int64
|
||||
}
|
||||
|
||||
func (c *Catalog) CreateOperator(o OperatorSpec) (int64, error) {
|
||||
oid, err := c.q.CreateOperator(context.Background(), catalogdb.CreateOperatorParams{
|
||||
NamespaceOid: nullInt64(o.NamespaceOID),
|
||||
DialectOid: nullInt64(o.DialectOID),
|
||||
Name: o.Name,
|
||||
LeftTypeOid: nullInt64(o.LeftTypeOID),
|
||||
RightTypeOid: nullInt64(o.RightTypeOID),
|
||||
ResultTypeOid: o.ResultTypeOID,
|
||||
ProcOid: nullInt64(o.ProcOID),
|
||||
})
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("create operator %q: %w", o.Name, err)
|
||||
}
|
||||
return oid, nil
|
||||
}
|
||||
|
||||
type OperatorOverload struct {
|
||||
OID int64
|
||||
Name string
|
||||
LeftTypeOID int64
|
||||
RightTypeOID int64
|
||||
ResultTypeOID int64
|
||||
ProcOID int64
|
||||
}
|
||||
|
||||
// FindOperators returns the overloads of name matching the given operand types,
|
||||
// where a zero OID means "any".
|
||||
func (c *Catalog) FindOperators(name string, leftTypeOID, rightTypeOID int64) ([]OperatorOverload, error) {
|
||||
rows, err := c.q.FindOperators(context.Background(), catalogdb.FindOperatorsParams{
|
||||
Name: name,
|
||||
LeftTypeOid: leftTypeOID,
|
||||
RightTypeOid: rightTypeOID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find operators %q: %w", name, err)
|
||||
}
|
||||
out := make([]OperatorOverload, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
out = append(out, OperatorOverload{
|
||||
OID: r.Oid,
|
||||
Name: r.Name,
|
||||
LeftTypeOID: orZero(r.LeftTypeOid),
|
||||
RightTypeOID: orZero(r.RightTypeOid),
|
||||
ResultTypeOID: r.ResultTypeOid,
|
||||
ProcOID: orZero(r.ProcOid),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user