forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_default.go
More file actions
38 lines (30 loc) · 1005 Bytes
/
parse_default.go
File metadata and controls
38 lines (30 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build !windows && cgo
// +build !windows,cgo
package postgresql
import (
cgonodes "github.com/pganalyze/pg_query_go/v4"
wasinodes "github.com/wasilibs/go-pgquery"
"google.golang.org/protobuf/proto"
)
func parseNodes(input string) (*wasinodes.ParseResult, error) {
cgoRes, err := cgonodes.Parse(input)
if err != nil {
return nil, err
}
// It would be too tedious to maintain conversion logic in a way that
// can target the two types from different packages despite being identical.
// We go ahead and take a small performance hit by marshaling through
// protobuf to unify the types. We must use the wasilibs version because
// the upstream version requires cgo even when only accessing the proto.
resBytes, err := proto.Marshal(cgoRes)
if err != nil {
return nil, err
}
var wasiRes wasinodes.ParseResult
if err := proto.Unmarshal(resBytes, &wasiRes); err != nil {
return nil, err
}
return &wasiRes, nil
}
var Parse = parseNodes
var Fingerprint = cgonodes.Fingerprint