对指定字段进行减一操作

@param mixed $fields 请参考 createField
@param mixed $where 请参考 _createWhere
@param int|float $diff 增加的数值
@return int 影响的行数
551136
public function decrease($fields, $where, float $diff = 1): int
    {
        return self::crease('-', $fields, $where, $diff);
    }
856572
protected function applyWhere(QueryBuilder $qb, array $where): void
    {
        $whereType = $this->getContext()->getDefinition()->getArgument('where')->getType();

        /** @var InputObjectDefinition $whereDefinition */
        $whereDefinition = $this->getContext()->getEndpoint()->getType($whereType);

        /** @var ObjectDefinition $node */
        $node = $this->getContext()->getEndpoint()->getType($this->getContext()->getDefinition()->getNode());

        foreach ($where as $filterName => $condition) {
            $filterDefinition = $whereDefinition->getField($filterName);

            //TODO: load filters from services
            /** @var FilterInterface $filter */
            $filter = (new \ReflectionClass($filterDefinition->getResolver()))->newInstanceWithoutConstructor();

            $fieldName = $filterDefinition->getMeta('filter_field');
            if ($fieldName && $node->hasField($fieldName)) {
                $relatedField = $node->getField($fieldName);
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node, $relatedField);
            } else {
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node);
            }

            $filter($filterContext, $qb, $condition);
        }
    }
552345
static function target_ids($where)
	{
		$xref_class_name = popval($where, 'xref_class_name');
		if(!$xref_class_name)
			$xref_class_name = get_called_class();

		$target_field_name = popval($where, 'target_field_name');
		if(!$target_field_name)
			$target_field_name = bors_foo($xref_class_name)->target_field_name();

		$xrefs = bors_find_all($xref_class_name, $where);

		return bors_field_array_extract($xrefs, $target_field_name);
	}
662867
public function sum($field, $where = null): float
    {
        return floatval(self::get(['sum(' . $field . ')' => 'sum'], $where));
    }
1346248
private function assembleWhere($where = array())
    {
        if (is_array($where)) {
            switch ($where['operator']) {
                case Operator::$equals:
                    return $this->buildEquals($where['field'], $where['value']);
                case Operator::$doesNotEqual:
                    return $this->buildDoesNotEqual($where['field'], $where['value']);
                case Operator::$greaterThanOrEqual:
                    return $this->buildGreaterThanOrEquals($where['field'], $where['value']);
                case Operator::$lessThanOrEqual:
                    return $this->buildLessThanOrEquals($where['field'], $where['value']);
                case Operator::$approximateEqual:
                    return $this->buildApproximatelyEquals($where['field'], $where['value']);
                case Operator::$startsWith:
                    return $this->buildStartsWith($where['field'], $where['value']);
                case Operator::$endsWith:
                    return $this->buildEndsWith($where['field'], $where['value']);
                case Operator::$contains:
                    return $this->buildContains($where['field'], $where['value']);
                case Operator::$wildcard:
                    return $this->buildWildcard($where['field']);
            }
        }

        return;
    }
767368
public function deleteFrom(string $table, array $where): int
    {
        $delete = new Delete($this->options);
        $sqlParams = $delete->buildQuery($table, $where);
        return $this->query($sqlParams->getSql(), $sqlParams->getParams())->getAffected();
    }
601826
public function row($fields = null, $where = null, $orderBy = null)
    {
        // 查询数据
        $row = parent::row($fields, $where, $orderBy);

        // 如果没有查到
        if (!$row) {
            $row = [];
        }
        // 构造 为行对象
        return new Row($this->tableName, $row);
    }
615495
public function findWhere(array $wheres, array $columns = ['*'])
    {
        return $this->mediator->transform($this->mediator(func_get_args()))->first();
    }
948288
public function addWhere(array $where): void
    {
        if (empty($where)) {
            return;
        }

        $firstClause = true;
        $this->statement .= ' WHERE ';
        foreach ($where as $clause) {
            if ($firstClause === false) {
                $this->statement .= ' ' . $clause['concatenator'] . ' ';
            }
            switch ($clause['operator']) {
                case 'IN':
                    $this->addWhereIn($clause['key'], $clause['value'], false);
                    break;
                case 'NOT IN':
                    $this->addWhereIn($clause['key'], $clause['value'], true);
                    break;
                case 'BETWEEN':
                    $this->addWhereBetween($clause['key'], $clause['value']['min'], $clause['value']['max']);
                    break;
                case 'NULL':
                    $this->addWhereNull($clause['key'], false);
                    break;
                case 'NOT NULL':
                    $this->addWhereNull($clause['key'], true);
                    break;
                default:
                    $this->addSimpleWhere($clause['key'], $clause['operator'], $clause['value']);
                    break;
            }

            $firstClause = false;
        }
    }
303074
static function diffField( $field1, $field2, $schema1Type, $schema2Type )
    {
        /* Type is always available */
        if ( $field1['type'] != $field2['type'] )
        {
            return array( 'different-options' => array( 'type' ), 'field-def' => $field2 );
        }

        $test_fields = array( 'default', 'not_null' );
        
        // Ignore length for int types
        if ( $field1['type'] === $field2['type'] && $field1['type'] !== 'int' )
            $test_fields[] = 'length';

        $different_options = array();

        foreach ( $test_fields as $test_field )
        {
            if ( isset( $field1[$test_field] ) )
            {
                if ( !isset( $field2[$test_field] ) ||
                     ( $field1[$test_field] != $field2[$test_field] ) )
                {
                    $different_options[] = $test_field;
                }
            }
            else
            {
                if ( isset( $field2[$test_field] ) && $field2[$test_field] )
                {
                    $different_options[] = $test_field;
                }
            }
        }

        if ( $different_options )
            return array( 'different-options' => $different_options, 'field-def' => $field2 );
        else
            return false;
    }
270569
public function whereExp($field, $where, array $bind = [], $logic = 'AND')
    {
        if ($bind) {
            $this->bindParams($where, $bind);
        }

        $this->options['where'][$logic][] = [$field, 'EXP', $this->raw($where)];

        return $this;
    }
121841
protected function describeWhereFields($where)
    {
        return implode(', ', array_map(function ($v, $k) {
            return sprintf("%s='%s'", $k, $v);
        }, $where, array_keys($where)));
    }
823923
public function select($table, $where = '', $fields = '*', $order = '', $limit = null, $offset = '')
    {
        $query = "SELECT $fields FROM $table "
                 .($where ? " WHERE $where " : '')
                 .($order ? " ORDER BY $order " : '')
                 .($limit ? " LIMIT $limit " : '')
                 .(($offset && $limit ? " OFFSET $offset " : ''));
                 
        $this->prepare($query);
    }
1199238
public static function count($where = null): int
    {
        $select = static::select();

        if ($where !== null) {
            if ($where instanceof Where) {
                $select->field('COUNT(*)', 'total');
                $select->where(clone $where);

            } else if (is_array($where)) {
                $select->field('COUNT(*)', 'total');
                foreach ($where as $field => $value) {
                    $select->where($field, $value);
                }

            } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
                $select->field('COUNT(' . static::$primaryKey . ')', 'total');
                $select->where(static::$primaryKey, $where);

            }
        } else {
            $pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
            $select->field('COUNT(' . $pk . ')', 'total');
        }

        $results = $select->fetchAll();

        if (isset($results[0])) {
            $r = $results[0];
            if (array_key_exists('total', $r)) {
                return (int)$r['total'];
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
1159359
function equal($field, $_where)
    {
        if ($_where instanceof SelectDB)
        {
            $where = $field.'=('.$_where->getsql().')';
        }
        else
        {
            $where = "`$field`='$_where'";
        }
        $this->where($where);
    }
1147594
function orwhere($where)
    {
        $args = func_get_args();
        if (count($args) == 1)
        {
            $where = $args[0];
        }
        else
        {
            list($field, $expr, $value) = $args;
            $where = '`'.str_replace('`', '', $field).'`' . $this->db->quote($expr) . " '".$this->db->quote($value)."'";
        }

        if ($this->where == "")
        {
            $this->where = "where " . $where;
        }
        else
        {
            $this->where = $this->where . " or " . $where;
        }
    }
873647
public function createCrease(string $field, string $op, $diff): string
    {
        // 检查参数
        if ($op != '-') {
            $op = '+';
        }

        // 字段名规范化
        $field = $this->markField($field);

        return $field . ' = ' . $field . ' ' . $op . ' ' . $diff;
    }