/** * Construct Closet object with owner's uid. * * @param int $uid */ public function __construct($uid) { $this->uid = $uid; $this->db = DB::table('closets'); // create a new closet if not exists if (!$this->db->where('uid', $uid)->get()) { $this->db->insert(['uid' => $uid, 'textures' => '']); } // load items from json string $this->textures = json_decode($this->db->where('uid', $uid)->get()[0]->textures, true); $this->textures = is_array($this->textures) ? $this->textures : []; $textures_invalid = []; // traverse items in the closet foreach ($this->textures as $texture) { $result = Texture::find($texture['tid']); if ($result) { // set user custom texture name $result->name = $texture['name']; // push instances of App\Models\Texture to the bag if ($result->type == "cape") { $this->textures_cape[] = $result; } else { $this->textures_skin[] = $result; } } else { $textures_invalid[] = $texture['tid']; continue; } } // remove invalid textures from closet foreach ($textures_invalid as $tid) { $this->remove($tid); } unset($textures_invalid); }
/** * @test */ public function it_appends_events() { $event = new PointsWereAdded(100); $stream = new EventStream($event); $eventData = ['aggregate_root_id' => 'BarId', 'type' => PointsWereAdded::class, 'payload' => ['amount' => '100']]; $this->db->table('events')->willReturn($this->queryBuilder); $this->serializer->serialize($event)->willReturn(['amount' => '100']); $this->queryBuilder->insert([$eventData])->willReturn(true); $this->eventStore->append($stream); }
/** * insert data * * @param array $args insert data * @return bool */ public function insert(array $args) { if ($this->dynamic === false) { return $this->query->insert($args); } $result = true; if (count($insert = $this->filter($args, $this->schema())) > 0) { $result = $this->query->insert($insert); } if ($this->proxy === true) { // autoincrement 가 primary key 일 경우 처리 할 것은? $this->getProxyManager()->insert($args); } return $result; }
/** * Insert a new record into the database. * * @param array $values * @return bool * @static */ public static function insert($values) { return \Illuminate\Database\Query\Builder::insert($values); }
private function insert($data) { foreach (array_chunk($data, 500) as $chunk) { $this->builder->insert($chunk); } }
/** * @param \Illuminate\Database\Query\Builder $builder * @param array $data */ protected function batchInsert(\Illuminate\Database\Query\Builder $builder, array $data) { $builder->getConnection()->transaction(function () use($builder, $data) { // Batch in group of 250 entries to prevent "Too many SQL variables" SQL error $insertBatchSize = 250; $insertBatchCount = ceil(count($data) / $insertBatchSize); for ($i = 0; $i < $insertBatchCount; ++$i) { $insertedData = array_slice($data, $i * $insertBatchSize, $insertBatchSize); $builder->insert($insertedData); } }); }
/** * Insert a new record into the database. * * @param array $values * * @return bool */ public function insert(array $values) { $result = parent::insert($values); $this->handler->setBuilder($this)->setValues($values)->setSqlOperation('insert')->invalidateQuery('insert'); return $result; }
public function insert(array $values) { if ($this->needFlushCache()) { // 清空表级缓存 $meta = $this->getMeta(); $meta->flush($this->db(), $this->model->table()); if (!is_array(reset($values))) { $values = [$values]; } $toClearIds = []; foreach ($values as $value) { $toClearIds[] = $value[$this->model->primaryKey()]; } $toClearKeys = $this->buildRowCacheKey($toClearIds); $this->getCache()->del(array_values($toClearKeys)); } return parent::insert($values); }
/** * Insert a new record into the database. * * @param array $values * * @return bool */ public function insert(array $values) { $result = parent::insert($values); $this->handler->setBuilder($this)->invalidateQuery(Reflector::QUERY_TYPE_INSERT, $values); return $result; }