Skip to content

Commit b6f8225

Browse files
committed
Revert "remove unnecessary function"
This reverts commit d710427.
1 parent d710427 commit b6f8225

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

internal/codegen/golang/postgresql_type.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,39 @@
11
package golang
22

33
import (
4+
"fmt"
45
"log"
6+
"strings"
57

68
"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
79
"github.com/sqlc-dev/sqlc/internal/codegen/sdk"
810
"github.com/sqlc-dev/sqlc/internal/debug"
911
"github.com/sqlc-dev/sqlc/internal/plugin"
1012
)
1113

14+
func parseIdentifierString(name string) (*plugin.Identifier, error) {
15+
parts := strings.Split(name, ".")
16+
switch len(parts) {
17+
case 1:
18+
return &plugin.Identifier{
19+
Name: parts[0],
20+
}, nil
21+
case 2:
22+
return &plugin.Identifier{
23+
Schema: parts[0],
24+
Name: parts[1],
25+
}, nil
26+
case 3:
27+
return &plugin.Identifier{
28+
Catalog: parts[0],
29+
Schema: parts[1],
30+
Name: parts[2],
31+
}, nil
32+
default:
33+
return nil, fmt.Errorf("invalid name: %s", name)
34+
}
35+
}
36+
1237
func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string {
1338
columnType := sdk.DataType(col.Type)
1439
notNull := col.NotNull || col.IsArray
@@ -530,7 +555,11 @@ func postgresType(req *plugin.GenerateRequest, options *opts.Options, col *plugi
530555
return "interface{}"
531556

532557
default:
533-
rel := col.Type
558+
rel, err := parseIdentifierString(columnType)
559+
if err != nil {
560+
// TODO: Should this actually return an error here?
561+
return "interface{}"
562+
}
534563
if rel.Schema == "" {
535564
rel.Schema = req.Catalog.DefaultSchema
536565
}

0 commit comments

Comments
 (0)