Skip to content

Commit

Permalink
Merge b804679 into 1817fa6
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Nov 8, 2020
2 parents 1817fa6 + b804679 commit 6841d94
Show file tree
Hide file tree
Showing 51 changed files with 1,784 additions and 622 deletions.
8 changes: 4 additions & 4 deletions doc/default.texy
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ A powerful abstraction layer for database. **Fast & Save**.

Supported platforms:

- **MySQL** via mysqli extension,
- **Postgres** via pgsql extension,
- **MS SQL Server** via sqlsrv extension.
- **MySQL** via `mysqli` or `pdo_mysql` extension,
- **Postgres** via `pgsql` or `pdo_pgsql` extension,
- **MS SQL Server** via `sqlsrv` extension.

Connection
==========

The connection instance is a main object that provides an API for accessing your database. Connection's constructor accepts a configuration array. The possible keys depend on the specific driver; some configuration keys are the shared for all drivers:

|* driver | driver name, use `mysqli`, `pgsql`, or `sqlsrv`
|* driver | driver name, use `mysqli`, `pgsql`, `sqlsrv`, `pdo_mysql`, `pdo_pgsql`
|* host | database server name
|* username | username for authentication
|* password | password for authentication
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Nextras Dbal
A powerful abstraction layer for a database. **Fast & Safe**.

Supported platforms:
- **MySQL** via `mysqli` extension,
- **PostgreSQL** via `pgsql` extension,
- **MySQL** via `mysqli` or `pdo_mysql` extension,
- **PostgreSQL** via `pgsql` or `pdo_pgsql` extension,
- **MS SQL Server** via `sqlsrv` extension.

Integrations:
Expand Down
62 changes: 62 additions & 0 deletions src/Bridges/NetteCaching/CachedPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Nextras\Dbal\Bridges\NetteCaching;


use DateInterval;
use DateTimeInterface;
use Nette\Caching\Cache;
use Nextras\Dbal\Platforms\IPlatform;

Expand Down Expand Up @@ -66,6 +68,66 @@ public function getPrimarySequenceName(string $table): ?string
}


public function formatString(string $value): string
{
return $this->platform->formatString($value);
}


public function formatStringLike(string $value, int $mode)
{
return $this->platform->formatStringLike($value, $mode);
}


public function formatJson($value): string
{
return $this->platform->formatJson($value);
}


public function formatBool(bool $value): string
{
return $this->platform->formatBool($value);
}


public function formatIdentifier(string $value): string
{
return $this->platform->formatIdentifier($value);
}


public function formatDateTime(DateTimeInterface $value): string
{
return $this->platform->formatDateTime($value);
}


public function formatLocalDateTime(DateTimeInterface $value): string
{
return $this->platform->formatLocalDateTime($value);
}


public function formatDateInterval(DateInterval $value): string
{
return $this->platform->formatDateInterval($value);
}


public function formatBlob(string $value): string
{
return $this->platform->formatBlob($value);
}


public function formatLimitOffset(?int $limit, ?int $offset): string
{
return $this->platform->formatLimitOffset($limit, $offset);
}


public function isSupported(int $feature): bool
{
return $this->platform->isSupported($feature);
Expand Down
12 changes: 7 additions & 5 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
use Nextras\Dbal\Utils\StrictObjectTrait;
use function array_unshift;
use function assert;
use function call_user_func_array;
use function is_array;
use function spl_object_hash;
use function str_replace;
use function ucfirst;
use function ucwords;


class Connection implements IConnection
Expand Down Expand Up @@ -189,7 +190,7 @@ public function getPlatform(): IPlatform
/** @inheritdoc */
public function createQueryBuilder(): QueryBuilder
{
return new QueryBuilder($this->driver);
return new QueryBuilder($this->getPlatform());
}


Expand Down Expand Up @@ -343,11 +344,12 @@ private function nativeQuery(string $sql): Result
private function createDriver(): IDriver
{
if (!isset($this->config['driver'])) {
throw new InvalidArgumentException('Undefined driver. Choose from: mysqli, pgsql, sqlsrv.');
throw new InvalidArgumentException('Undefined driver. Choose from: mysqli, pgsql, sqlsrv, pdo_mysql, pdo_pgsql.');
} elseif ($this->config['driver'] instanceof IDriver) {
return $this->config['driver'];
} else {
$name = ucfirst($this->config['driver']);
$driver = $this->config['driver'];
$name = ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $driver))));
$class = "Nextras\\Dbal\\Drivers\\{$name}\\{$name}Driver";
return new $class();
}
Expand All @@ -361,7 +363,7 @@ private function createSqlProcessor(): SqlProcessor
assert($factory instanceof ISqlProcessorFactory);
return $factory->create($this);
} else {
return new SqlProcessor($this->driver, $this->getPlatform());
return new SqlProcessor($this->getPlatform());
}
}
}
53 changes: 14 additions & 39 deletions src/Drivers/IDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Nextras\Dbal\Drivers;


use DateInterval;
use DateTimeInterface;
use DateTimeZone;
use Nextras\Dbal\Connection;
use Nextras\Dbal\Drivers\Exception\DriverException;
use Nextras\Dbal\Exception\NotSupportedException;
use Nextras\Dbal\ILogger;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Dbal\Result\Result;
Expand Down Expand Up @@ -54,6 +54,13 @@ public function isConnected(): bool;
public function getResourceHandle();


/**
* Returns connection time zone.
* If unsupported by driver, throws {@link NotSupportedException}.
*/
public function getConnectionTimeZone(): DateTimeZone;


/**
* Runs query and returns a result. Returns a null if the query does not select any data.
* @throws DriverException
Expand Down Expand Up @@ -97,6 +104,7 @@ public function getServerVersion(): string;

/**
* Pings server.
* Returns true if the ping was successful and connection is alive.
* @internal
*/
public function ping(): bool;
Expand Down Expand Up @@ -158,48 +166,15 @@ public function rollbackSavepoint(string $name): void;

/**
* Converts database value to php boolean.
* @param mixed $nativeType
* @return mixed
*/
public function convertToPhp(string $value, $nativeType);


public function convertStringToSql(string $value): string;


/**
* @param mixed $value
*/
public function convertJsonToSql($value): string;


/**
* @param int $mode -1 = left, 0 = both, 1 = right
* @param mixed $nativeType
* @return mixed
*/
public function convertLikeToSql(string $value, int $mode);


public function convertBoolToSql(bool $value): string;


public function convertIdentifierToSql(string $value): string;


public function convertDateTimeToSql(DateTimeInterface $value): string;


public function convertDateTimeSimpleToSql(DateTimeInterface $value): string;


public function convertDateIntervalToSql(DateInterval $value): string;


public function convertBlobToSql(string $value): string;
public function convertToPhp($value, $nativeType);


/**
* Adds driver-specific limit clause to the query.
* Converts string to safe escaped SQL expression including surrounding quotes.
*/
public function modifyLimitQuery(string $query, ?int $limit, ?int $offset): string;
public function convertStringToSql(string $value): string;
}
Loading

0 comments on commit 6841d94

Please sign in to comment.