table() public method

Begin a fluent query against a database table.
public table ( string $table ) : Builder
$table string
return Illuminate\Database\Query\Builder
 /**
  * @param EventStreamInterface $eventStream
  * @return void
  * @throws SerializationException
  */
 public function append(EventStreamInterface $eventStream)
 {
     $events = collect(iterator_to_array($eventStream))->map(function ($event) {
         /** @var EventInterface $event */
         return ['aggregate_root_id' => (string) $event->getAggregateRootId(), 'type' => get_class($event), 'payload' => $this->serializer->serialize($event)];
     });
     $this->db->table('events')->insert($events->toArray());
 }
示例#2
0
 /**
  * @param $table
  * @param $field
  * @param $hash
  * @param $min_length
  * @param $max_length
  * @return string
  */
 private function checkIfHAshIsUnique($table, $field, $hash, $min_length, $max_length)
 {
     if (!$this->db->table($table)->where($field, '=', $hash)->get()) {
         return $hash;
     } else {
         return $this->makeHAsh($table, $field, true, $min_length, $max_length);
     }
 }
示例#3
0
 /**
  * @param \Illuminate\Database\Connection $db
  * @param int                             $channelId
  * @param string                          $nick
  * @return int
  */
 protected function getNickId(Connection $db, $channelId, $nick)
 {
     $targetNick = $db->table('nicks')->select('id')->where('channel_id', '=', $channelId)->where('nick', '=', $nick)->first();
     if ($targetNick) {
         return $targetNick['id'];
     } else {
         return $db->table('nicks')->insertGetId(['channel_id' => $channelId, 'nick' => $nick]);
     }
 }
 public function run()
 {
     $this->database->table(DbEventStore::TABLE)->truncate();
     $startTaskList = new StartTaskListCommand(['Eat cake', 'Walk cake off', 'Rinse and repeat']);
     $this->service->handleStartTaskListCommand($startTaskList);
     $startTaskList = new StartTaskListCommand(['Read: Learn DDD', 'Read: Implementing DDD', 'Read: The data model resource book volume 1', 'Read: The data model resource book volume 2']);
     $this->service->handleStartTaskListCommand($startTaskList);
     $this->command->getOutput()->writeln("<info>Seeded:</info> Task Lists!");
 }
 /**
  * @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);
 }
 /**
  * Create and return a new query to identify untranslated records.
  *
  * @param string $locale
  * @return \Illuminate\Database\Query\Builder
  */
 protected function untranslatedQuery($locale)
 {
     $table = $this->model->getTable();
     return $this->database->table("{$table} as {$table}")->select("{$table}.id")->leftJoin("{$table} as e", function (JoinClause $query) use($table, $locale) {
         $query->on('e.namespace', '=', "{$table}.namespace")->on('e.group', '=', "{$table}.group")->on('e.item', '=', "{$table}.item")->where('e.locale', '=', $locale);
     })->where("{$table}.locale", $this->defaultLocale)->whereNull("e.id");
 }
示例#7
0
 /**
  * Delete a reserved job from the queue.
  *
  * @param  string  $queue
  * @param  string  $id
  * @return void
  */
 public function deleteReserved($queue, $id)
 {
     $this->database->beginTransaction();
     if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
         $this->database->table($this->table)->where('id', $id)->delete();
     }
     $this->database->commit();
 }
 /**
  * @param string[] $eventTypes
  * @param int $skip
  * @param int $take
  * @return DomainEventStream
  */
 public function getEventsByType($eventTypes, $skip, $take)
 {
     $rows = $this->db->table($this->eventStoreTableName)->select(['uuid', 'playhead', 'metadata', 'payload', 'recorded_on'])->whereIn('type', $eventTypes)->skip($skip)->take($take)->orderBy('recorded_on', 'asc')->get();
     $events = [];
     foreach ($rows as $row) {
         $events[] = $this->deserializeEvent($row);
     }
     return new \SmoothPhp\Domain\DomainEventStream($events);
 }
 /**
  * Create a new query builder instance.
  *
  * @param  $insert  boolean  Whether the query is an insert or not.
  *
  * @return \Illuminate\Database\Query\Builder
  */
 protected function newQuery($insert = false)
 {
     $query = $this->connection->table($this->table);
     if ($this->queryConstraint !== null) {
         $callback = $this->queryConstraint;
         $callback($query, $insert);
     }
     return $query;
 }
 /**
  * Counts current query.
  *
  * @return int
  */
 public function count()
 {
     $query = $this->query;
     // if its a normal query ( no union and having word ) replace the select with static text to improve performance
     $myQuery = clone $query;
     if (!Str::contains(Str::lower($myQuery->toSql()), 'union') && !Str::contains(Str::lower($myQuery->toSql()), 'having')) {
         $myQuery->select($this->connection->raw("'1' as row_count"));
     }
     return $this->connection->table($this->connection->raw('(' . $myQuery->toSql() . ') count_row_table'))->setBindings($myQuery->getBindings())->count();
 }
 /**
  * Create a new query builder instance.
  *
  * @return \Illuminate\Database\Query\Builder
  */
 protected function newQuery()
 {
     $query = $this->connection->table($this->table);
     foreach ($this->extraColumns as $key => $value) {
         $query->where($key, '=', $value);
     }
     if ($this->queryConstraint !== null) {
         $callback = $this->queryConstraint;
         $callback($query);
     }
     return $query;
 }
示例#12
0
 /**
  * Seed the given connection from the given path.
  *
  * @param  Illuminate\Database\Connection  $connection
  * @param  string  $path
  * @return int
  */
 public function seed(Connection $connection, $path)
 {
     $total = 0;
     foreach ($this->getFiles($path) as $file) {
         $records = $this->files->getRequire($file);
         // We'll grab the table name here, which could either come from the array or
         // from the filename itself. Then, we will simply insert the records into
         // the databases via a connection and fire an event noting the seeding.
         $table = $this->getTable($records, $file);
         $connection->table($table)->delete();
         $connection->table($table)->insert($records);
         $total += $count = count($records);
         // Once we have seeded the table, we will fire an event to let any listeners
         // know the tables have been seeded and how many records were inserted so
         // information can be presented to the developer about the seeding run.
         if (isset($this->events)) {
             $this->events->fire('illuminate.seeding', array($table, $count));
         }
     }
     return $total;
 }
示例#13
0
 private function getNextPreviousInternal(array $data, $prev = false)
 {
     $primary = $this->getPrimaryKey();
     $primaryFields = array_only($data, $primary);
     $select = $this->db->table($this->table)->select(array_keys($primaryFields))->limit(1);
     $op = $prev ? '<' : '>';
     foreach ($primaryFields as $col => $value) {
         $select->where($col, $op, $value);
         $select->orderBy($col, $prev ?: 'asc');
     }
     return $select;
 }
示例#14
0
 /**
  * Cache all configurations.
  *
  * @return void
  */
 public function fetchAndCache()
 {
     $this->removeCache();
     $configs = $this->cache->rememberForever('cartalyst.config', function () {
         return $this->database->table($this->databaseTable)->get();
     });
     $cachedConfigs = [];
     foreach ($configs as $key => $config) {
         $value = $this->parseValue($config->value);
         $cachedConfigs[$config->item] = $value;
         parent::set($config->item, $value);
     }
     $this->cachedConfigs = $cachedConfigs;
 }
 /**
  * setUp
  */
 public function setUp()
 {
     $configs = (include __DIR__ . '/../test_database.php');
     $config = array_get($configs, $this->getConfig());
     $dsn = sprintf('%s:dbname=%s', $config['driver'], $config['database']);
     $pdo = new PDO($dsn, $config['username'], $config['password']);
     $class = $this->getConnectionClass();
     $this->connection = new $class($pdo);
     $this->connection->getSchemaBuilder()->dropIfExists('riders');
     $this->connection->getSchemaBuilder()->dropIfExists('classes');
     $this->connection->getSchemaBuilder()->create('classes', function (Blueprint $table) {
         $table->integer('id')->primary();
         $table->string('name');
     });
     $this->connection->table('classes')->insert([['id' => '1', 'name' => 'class1'], ['id' => '2', 'name' => 'class2']]);
     $this->connection->getSchemaBuilder()->create('riders', function (Blueprint $table) {
         $table->increments('id')->primary();
         $table->integer('class_id')->index();
         $table->foreign('class_id')->references('id')->on('classes')->onUpdate('cascade');
         $table->string('name');
     });
     $this->sut = new ColumnCollectionFactory($this->connection);
 }
示例#16
0
 /**
  * Hydrates a node by querying the database for it
  * and updating it's reserved attributes from the
  * queried record.
  *
  * @param  Cartalyst\NestedSets\Nodes\NodeInterface  $node
  * @return void
  */
 public function hydrateNode(NodeInterface $node)
 {
     $table = $this->getTable();
     $attributes = $this->getReservedAttributeNames();
     $keyName = $this->baseNode->getKeyName();
     $result = $this->connection->table("{$table}")->where($keyName, '=', $key = $node->getAttribute($keyName))->first(array_values($attributes));
     if ($result === null) {
         throw new \RuntimeException("Attempting to hydrate non-existent node [{$key}].");
     }
     // We only want to update the attributes which
     // affect nested sets.
     $attributes = array_intersect_key((array) $result, array_flip($attributes));
     foreach ($attributes as $key => $value) {
         $node->setAttribute($key, $value);
     }
 }
 /**
  * @param Table $table
  * @return array [Collection, Collection]
  */
 protected function getForeignKeys(Table $table)
 {
     $foreignTables = Collection::make([]);
     $foreignKeyColumns = Collection::make([]);
     Collection::make($table->getForeignKeys())->each(function (ForeignKeyConstraint $key) use($foreignTables, $foreignKeyColumns) {
         if (count($key->getLocalColumns()) != 1) {
             return;
         }
         $column = $key->getLocalColumns()[0];
         $table = $key->getForeignTableName();
         $foreignKeyColumns->put($column, $table);
         if ($foreignTables->has($table)) {
             return;
         }
         $foreignTables->put($table, $this->connection->table($table)->orderBy('id')->lists('name', 'id'));
     });
     return [$foreignKeyColumns, $foreignTables];
 }
示例#18
0
 /**
  * Retrieve a user by the given credentials.
  *
  * @param  array  $credentials
  * @return \Illuminate\Auth\UserInterface|null
  */
 public function retrieveByCredentials(array $credentials)
 {
     // First we will add each credential element to the query as a where clause.
     // Then we can execute the query and, if we found a user, return it in a
     // generic "user" object that will be utilized by the Guard instances.
     $query = $this->conn->table($this->table);
     foreach ($credentials as $key => $value) {
         if (!str_contains($key, 'password')) {
             $query->where($key, $value);
         }
     }
     // Now we are ready to execute the query to see if we have an user matching
     // the given credentials. If not, we will just return nulls and indicate
     // that there are no matching users for these given credential arrays.
     $user = $query->first();
     if (!is_null($user)) {
         return new GenericUser((array) $user);
     }
 }
 /**
  * Restore the field type column to cache.
  *
  * @param Blueprint $table
  */
 public function restoreColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Translatable or no?
     $translatable = ends_with($table->getTable(), '_translations');
     // Restore the data.
     $results = $this->cache->get(__CLASS__ . $this->fieldType->getColumnName());
     foreach ($results as $result) {
         $result = (array) $result;
         $this->connection->table($table->getTable())->where($translatable ? 'entry_id' : 'id', array_pull($result, 'id'))->update($result);
     }
     $this->cache->forget(__CLASS__ . $this->fieldType->getColumnName());
 }
示例#20
0
 /**
  * Returns a query builder object for the given environment, group
  * and namespace.
  *
  * @param  string     $environment
  * @param  string     $group
  * @param  string     $namespace
  * @param bool|string $fallback
  * @return \Illuminate\Database\Query $query
  */
 protected function getGroupQuery($environment, $group, $namespace, $fallback = true)
 {
     $query = $this->database->table($this->databaseTable);
     if ($fallback === true) {
         $query->whereNested(function ($query) use($environment) {
             $query->where('environment', '=', '*');
             if ($environment != '*') {
                 $query->orWhere('environment', '=', $environment);
             }
         });
     } else {
         $query->where('environment', '=', $environment);
     }
     $query->where('group', '=', $group);
     if (isset($namespace)) {
         $query->where('namespace', '=', $namespace);
     } else {
         $query->whereNull('namespace');
     }
     if ($fallback === true) {
         $query->orderBy('environment');
     }
     return $query;
 }
示例#21
0
 /**
  * Delete a reserved job from the queue.
  *
  * @param string $queue        	
  * @param string $id        	
  * @return void
  */
 public function deleteReserved($queue, $id)
 {
     $this->database->table($this->table)->where('id', $id)->delete();
 }
 /**
  * Get a fresh query builder instance for the table.
  *
  * @return \Illuminate\Database\Query\Builder
  */
 protected function getQuery()
 {
     return $this->connection->table($this->table);
 }
 /**
  * @param string $database
  * @param string $table
  *
  * @return array
  */
 public function getTableSchema($database, $table)
 {
     $select = $this->connection->table('COLUMNS')->select(['COLUMN_NAME AS `column`', 'DATA_TYPE AS type', DB::raw('IF(INSTR(COLUMN_TYPE, "unsigned") > 0, 1, 0) AS `unsigned`'), 'COLUMN_DEFAULT AS `default`', DB::raw('IF(IS_NULLABLE = "YES", 1, 0) AS nullable'), DB::raw('IF(CHARACTER_MAXIMUM_LENGTH IS NULL, NUMERIC_PRECISION, CHARACTER_MAXIMUM_LENGTH) AS length'), 'NUMERIC_SCALE AS `decimal`', DB::raw('IF(DATA_TYPE IN ("enum", "set"), REPLACE(REPLACE(REPLACE(REPLACE(COLUMN_TYPE, "enum", ""), "set", ""), "(", ""), ")", ""), NULL) AS values'), 'CHARACTER_SET_NAME AS character_set', 'COLLATION_NAME AS collation'])->where('TABLE_SCHEMA', '=', $database)->where('TABLE_NAME', '=', $table)->orderBy('ORDINAL_POSITION', 'ASC');
     return $select->get();
 }
 /**
  * @param DomainMessage $domainMessage
  */
 private function insertEvent(DomainMessage $domainMessage)
 {
     $this->db->table($this->eventStoreTableName)->insert(['uuid' => (string) $domainMessage->getId(), 'playhead' => $domainMessage->getPlayHead(), 'metadata' => json_encode($this->serializer->serialize($domainMessage->getMetadata())), 'payload' => json_encode($this->serializer->serialize($domainMessage->getPayload())), 'recorded_on' => (string) $domainMessage->getRecordedOn(), 'type' => $domainMessage->getType()]);
 }
示例#25
0
 /**
  * {@inheritdoc}
  */
 public function down($id)
 {
     $this->connection->table($this->tableName)->where('version', $id)->delete();
     return $this;
 }
示例#26
0
 /**
  * Return the name of the users table.
  *
  * @return Illuminate\Database\Query\Builder
  */
 protected function newQuery()
 {
     return $this->database->table('users');
 }
示例#27
0
 /**
  * @param Connection $utnianos
  * @param $planes
  * @param $materias
  */
 private function importarCorrelativas(Connection $utnianos, $planes, $materias)
 {
     $correlativas = $utnianos->table('utnianos_correlativas')->get();
     $this->info(PHP_EOL . 'Importando correlativas');
     $bar = $this->output->createProgressBar(count($correlativas));
     foreach ($correlativas as $correlativa) {
         if (!isset($planes[$correlativa->IdPlan]) || !isset($materias[$correlativa->IdMateria]) || !isset($materias[$correlativa->IdRequerimiento])) {
             continue;
         }
         $tipoRequerimiento = null;
         if ($correlativa->TipoMateria == 'C') {
             if ($correlativa->TipoRequerimiento == 'C') {
                 $tipoRequerimiento = Correlativa::CURSADA_CURSADA;
             } elseif ($correlativa->TipoRequerimiento == 'F') {
                 $tipoRequerimiento = Correlativa::CURSADA_FINAL;
             }
         } elseif ($correlativa->TipoMateria == 'F') {
             if ($correlativa->TipoRequerimiento == 'C') {
                 $tipoRequerimiento = Correlativa::FINAL_CURSADA;
             } elseif ($correlativa->TipoRequerimiento == 'F') {
                 $tipoRequerimiento = Correlativa::FINAL_FINAL;
             }
         }
         Correlativa::create(['plan_id' => $planes[$correlativa->IdPlan], 'materia_id' => $materias[$correlativa->IdMateria], 'requerimiento_id' => $materias[$correlativa->IdRequerimiento], 'tipo_requerimiento' => $tipoRequerimiento]);
         $bar->advance();
     }
     $bar->finish();
 }
示例#28
0
 /**
  * Down
  *
  * @param Migration $migration
  * @return AdapterInterface
  */
 public function down(Migration $migration)
 {
     $this->adapter->table($this->tableName)->where('version', $migration->getVersion())->delete();
     return $this;
 }
示例#29
0
 /**
  * Get a query builder for the cache table.
  *
  * @return \Illuminate\Database\Query\Builder
  */
 protected function table()
 {
     return $this->connection->table($this->table);
 }
示例#30
0
 /**
  * Return the name of the users table.
  *
  * @return Illuminate\Database\Query\Builder
  */
 protected function newQuery()
 {
     return $this->database->table('member');
 }