1. Go to this page and download the library: Download gowork/dqo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gowork / dqo example snippets
final class UserTable extends GW\DQO\Table
{
public const ID = 'id';
public const EMAIL = 'email';
public const NAME = 'name';
public function id(): string
{
return $this->fieldPath(self::ID);
}
public function email(): string
{
return $this->fieldPath(self::EMAIL);
}
public function name(): string
{
return $this->fieldPath(self::NAME);
}
public function createRow(array $raw): UserRow
{
return new UserRow($raw, $this);
}
}
$userTable = new UserTable('user_alias');
$userTable->table(); // "user"
$userTable->alias(); // "user_alias"
$userTable->id(); // "user_alias.id"
$userTable->selectField(UserTable::ID); // "user_alias.id as user_alias_id"
final class UserRow extends ClientRow
{
public function id(): UserId
{
return $this->getThroughType('UserId', UserTable::ID);
}
public function name(): string
{
return $this->getString(UserTable::NAME);
}
public function email(): Email
{
return Email::fromString($this->getString(UserTable::EMAIL));
}
public function optionalSecondEmail(): ?Email
{
return $this->getThrough([Email::class, 'fromString'], UserTable::OPTIONAL_SECOND_EMAIL);
}
public function about(): ?string
{
return $this->getNullableString(UserTable::NAME);
}
}
$userTable = new UserTable();
$userRow = new UserRow($rowFromQuery, $userTable);
$table = new UserTable();
$builder = $builder->select(...$table->select(UserTable::ID, UserTable::email));
// or
$builder = $builder->select($table->selectField(UserTable::ID), $table->selectField(UserTable::email));
// or
$builder = $builder->select(...$table->selectAll());
$table = new UserTable();
// first add $table to builder so it can recognize `user.id`, `user.email` and create valid aliases...
$builder = $builder->from($table);
// ...then simply select
$builder = $builder->select($table->id(), $table->email());
$start = new DateTimeImmutable('first day of last month 00:00');
$end = new DateTimeImmutable('last day of last month 23:59');
$builder = $builder
->withTypes([DateTimeImmutable::class => 'datetime_immutable'])
->from($user)
->where("{$user->registered()} BETWEEN :start AND :end", ['start' => $start, 'end' => $end]);
/** @var array<string, mixed>|null $result one result row or null when there are no rows */
$result = $builder->fetch();
/** @var mixed|null $result one column from first result or null when no results */
$result = $builder->fetchColumn();
/** @var array<int, array<string, mixed>> $result fetch all result rows */
$result = $builder->fetchAll();
/**
* @var ArrayValue<array<string, mixed>> $result
* @see https://github.com/gowork/values
*/
$result = $builder->wrapAll();
/** @var int $result */
@result = $builder->count();
public function registerBundles(): array
{
$bundles = [
// ...
];
if ($this->getEnvironment() === 'dev') {
// ...
$bundles[] = new GW\DQO\Symfony\DatabaseAccessGeneratorBundle();
}
...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.