Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PHP client for [ClickHouse](https://clickhouse.com) — fast, lightweight, no de

- Sync & async (parallel) SELECT queries
- [Native query parameters](doc/native-params.md) — server-side `{name:Type}` binding, SQL injection impossible
- [Rich type system](doc/types.md) — Boolean, Int64, Decimal, UUID, IPv4/IPv6, DateTime64, Date32, Map, Tuple
- [Rich type system](doc/types.md) — Boolean, integer and floating-point types, Decimal, UUID, IPv4/IPv6, DateTime64, Date32, Map, Tuple
- Bulk inserts: arrays, CSV files, streams
- [Generators](doc/generators.md) — memory-efficient iteration for large resultsets
- HTTP compression (gzip) for inserts
Expand Down
17 changes: 17 additions & 0 deletions doc/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ All types implement `ClickHouseDB\Type\Type` interface and work with `insert()`,

## Numeric Types

### Integer and floating-point types

The integer types `Int8`, `Int16`, `Int32`, `Int64`, `Int128`, `Int256` and
`UInt8`, `UInt16`, `UInt32`, `UInt64`, `UInt128`, `UInt256`, plus `Float32`
and `Float64`, preserve their string representation when used in inserts,
bindings, or comparisons:

```php
use ClickHouseDB\Type\UInt128;

$db->insert('table', [[UInt128::fromString('340282366920938463463374607431768211455')]], ['value']);
```

### UInt64

Large unsigned integers that overflow PHP's `int` range.
Expand Down Expand Up @@ -44,6 +57,10 @@ $db->insert('table', [
], ['price']);
```

`Decimal32`, `Decimal64`, `Decimal128`, and `Decimal256` are available for
explicit ClickHouse decimal column types. ClickHouse `Bool` values use the
existing `Boolean` class because `Bool` is a reserved PHP keyword.

## Date & Time Types

### Date and DateTime
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PHP client for [ClickHouse](https://clickhouse.com) — fast, lightweight, zero

- Sync & async (parallel) SELECT queries
- [Native query parameters](native-params) — server-side `{name:Type}` binding, SQL injection impossible
- [Rich type system](types) — Boolean, Int64, Decimal, UUID, IPv4/IPv6, DateTime64, Date32, Map, Tuple
- [Rich type system](types) — Boolean, integer and floating-point types, Decimal, UUID, IPv4/IPv6, DateTime64, Date32, Map, Tuple
- Bulk inserts: arrays, CSV files, streams
- [Generators](generators) — memory-efficient iteration for large resultsets
- HTTP compression (gzip) for inserts
Expand Down
38 changes: 38 additions & 0 deletions src/Type/Decimal128.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Decimal128 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Decimal128 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Decimal256.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Decimal256 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Decimal256 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Decimal32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Decimal32 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Decimal32 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Decimal64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Decimal64 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Decimal64 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Float32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Float32 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Float32 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Float64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function is_numeric;

final class Float64 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (! is_numeric($value)) {
throw new InvalidArgumentException('Float64 expects a numeric string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Int128.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function preg_match;

final class Int128 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (preg_match('/^-?\d+$/', $value) !== 1) {
throw new InvalidArgumentException('Int128 expects an integer string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Int16.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function preg_match;

final class Int16 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (preg_match('/^-?\d+$/', $value) !== 1) {
throw new InvalidArgumentException('Int16 expects an integer string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
38 changes: 38 additions & 0 deletions src/Type/Int256.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ClickHouseDB\Type;

use InvalidArgumentException;

use function preg_match;

final class Int256 implements ScalarNumericType
{
public string $value;

private function __construct(string $value)
{
$this->value = $value;
}

public static function fromString(string $value): static
{
if (preg_match('/^-?\d+$/', $value) !== 1) {
throw new InvalidArgumentException('Int256 expects an integer string, got: ' . $value);
}

return new static($value);
}

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

public function __toString(): string
{
return $this->value;
}
}
Loading