public function execute(QueryContext $context) { $query = $this->toQueryString($context); if (true === $this->insertGetId) { if (true === DB::insert($query, $context->getParams())) { return DB::table($this->schema->getName())->orderBy($this->schema->getAutoIncrementField(), 'DESC')->pluck($this->schema->getAutoIncrementField())->execute(); } } return DB::insert($query, $context->getParams()); }
public function save(array $fields = null) { $this->parseUpdateFields($fields); if (empty($this->updates)) { return true; } if ($this->exists) { $result = DB::table($this->schema->getName())->where($this->schema->getAutoIncrementField(), $this->fields[$this->schema->getAutoIncrementField()])->update($this->updates)->execute(); $this->updates = array(); return $result; } else { $id = DB::table($this->schema->getName())->insertGetId($this->updates)->execute(); if ($id > 0) { $this->setField($this->schema->getAutoIncrementField(), $id); $this->updates = array(); } return $id; } }
public function forceDelete() { return DB::transaction(function () { if (false === $this->beforeDelete()) { return false; } if (false === $this->beforeForceDelete()) { return false; } $key = $this->schema->getAutoIncrementField(); $result = DB::table($this->schema->getName())->where($key, $this->entity->{$key})->forceDelete()->execute(); if ($result) { $this->afterDelete($this->fields()); } if ($result) { $this->afterForceDelete($this->fields()); } return $result; }); }