package bun

import (
	
	

	
	
)

type DropIndexQuery struct {
	baseQuery
	cascadeQuery

	concurrently bool
	ifExists     bool

	index schema.QueryWithArgs
}

func ( *DB) *DropIndexQuery {
	 := &DropIndexQuery{
		baseQuery: baseQuery{
			db:   ,
			conn: .DB,
		},
	}
	return 
}

func ( *DropIndexQuery) ( IConn) *DropIndexQuery {
	.setConn()
	return 
}

func ( *DropIndexQuery) ( interface{}) *DropIndexQuery {
	.setTableModel()
	return 
}

//------------------------------------------------------------------------------

func ( *DropIndexQuery) () *DropIndexQuery {
	.concurrently = true
	return 
}

func ( *DropIndexQuery) () *DropIndexQuery {
	.ifExists = true
	return 
}

func ( *DropIndexQuery) () *DropIndexQuery {
	.restrict = true
	return 
}

func ( *DropIndexQuery) ( string,  ...interface{}) *DropIndexQuery {
	.index = schema.SafeQuery(, )
	return 
}

//------------------------------------------------------------------------------

func ( *DropIndexQuery) () string {
	return "DROP INDEX"
}

func ( *DropIndexQuery) ( schema.Formatter,  []byte) ( []byte,  error) {
	if .err != nil {
		return nil, .err
	}

	 = append(, "DROP INDEX "...)

	if .concurrently {
		 = append(, "CONCURRENTLY "...)
	}
	if .ifExists {
		 = append(, "IF EXISTS "...)
	}

	,  = .index.AppendQuery(, )
	if  != nil {
		return nil, 
	}

	 = .appendCascade(, )

	return , nil
}

//------------------------------------------------------------------------------

func ( *DropIndexQuery) ( context.Context,  ...interface{}) (sql.Result, error) {
	,  := .AppendQuery(.db.fmter, .db.makeQueryBytes())
	if  != nil {
		return nil, 
	}

	 := internal.String()

	,  := .exec(, , )
	if  != nil {
		return nil, 
	}

	return , nil
}