Arg appends an input argument to the builder.
(a any)
| 3160 | |
| 3161 | // Arg appends an input argument to the builder. |
| 3162 | func (b *Builder) Arg(a any) *Builder { |
| 3163 | switch v := a.(type) { |
| 3164 | case nil: |
| 3165 | b.WriteString("NULL") |
| 3166 | return b |
| 3167 | case *raw: |
| 3168 | b.WriteString(v.s) |
| 3169 | return b |
| 3170 | case Querier: |
| 3171 | b.Join(v) |
| 3172 | return b |
| 3173 | } |
| 3174 | // Default placeholder param (MySQL and SQLite). |
| 3175 | format := "?" |
| 3176 | if b.postgres() { |
| 3177 | // Postgres' arguments are referenced using the syntax $n. |
| 3178 | // $1 refers to the 1st argument, $2 to the 2nd, and so on. |
| 3179 | format = "$" + strconv.Itoa(b.total+1) |
| 3180 | } |
| 3181 | if f, ok := a.(ParamFormatter); ok { |
| 3182 | format = f.FormatParam(format, &StmtInfo{ |
| 3183 | Dialect: b.dialect, |
| 3184 | }) |
| 3185 | } |
| 3186 | return b.Argf(format, a) |
| 3187 | } |
| 3188 | |
| 3189 | // Args appends a list of arguments to the builder. |
| 3190 | func (b *Builder) Args(a ...any) *Builder { |