github.com/blend/go-sdk@v1.20220411.3/db/dbutil/drop_database.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package dbutil 9 10 import ( 11 "context" 12 "fmt" 13 14 "github.com/blend/go-sdk/db" 15 ) 16 17 // DropDatabase drops a database. 18 func DropDatabase(ctx context.Context, name string, opts ...db.Option) (err error) { 19 var conn *db.Connection 20 defer func() { 21 err = db.PoolCloseFinalizer(conn, err) 22 }() 23 24 conn, err = OpenManagementConnection(opts...) 25 if err != nil { 26 return 27 } 28 29 if err = CloseAllConnections(ctx, conn, name); err != nil { 30 return 31 } 32 33 _, err = conn.ExecContext(ctx, fmt.Sprintf("DROP DATABASE %s ", name)) 34 return 35 }