public function performInDatabase($databaseKey, $actions)
    {
        $backupDatabase = $this->currentDatabase;
        $this->amConnectedToDatabase($databaseKey);

        if (is_callable($actions)) {
            $actions($this);
            $this->amConnectedToDatabase($backupDatabase);
            return;
        }
        if (is_array($actions)) {
            $actions = ActionSequence::build()->fromArray($actions);
        }

        if (!$actions instanceof ActionSequence) {
            throw new \InvalidArgumentException("2nd parameter, actions should be callback, ActionSequence or array");
        }

        $actions->run($this);
        $this->amConnectedToDatabase($backupDatabase);
    }
public function performInDatabase($databaseKey, $actions)
    {
        $backupDatabase = $this->currentDatabase;
        $this->amConnectedToDatabase($databaseKey);

        if (is_callable($actions)) {
            $actions($this);
            $this->amConnectedToDatabase($backupDatabase);
            return;
        }
        if (is_array($actions)) {
            $actions = ActionSequence::build()->fromArray($actions);
        }

        if (!$actions instanceof ActionSequence) {
            throw new \InvalidArgumentException("2nd parameter, actions should be callback, ActionSequence or array");
        }

        $actions->run($this);
        $this->amConnectedToDatabase($backupDatabase);
    }
public function performInDatabase ( $ databaseKey , $ actions ) { $ backupDatabase = $ this -> currentDatabase ; $ this -> amConnectedToDatabase ( $ databaseKey ) ; if ( is_callable ( $ actions ) ) { $ actions ( $ this ) ; $ this -> amConnectedToDatabase ( $ backupDatabase ) ; return ; } if ( is_array ( $ actions ) ) { $ actions = ActionSequence :: build ( ) -> fromArray ( $ actions ) ; } if ( ! $ actions instanceof ActionSequence ) { throw new \ InvalidArgumentException ( "2nd parameter, actions should be callback, ActionSequence or array" ) ; } $ actions -> run ( $ this ) ; $ this -> amConnectedToDatabase ( $ backupDatabase ) ; }
Can be used with a callback if you don't want to change the current database in your test.

```php
<?php
$I->seeNumRecords(2, 'users');   //executed on default database
$I->performInDatabase('db_books', function($I) {
$I->seeNumRecords(30, 'books');  //executed on db_books database
});
$I->seeNumRecords(2, 'users');  //executed on default database
```
List of actions can be pragmatically built using `Codeception\Util\ActionSequence`:

```php
<?php
$I->performInDatabase('db_books', ActionSequence::build()
->seeNumRecords(30, 'books')
);
```
Alternatively an array can be used:

```php
$I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]);
```

Choose the syntax you like the most and use it,

Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to
exception on failure.

@param $databaseKey
@param \Codeception\Util\ActionSequence|array|callable $actions
@throws ModuleConfigException
Can be used with a callback if you don t want to change the current database in your test .