/**
  * write
  *
  * @param string|int $id
  * @param string     $data
  *
  * @return  boolean
  */
 public function write($id, $data)
 {
     $writer = $this->db->getWriter();
     $data = array($this->options['data_col'] => $data, $this->options['time_col'] => (int) time(), $this->options['id_col'] => $id);
     $writer->updateOne($this->options['table'], $data, $this->options['id_col']);
     if ($writer->countAffected()) {
         return true;
     }
     $writer->insertOne($this->options['table'], $data, $this->options['id_col']);
     return true;
 }
Exemple #2
0
 /**
  * Method to store a row in the database from the AbstractTable instance properties.
  * If a primary key value is set the row with that primary key value will be
  * updated with the instance property values.  If no primary key value is set
  * a new row will be inserted into the database with the properties from the
  * AbstractTable instance.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  $this  Method allows chaining
  *
  * @since   2.0
  */
 public function store($updateNulls = false)
 {
     // Event
     $this->triggerEvent('onBefore' . ucfirst(__FUNCTION__), array('updateNulls' => &$updateNulls));
     // If a primary key exists update the object, otherwise insert it.
     if ($this->hasPrimaryKey()) {
         $this->db->getWriter()->updateOne($this->table, $this->data, $this->keys, $updateNulls);
     } else {
         $this->db->getWriter()->insertOne($this->table, $this->data, $this->keys[0]);
     }
     // Event
     $this->triggerEvent('onAfter' . ucfirst(__FUNCTION__));
     return $this;
 }
Exemple #3
0
 /**
  * Method to store a row in the database from the AbstractTable instance properties.
  * If a primary key value is set the row with that primary key value will be
  * updated with the instance property values.  If no primary key value is set
  * a new row will be inserted into the database with the properties from the
  * AbstractTable instance.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  $this  Method allows chaining
  *
  * @since   2.0
  */
 public function store($updateNulls = false)
 {
     // Event
     $this->triggerEvent('onBefore' . ucfirst(__FUNCTION__), array('updateNulls' => &$updateNulls));
     // Filter non-necessary field
     $data = array();
     foreach ($this->getFields() as $field => $value) {
         $data[$field] = $this->data->{$field};
     }
     // If a primary key exists update the object, otherwise insert it.
     if ($this->hasPrimaryKey()) {
         $this->db->getWriter()->updateOne($this->table, $data, $this->keys, $updateNulls);
     } else {
         $this->db->getWriter()->insertOne($this->table, $data, $this->keys[0]);
     }
     $this->data->{$this->keys[0]} = $data[$this->keys[0]];
     // Event
     $this->triggerEvent('onAfter' . ucfirst(__FUNCTION__));
     return $this;
 }
 /**
  * Do updateAll action.
  *
  * @param string  $table      The table name.
  * @param mixed   $data       The data we want to update to every rows.
  * @param mixed   $conditions Where conditions, you can use array or Compare object.
  *
  * @throws \Exception
  * @return  boolean
  */
 public function updateAll($table, $data, array $conditions = array())
 {
     return (bool) $this->db->getWriter()->updateBatch($table, $data, $conditions);
 }