shaoner / ziti

MySQL ORM for Node.js
http://ziti.ewdl.org/
MIT License
3 stars 0 forks source link

Syntax to set field = f(field) using a mysql function or an affectation #4

Closed shaoner closed 9 years ago

shaoner commented 9 years ago

Purpose is to set a field using an SQL function:

Syntax:

User.update({ age: [ '?? + ?', 'age', 1 ] });
// UPDATE user SET `age` = `age` + 1

Aliases:

User.update({ age: ziti.$inc('age') });
// UPDATE user SET `age` = `age` + 1

or

User.update({ age: ziti.$inc });
// UPDATE user SET `age` = `age` + 1

Chain:

User.update({ age: ziti.$inc(ziti.$dec) });
// UPDATE user SET `age` = `age` - 1 + 1
Function name Description
$inc Increment a column
$dec Decrement a column
$div Divide a column
$idiv Integer division of a column
$mult Multiply a column
$mod Remainder of a column
$upper Sets a column to an uppercase column
$lower Sets a column to a lowercase column
$ceil Sets the smallest integer value not less than the column
$floor Sets the largest integer value not greater than the column
$ltrim Remove the leading space of a column
$rtrim Remove the trailing space of a column
$trim Remove the leading and trailing space of a column
$rand Sets a random pointing value between 0 and 1.0 a column
$pi Sets the pi value to a column
$hex Turns into a hexadecimal string representation of a column
$now Sets the current date and time
shaoner commented 9 years ago

See cca276e2145182eb3bf31e02c96f75e4a68a145d