mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-22 15:53:36 +00:00
Prepare for v3
This commit is contained in:
@@ -29,18 +29,24 @@ func init() {
|
||||
|
||||
// NewEphemeral creates new mongo connection
|
||||
func NewEphemeral(URI string) (db *EphemeralDatabase, err error) {
|
||||
return NewEphemeralWithContext(context.Background(), URI)
|
||||
}
|
||||
|
||||
func NewEphemeralWithContext(ctx context.Context, URI string) (db *EphemeralDatabase, err error) {
|
||||
if URI == "" {
|
||||
URI = defaultURI
|
||||
}
|
||||
|
||||
name := primitive.NewObjectID().Hex()
|
||||
opts := options.Client().ApplyURI(URI)
|
||||
client, err := mongo.Connect(context.Background(), opts)
|
||||
client, err := mongo.Connect(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db = &EphemeralDatabase{Database: database.NewDatabase(client, name)}
|
||||
db = &EphemeralDatabase{Database: database.NewDatabase(ctx, client, name)}
|
||||
|
||||
return
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// Close the connection and drop database
|
||||
|
||||
Reference in New Issue
Block a user