本文整理汇总了PHP中Illuminate\Database\Connection::table方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::table方法的具体用法?PHP Connection::table怎么用?PHP Connection::table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Connection
的用法示例。
在下文中一共展示了Connection::table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: append
/**
* @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: checkIfHAshIsUnique
/**
* @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: getNickId
/**
* @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]);
}
}
示例4: run
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!");
}
示例5: it_appends_events
/**
* @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);
}
示例6: untranslatedQuery
/**
* 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: deleteReserved
/**
* 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();
}
示例8: getEventsByType
/**
* @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);
}
示例9: newQuery
/**
* 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;
}
示例10: count
/**
* 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();
}
示例11: newQuery
/**
* 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: seed
/**
* 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: getNextPreviousInternal
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: fetchAndCache
/**
* 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;
}
示例15: setUp
/**
* 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);
}