diff options
Diffstat (limited to 'vendor/github.com/uptrace/bun/query_column_add.go')
-rw-r--r-- | vendor/github.com/uptrace/bun/query_column_add.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/vendor/github.com/uptrace/bun/query_column_add.go b/vendor/github.com/uptrace/bun/query_column_add.go index 30d76e610..dff514904 100644 --- a/vendor/github.com/uptrace/bun/query_column_add.go +++ b/vendor/github.com/uptrace/bun/query_column_add.go @@ -11,6 +11,8 @@ import ( type AddColumnQuery struct { baseQuery + + ifNotExists bool } func NewAddColumnQuery(db *DB) *AddColumnQuery { @@ -59,6 +61,11 @@ func (q *AddColumnQuery) ColumnExpr(query string, args ...interface{}) *AddColum return q } +func (q *AddColumnQuery) IfNotExists() *AddColumnQuery { + q.ifNotExists = true + return q +} + //------------------------------------------------------------------------------ func (q *AddColumnQuery) Operation() string { @@ -82,6 +89,10 @@ func (q *AddColumnQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte b = append(b, " ADD "...) + if q.ifNotExists { + b = append(b, "IF NOT EXISTS "...) + } + b, err = q.columns[0].AppendQuery(fmter, b) if err != nil { return nil, err @@ -99,11 +110,5 @@ func (q *AddColumnQuery) Exec(ctx context.Context, dest ...interface{}) (sql.Res } query := internal.String(queryBytes) - - res, err := q.exec(ctx, q, query) - if err != nil { - return nil, err - } - - return res, nil + return q.exec(ctx, q, query) } |