@@ -53,29 +53,10 @@ func Parse(dataSourceName string) (opts []config.Option, connectorOpts []Connect
5353 }
5454 }
5555 if info .Params .Has ("go_query_bind" ) {
56- var binders []ConnectorOption
5756 queryTransformers := strings .Split (info .Params .Get ("go_query_bind" ), "," )
58- for _ , transformer := range queryTransformers {
59- switch transformer {
60- case "declare" :
61- binders = append (binders , WithQueryBind (bind.AutoDeclare {}))
62- case "positional" :
63- binders = append (binders , WithQueryBind (bind.PositionalArgs {}))
64- case "numeric" :
65- binders = append (binders , WithQueryBind (bind.NumericArgs {}))
66- default :
67- if strings .HasPrefix (transformer , tablePathPrefixTransformer ) {
68- prefix , err := extractTablePathPrefixFromBinderName (transformer )
69- if err != nil {
70- return nil , nil , xerrors .WithStackTrace (err )
71- }
72- binders = append (binders , WithTablePathPrefix (prefix ))
73- } else {
74- return nil , nil , xerrors .WithStackTrace (
75- fmt .Errorf ("unknown query rewriter: %s" , transformer ),
76- )
77- }
78- }
57+ binders , err := bindTablePathPrefixInConnectorOptions (queryTransformers )
58+ if err != nil {
59+ return nil , nil , err
7960 }
8061 connectorOpts = append (connectorOpts , binders ... )
8162 }
@@ -96,3 +77,30 @@ func extractTablePathPrefixFromBinderName(binderName string) (string, error) {
9677
9778 return ss [0 ][1 ], nil
9879}
80+
81+ // bindTablePathPrefixInConnectorOptions binds table path prefix query transformers to a list of ConnectorOptions.
82+ func bindTablePathPrefixInConnectorOptions (queryTransformers []string ) ([]ConnectorOption , error ) {
83+ var binders []ConnectorOption
84+ for _ , transformer := range queryTransformers {
85+ switch transformer {
86+ case "declare" :
87+ binders = append (binders , WithQueryBind (bind.AutoDeclare {}))
88+ case "positional" :
89+ binders = append (binders , WithQueryBind (bind.PositionalArgs {}))
90+ case "numeric" :
91+ binders = append (binders , WithQueryBind (bind.NumericArgs {}))
92+ default :
93+ if strings .HasPrefix (transformer , tablePathPrefixTransformer ) {
94+ prefix , err := extractTablePathPrefixFromBinderName (transformer )
95+ if err != nil {
96+ return nil , xerrors .WithStackTrace (err )
97+ }
98+ binders = append (binders , WithTablePathPrefix (prefix ))
99+ } else {
100+ return nil , xerrors .WithStackTrace (fmt .Errorf ("unknown query rewriter: %s" , transformer ))
101+ }
102+ }
103+ }
104+
105+ return binders , nil
106+ }
0 commit comments