private function constructDatabase($db)
    {
        if (is_null($this->dbClass)) {
            if (is_array($db)) {
                if (array_keys($db) !== range(0, count($db) - 1)) {
                    $this->db = new Databases\AssociativeArray($db);
                } else {
                    $this->db = new Databases\NumericArray($db);
                }
            } elseif ($db instanceof \Illuminate\Support\Collection) {
                $this->db = new Databases\LaravelCollection($db);
            } elseif ($db instanceof \Illuminate\Database\Eloquent\Builder
                || $db instanceof \Illuminate\Database\Eloquent\Relations\Relation) {
                $this->db = new Databases\LaravelEloquent($db);
            } elseif (!is_object($db)) {
                throw new InvalidArgumentException('Database must be an object or array');
            } else {
                $class_name = get_class($db);

                throw new DomainException("Please add database class for handling $class_name objects");
            }
        } else {
            $this->db = new $dbClass($db);
        }
    }