Browse Source

added increment method to query builder.

Taylor Otwell 13 years ago
parent
commit
559785f168
2 changed files with 16 additions and 4 deletions
  1. 4 4
      laravel/database/grammars/grammar.php
  2. 12 0
      laravel/database/query.php

+ 4 - 4
laravel/database/grammars/grammar.php

@@ -325,7 +325,7 @@ class Grammar {
 	 * @param  array   $columns
 	 * @return string
 	 */
-	protected function columnize($columns)
+	public function columnize($columns)
 	{
 		return implode(', ', array_map(array($this, 'wrap'), $columns));
 	}
@@ -340,7 +340,7 @@ class Grammar {
 	 * @param  string  $value
 	 * @return string
 	 */
-	protected function wrap($value)
+	public function wrap($value)
 	{
 		if (strpos(strtolower($value), ' as ') !== false) return $this->alias($value);
 
@@ -376,7 +376,7 @@ class Grammar {
 	 * @param  array   $values
 	 * @return string
 	 */
-	protected function parameterize($values)
+	public function parameterize($values)
 	{
 		return implode(', ', array_map(array($this, 'parameter'), $values));
 	}
@@ -391,7 +391,7 @@ class Grammar {
 	 * @param  mixed   $value
 	 * @return string
 	 */
-	protected function parameter($value)
+	public function parameter($value)
 	{
 		return ($value instanceof Expression) ? $value->get() : '?';
 	}

+ 12 - 0
laravel/database/query.php

@@ -581,6 +581,18 @@ class Query {
 		return (int) $this->connection->pdo->lastInsertId($sequence);
 	}
 
+	/**
+	 * Increment the value of a column by a given amount.
+	 *
+	 * @param  string  $column
+	 * @param  int     $amount
+	 * @return int
+	 */
+	public function increment($column, $amount = 1)
+	{
+		return $this->update(array($column => Manager::raw($this->grammar->wrap($column).' + '.$amount)));
+	}
+
 	/**
 	 * Update an array of values in the database table.
 	 *