Helper function used to replace {@} alias with actual table name.

@param mixed $where

@return mixed
351078
protected function prepare($where)
    {
        if (is_string($where)) {
            return str_replace('{@}', $this->alias, $where);
        }

        if (!is_array($where)) {
            return $where;
        }

        $result = [];
        foreach ($where as $column => $value) {
            if (is_string($column) && !is_int($column)) {
                $column = str_replace('{@}', $this->alias, $column);
            }

            $result[$column] = !is_array($value) ? $value : $this->prepare($value);
        }

        return $result;
    }
339881
function buildWhere($where, $operand = "AND")
    {
        if (empty($where)) {
            return "";
        }

        if (is_array($where)) {
            $wheres = array();
            foreach ($where as $k => $w) {
                $wheres[] = "(" . $w . ")";
            }
            $where = implode(" $operand ", $wheres);
        }

        return " WHERE " . $where;
    }
333681
public function table($table, /*# string */ $alias = '')
    {
        $tbl = $this->fixTable($table, $alias);
        $clone = [] === $this->tables ? $this : clone $this;
        $clone->tables = $tbl;
        return $clone;
    }
475429
public function where($where)
    {
        //Argument 1 must be a string or array
        Argument::i()->test(1, 'string', 'array');
        
        if (is_string($where)) {
            $where = array($where);
        }
        
        $this->where = array_merge($this->where, $where);
        
        return $this;
    }
1301407
public function outerJoinOn($table, $where)
    {
        $where = func_get_args();
        $table = array_shift($where);

        $this->join[] = [self::OUTER, $table, $where, false];

        return $this;
    }
9029
public function setWhere(array $where)
    {
        // When the statement is empty set the
        // where property to null to prevent
        // empty statement errors.
        if (empty($where)) {
            // delete the current where statement
            $this->where = null;

            // Skip further execution
            return $this;
        }

        // Ensure the base $or clause
        if (! isset($where['$or'])) {
            // wrap the statement in an $or clause
            $where = ['$or' => [$where]];
        }

        // Fetch the last clause in the $or array
        // to allow further chaining it's required
        // to be wrapped in an @and statement.
        $lastClause = array_pop($where['$or']);

        if (! isset($lastClause['$and'])) {
            // Wrap in an @and statement
            $lastClause = ['$and' => [$lastClause]];
        }

        // Re-append the $and clause
        $where['$or'][] = $lastClause;

        // Replace the base where statement
        $this->where = $where;

        return $this;
    }
468864
public static function listDatabases($where = null)
    {
        $where = (array) $where;
        $where[] = 'datistemplate = false';
        $where = new QueryElement('WHERE', $where, ' AND ');

        return 'SELECT datname FROM pg_database ' . $where . ';';
    }
1264808
public function render($where){
        if(is_array($this->table)){
            $result = [];
            foreach($this->table as $a => $m){
                $query = $this->whereComplete($where, $a);
                if(is_array($query)) $result = array_merge($result, $query);
            }
        }else {
            $result = $this->whereComplete($where);
        }
        if($result == null) return " true ";

        $this->q = $this->whereCompleteParser($result);

        if(empty($this->q)) return null;
        else return $this->q;
    }
537354
public function get(array $where) {
        $options = [
            Db::OPTION_FETCH_MODE => $this->getFetchArgs(),
            'rowCallback' => [$this, 'unserialize']
        ];

        $qry = new TableQuery($this->name, $where, $this->db, $options);
        $qry->setLimit($this->getDefaultLimit())
            ->setOrder(...$this->getDefaultOrder());

        return $qry;
    }
814862
protected function where(array $where): string
	{
		if(is_array($where['column']))
		{
			$column = '(' . $this->columns($where['column'], false) . ')';

			$value = is_array($where['value']) ? '(' . $this->params($where['value']) . ')' : $this->param($where['value']);

			return $column . ' ' . $where['operator'] . ' ' . $value;
		}

		return $this->column($where['column']) . ' ' . $where['operator'] . ' ' . $this->param($where['value']);
	}
84588
public function delete($where = null)
    {
        if ($this->map) {
            $where = $this->map->where($where);
        }
        if ($this->fake) {
            return $this->fake->delete($where);
        }
        $pattern = 'DELETE FROM ?t WHERE ?w';
        $data = array($this->name, $where);
        return $this->db->query($pattern, $data)->ar();
    }
1063562
public function deleteFrom($table, $where = null)
    {
        $this->clear();

        if (isset($where)) {
            $this->where = "WHERE\n\t(" . $where . ")";
        }

        $this->start = "DELETE";
        $this->from($table);
        return $this;
    }
132085
public static function count($where)
     {
         $self = self::instance();
         $rows = new ModelArray();
         //
         $sql = 'select count(*) as cnt from '.$self->DBtable." where $where ";
         $data = Database::read($sql, 1);
         //
         return $data[0]['cnt'];
     }
400339
private function loadByWhere(array $where): Record
    {
        $this->_loaded = true;
        $this->_data = $this->_table->row('*', $where)->toArray();
        return $this;
    }
1185459
public static function delete($table, $where) {
        $delete = Delete::table($table);
        if (is_array($where)) {
            foreach ($where as $field => $value) {
                $delete->where($field, $value);
            }
        } else {
            $delete->where("id", $where);
        }
        return $delete->excuse();
    }
1073649
public function formatWhere(Predicate $where) {
        if ($where->getParams()) {
            return sprintf($this->getClause(self::WHERE), $this->formatPredicate($where));
        }

        return '';
    }
833560
protected function fixSql($where)
    {
        if ($where == parent::NO_MATCH_SQL) {
            return parent::MATCH_ALL_SQL;
        } elseif ($where == parent::MATCH_ALL_SQL) {
            return parent::NO_MATCH_SQL;
        } else {
            return "NOT ($where)";
        }
    }