storj/private/dbutil/tempdb/tempdb.go
Egon Elbre b9740f0c0a storage/cockroachkv: add ctx argument
Change-Id: Ib6c29f44722b0354afcd499a0e567f04aef7eb28
2020-01-13 15:57:47 +02:00

28 lines
910 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package tempdb
import (
"context"
"strings"
"github.com/zeebo/errs"
"storj.io/storj/private/dbutil"
"storj.io/storj/private/dbutil/cockroachutil"
"storj.io/storj/private/dbutil/pgutil"
)
// OpenUnique opens a temporary, uniquely named database (or isolated database schema)
// for scratch work. When closed, this database or schema will be cleaned up and destroyed.
func OpenUnique(ctx context.Context, connURL string, namePrefix string) (*dbutil.TempDatabase, error) {
if strings.HasPrefix(connURL, "postgres://") || strings.HasPrefix(connURL, "postgresql://") {
return pgutil.OpenUnique(ctx, connURL, namePrefix)
}
if strings.HasPrefix(connURL, "cockroach://") {
return cockroachutil.OpenUnique(ctx, connURL, namePrefix)
}
return nil, errs.New("OpenUnique does not yet support the db type for %q", connURL)
}