Db.Row Class
The class representing database row
Constructor
Item Index
Methods
Methods
beforeRemove
-
search_criteria
-
[callback=null]
Optional. If defined the method is called before taking actions to remove row. It can be used synchronously and can ignore callback but must return search_criteria object. If used asyncronously shall pass this object to callback
NOTE: if this method is defined but do not return result and do not call callback, the remove() method fails silently without changing database!!!
beforeRetrieve
-
search_criteria
-
[callback=null]
Optional. If defined the method is called before taking actions to retrieve row. It can be used synchronously and can ignore callback but must return search_criteria object. If used asyncronously shall pass this object to callback
NOTE: if this method is defined but do not return result and do not call callback, the retrieve() method fails silently!!!
beforeSave
-
modifiedFields
-
[callback=null]
Optional. If defined the method is called before taking actions to save row.
It can be used synchronously and can ignore callback but must return
modifiedFields
object. If used asyncronously shall pass this object
to callback
NOTE: if this method is defined but do returns null and do not call callback,
the save()
method fails silently without making any changes in the database!!!
copyFromRow
-
row
This function copies the members of another row, as well as the primary key, etc. and assigns it to this row.
Parameters:
-
row
Db.RowThe source row. Be careful -- In this case, Db does not check whether the class of the Db_Row matches. It leaves things up to you.
Returns:
returns this object, for chaining
getFields
()
Get plain object with the fields of the row
remove
-
[search_criteria=null]
-
[useIndex=false]
-
[callback=null]
Deletes the row from the database. If object has methods beforeRetrieve, beforeRetrieveExecute or afterRetrieveExecute, they may be triggered during this operation.
Parameters:
-
[search_criteria=null]
String | Object optionalYou can provide custom search criteria here, such as
{"tag.name LIKE ": this.name}
If this is left null, and this Db_Row was retrieved, then the db rows corresponding to the primary key are deleted. But if it wasn't retrieved, then the modified fields are used as the search criteria. -
[useIndex=false]
Boolean optionalIf true, the primary key is used in searching for rows to delete. An exception is thrown when some fields of the primary key are not specified
-
[callback=null]
Function optionalThis function is called when all queries have completed. The "this" object would be this row, now hydrated with values from the database. It is passed the following arguments: 1) errors: an Object. If there were any errors they will be passed along as documented in query.execute. If there were no errors, this will be null. 2) count: an Integer the number of rows deleted. If there were any errors, it will be passed nothing
retrieve
-
[fields='*']
-
[useIndex=false]
-
[modifyQuery=false]
-
[options=array()]
-
[callback=null]
Retrieves a row from the database. If object has methods beforeRetrieve, beforeRetrieveExecute or afterRetrieveExecute, they may be triggered during this operation.
Parameters:
-
[fields='*']
String optionalThe fields to retrieve and set in the Db_Row. This gets used if we make a query to the database.
-
[useIndex=false]
Boolean optionalIf true, the primary key is used in searching, and an exception is thrown when any fields of the primary key are not specified
-
[modifyQuery=false]
Array | Boolean optionalIf an array, the following keys are options for modifying the query. Any other keys will be sent to query.options(modifyQuery); You can call more methods, like limit, offset, where, orderBy, and so forth, on that Db_Query. After you have modified it sufficiently, get the ultimate result of this function, by calling the resume() method on the Db_Query object (via the chainable interface).
You can also pass true in place of the modifyQuery field to achieve the same effect as {"query": true}
-
[begin]
Boolean | String optionalthis will cause the query to have .begin() a transaction which locks the row for update. You should call .save(..., true) to unlock the row, otherwise other database connections trying to access the row will be blocked.
-
[rollbackIfMissing]
Boolean optionalIf begin is true, this option determines whether to rollback the transaction if the row we're trying to retrieve is missing. Defaults to false.
-
[ignoreCache]
Boolean optionalIf true, then call ignoreCache on the query
-
[caching]
Boolean optionalIf provided, then call caching() on the query, passing this value
-
[query]
Boolean optionalIf true, it will return a Db_Query that can be modified, rather than the result.
-
-
[options=array()]
Array optionalArray of options to pass to beforeRetrieve and afterFetch functions.
-
[callback=null]
Function optionalThis function is called when all queries have completed. The "this" object would be this row, now hydrated with values from the database. It is passed the following arguments: 1) errors: an Object. If there were any errors they will be passed along as documented in query.execute. If there were no errors, this will be null. 2) result: an array of rows retrieved. If error occured it will be passed nothing
rollback
-
[callback=null]
Rolls back the transaction
Parameters:
-
[callback=null]
Function optionalThis function is called when all queries have completed. The "this" object would be this row, now hydrated with values from the database. It is passed the following argument: errors: an Object. If there were any errors they will be passed along as documented in query.execute. If there were no errors, this will be null.
save
-
[onDuplicateKeyUpdate=false]
-
[commit=false]
-
[callback=null]
Saves the row in the database. If object has methods beforeRetrieve, beforeRetrieveExecute or afterRetrieveExecute, they may be triggered during this operation.
Parameters:
-
[onDuplicateKeyUpdate=false]
Boolean optionalIf MySQL is being used, you can set this to TRUE to add an ON DUPLICATE KEY UPDATE clause to the INSERT statement
-
[commit=false]
Boolean optionalIf this is TRUE, then the current transaction is committed right after the save. Use this only if you started a transaction before.
-
[callback=null]
Function optionalThis function is called when the queries have all completed. Its this object is the same as the one the save method is called on. It is passed the one optional argument: errors: an Object. If there were any errors, it will be passed error object as returned from query.execute. If successful, it will be passed nothing.
split
-
index
Set up temporary config for shard split
Parameters:
-
index
ObjectSplit shard index
- 'indexes->connection' section of sharding config. Shall contain 'fields' and 'partition' fields
- 'partition' field shall contain new points mapped to shards
- 'shards' section of config shall be already filled with new shards config