| 84 | } |
| 85 | |
| 86 | func (o *Override) parse(req *plugin.GenerateRequest) (err error) { |
| 87 | // validate deprecated postgres_type field |
| 88 | if o.Deprecated_PostgresType != "" { |
| 89 | fmt.Fprintf(os.Stderr, "WARNING: \"postgres_type\" is deprecated. Instead, use \"db_type\" to specify a type override.\n") |
| 90 | if o.DBType != "" { |
| 91 | return fmt.Errorf(`Type override configurations cannot have "db_type" and "postres_type" together. Use "db_type" alone`) |
| 92 | } |
| 93 | o.DBType = o.Deprecated_PostgresType |
| 94 | } |
| 95 | |
| 96 | // validate deprecated null field |
| 97 | if o.Deprecated_Null { |
| 98 | fmt.Fprintf(os.Stderr, "WARNING: \"null\" is deprecated. Instead, use the \"nullable\" field.\n") |
| 99 | o.Nullable = true |
| 100 | } |
| 101 | |
| 102 | schema := "public" |
| 103 | if req != nil && req.Catalog != nil { |
| 104 | schema = req.Catalog.DefaultSchema |
| 105 | } |
| 106 | |
| 107 | // validate option combinations |
| 108 | switch { |
| 109 | case o.Column != "" && o.DBType != "": |
| 110 | return fmt.Errorf("Override specifying both `column` (%q) and `db_type` (%q) is not valid.", o.Column, o.DBType) |
| 111 | case o.Column == "" && o.DBType == "": |
| 112 | return fmt.Errorf("Override must specify one of either `column` or `db_type`") |
| 113 | } |
| 114 | |
| 115 | // validate Column |
| 116 | if o.Column != "" { |
| 117 | colParts := strings.Split(o.Column, ".") |
| 118 | switch len(colParts) { |
| 119 | case 2: |
| 120 | if o.ColumnName, err = pattern.MatchCompile(colParts[1]); err != nil { |
| 121 | return err |
| 122 | } |
| 123 | if o.TableRel, err = pattern.MatchCompile(colParts[0]); err != nil { |
| 124 | return err |
| 125 | } |
| 126 | if o.TableSchema, err = pattern.MatchCompile(schema); err != nil { |
| 127 | return err |
| 128 | } |
| 129 | case 3: |
| 130 | if o.ColumnName, err = pattern.MatchCompile(colParts[2]); err != nil { |
| 131 | return err |
| 132 | } |
| 133 | if o.TableRel, err = pattern.MatchCompile(colParts[1]); err != nil { |
| 134 | return err |
| 135 | } |
| 136 | if o.TableSchema, err = pattern.MatchCompile(colParts[0]); err != nil { |
| 137 | return err |
| 138 | } |
| 139 | case 4: |
| 140 | if o.ColumnName, err = pattern.MatchCompile(colParts[3]); err != nil { |
| 141 | return err |
| 142 | } |
| 143 | if o.TableRel, err = pattern.MatchCompile(colParts[2]); err != nil { |