@param string $type
@param $source
@param $table
@param $on
@param array $params

@throws SqlException

@return $this
543445
private function join(string $type, $source, $table, $on = null, array $params = [])
    {
        if ($source) {
            $source = $this->getSourceName($source);
        }

        [$tableAlias, $tableName] = $this->dialect()->parseTable($table);

        if ($tableName instanceof SelectQuery) {
            if (!$tableAlias) {
                throw new SqlException('JOIN table should have an alias name.');
            }

            $tableKey = $tableAlias;
        } else {
            $tableKey = $tableAlias ?: $tableName;

            $tableName = $this->dialect()->quoteTable($tableName);
        }

        if ($tableAlias) {
            $tableAlias = $this->dialect()->quoteName($tableAlias);
        }

        if (is_callable($on)) {
            $conditions = new Conditions($this->dialect());

            call_user_func_array($on, [$conditions]);

            $on = $conditions;
        }

        if (is_scalar($on)) {
            $on = $this->dialect()->quote($on);
        }

        $this->addJoin($tableKey, $type, $source, $tableName, $tableAlias, $on, $params);

        return $this;
    }
155636
public function from($sources)
    {
        if (!$sources) {
            throw new SqlException("A `FROM` clause requires a non empty table.");
        }
        $sources = is_array($sources) ? $sources : func_get_args();
        $this->_parts['from'] += array_merge($this->_parts['from'], $sources);
        return $this;
    }
1265143
public function select($query, $params = [], $type = null) {

		$type = $type === null ? $this -> getEntityNamespace($this -> getTable()) : $type;

		if(null === $this -> getAdapter()) {
			return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
		}
		
		return new ResultSet($this -> getAdapter() -> query($query, $params) -> toArray(), $type, $this -> getAdapter());
	}
335367
protected function _run(string $type, string $table, string $sql=NULL, array $vals=NULL, bool $reset=TRUE): PDOStatement
	{
		if ($sql === NULL)
		{
			$sql = $this->_compile($type, $table);
		}

		if ($vals === NULL)
		{
			$vals = array_merge($this->state->getValues(), $this->state->getWhereValues());
		}

		$startTime = microtime(TRUE);

		$res = empty($vals)
			? $this->driver->query($sql)
			: $this->driver->prepareExecute($sql, $vals);

		$endTime = microtime(TRUE);
		$totalTime = number_format($endTime - $startTime, 5);

		// Add this query to the list of executed queries
		$this->_appendQuery($vals, $sql, (int) $totalTime);

		// Reset class state for next query
		if ($reset)
		{
			$this->resetQuery();
		}

		return $res;
	}
1042609
public function add(SourceTypeInterface $type, $alias)
    {
        if ($alias !== $type->getName()) {
            throw new SourceTypeException(sprintf('Mapper source type %s alias is not valid!', $alias));
        }

        $this->types[$alias] = $type;
    }
739380
public function addDebugListener($listener, $type = "")
    {
        if (!Text::isEmpty($type) && !in_array($type, ["exec", "query"])) {
            throw new DbException("Invalid filter type. Valid filter types are 'exec' and 'query'");
        }
        
        $types = Text::isEmpty($type)? ["exec", "query"]: [$type];
        foreach ($types as $type) {
            $this->_debugger->on($type, $listener);
        }
    }
614061
public function rightJoinOnTo($source, $table, $on)
    {
        $this->join('RIGHT', $source, $table, $on);

        return $this;
    }
1278882
public function log($type, $text, $source='')
    {
        $log = new Logs();
        $log->setType($type);
        $log->setSource($source);
        $log->setContent($text);

        $this->em->persist($log);
        $this->em->flush();

        return $log;
    }
639901
public function join($type, $table, array $relations = array())
    {
        $this->append(sprintf(' %s JOIN %s ', $type, $table));

        // Append relations if provided
        if (!empty($relations)) {
            // First on
            $this->on();

            $i = 0; // Iteration counter
            $count = count($relations);

            foreach ($relations as $column => $value) {
                // Increment iteration count
                $i++;

                $this->equals($column, $value);

                // If last iteration
                if ($i != $count) {
                    $this->rawAnd();
                }
            }
        }

        return $this;
    }
1301072
public function join(string $to, string $as, string $on, $onParams = null, string $type = ''): self
    {
        return $this->push('join', sprintf('%sJOIN %s AS %s ON (%s)',
            $type ? strtoupper($type) .' ' : '',
            $this->prepareField($to),
            $this->agent->quoteField($as),
            $this->agent->prepareIdentifier($on, $onParams))
        );
    }
373828
protected function write($name, $type, $source, $dependencies = array())
    {
        $types = array(
            'script' => 'script',
            'style'  => 'style',
            'js'     => 'script',
            'css'    => 'style'
        );

        if (array_key_exists($type, $types))
        {
            $type = $types[$type];

            $this->register($type, $name, $source, $dependencies, array());
        }

        return $this;
    }
23144
protected function query_start($sql, array $params = null, $type, $extrainfo = null) {
        parent::query_start($sql, $params, $type, $extrainfo);
    }
1043739
public <S> S queryOne(Class<S> type, String sql, Object[] params) {
        Connection conn = getConn();
        try {
            Query query = conn.createQuery(sql)
                    .withParams(params)
                    .setAutoDeriveColumnNames(true)
                    .throwOnMappingFailure(false);

            return ifReturn(AnimaUtils.isBasicType(type),
                    () -> query.executeScalar(type),
                    () -> query.executeAndFetchFirst(type));
        } finally {
            this.closeConn(conn);
            this.clean(null);
        }
    }
408334
public function query($type = 'object')
    {
        $sql = 'select '.$this->columns.' from '.$this->getTables($this->tables).' '.$this->where.' '.$this->order.' '.$this->group;

        static::$sql = static::$register[] = $sql;
        //
        if ($data = Database::read($sql)) {
            return self::fetch($data, $type);
        } elseif (Database::execerr()) {
            throw new QueryException();
        }
    }
769257
public static function setTableName($type = 'access', $tableName = 'access')
    {
        if (is_array($type)) {
            self::$tables = array_merge(self::$tables, $type);
        } else {
            self::$tables[$type] = $tableName;
        }
    }
875159
protected function _execute($type, $sql, $bind = [])
    {
        $context = $this->_context;

        $context->sql = $sql;
        $context->bind = $bind;

        $context->affected_rows = 0;

        $this->eventsManager->fireEvent('db:before' . ucfirst($type), $this);

        if ($context->connection) {
            $connection = $context->connection;
        } else {
            $connection = $this->poolManager->pop($this, $this->_timeout);
        }

        try {
            $start_time = microtime(true);
            $context->affected_rows = $connection->execute($sql, $bind);
            $elapsed = round(microtime(true) - $start_time, 3);
        } finally {
            if (!$context->connection) {
                $this->poolManager->push($this, $connection);
            }
        }

        $count = $context->affected_rows;
        $event_data = compact('count', 'sql', 'bind', 'elapsed');
        if (is_int($context->affected_rows)) {
            $this->eventsManager->fireEvent('db:after' . ucfirst($type), $this, $event_data);
        }

        $this->logger->info($event_data, 'db.' . $type);
        return $count;
    }
419974
public function join($type, $table, array $relations = array())
    {
        $this->queryBuilder->join($type, $table, $relations);
        return $this;
    }