NaifyDb\Adapter\Pgsql クラス
extends
NaifyDb\Adapter\Adapter
implements
NaifyDb\Connection\ConnectionConfigInterface
PostgreSQL 接続設定ビルダー
PostgreSQL 用の DSN と認証情報を fluent API で組み立てる。
NaifyDb 側では ConnectionConfigInterface 実装として扱うため、
呼び出し側は PDO の接続文字列を直接意識せずに設定 object を渡せる。
役割:
- host / port / database / username / password をまとめる
- PostgreSQL 向けの DSN を安定して組み立てる
- sslmode や application_name のような一般的な接続属性を保持する
- metadata / describeTable() を通して PostgreSQL 方言の情報取得を提供する
使用例
$config = Pgsql::configure()
->host('127.0.0.1')
->port(5432)
->database('mydb')
->username('postgres')
->password('secret')
->sslmode('prefer')
->applicationName('naify-dev');
NaifyDb::configure()->loadConfig('reporting', $config)->apply();
$db = NaifyDb::db('reporting');
プロパティ
| 名前 | 型 | 説明 |
|---|---|---|
private
$host
|
string |
接続先ホスト |
private
$port
|
int |
接続先ポート |
private
$database
|
string |
データベース名 |
private
$username
|
string |
接続ユーザー名 |
private
$password
|
string |
接続パスワード |
private
$sslmode
|
?string |
libpq の sslmode |
private
$applicationName
|
?string |
接続の application_name |
メソッド
| メソッド | 説明 |
|---|---|
public
host(string $host): static
|
接続先ホストを設定する |
public
port(int $port): static
|
接続先ポートを設定する |
public
database(string $database): static
|
データベース名を設定する |
public
username(string $username): static
|
接続ユーザー名を設定する |
public
password(string $password): static
|
接続パスワードを設定する |
public
sslmode(?string $sslmode): static
|
libpq の sslmode を設定する
例: `disable`, `allow`, `prefer`, `require`, `verify-ca`, `verify-full` |
public
applicationName(?string $applicationName): static
|
接続の application_name を設定する
サーバー側のセッション観測やログで接続元を見分けたい時に使う。 |
public
override
toDsn(): string
|
PostgreSQL 用 DSN を生成する |
public
override
getUsername(): ?string
|
接続ユーザー名を返す 8.4 → property hooks |
public
override
getPassword(): ?string
|
接続パスワードを返す 8.4 → property hooks |
public
override
getMetadata(): MetadataInterface
|
PostgreSQL 用 metadata オブジェクトを返す |
public
override
describeTable(PDO $pdo, string $tableName): array
|
PostgreSQL のカラム情報を直接取得する
information_schema と pg_catalog を組み合わせて、 型、nullable、default、comment、PK、auto increment を共通形式へ寄せる。 |
private
normalizeSchemaAndTableName(string $tableName): array
|
`schema.table` を schema 名と table 名へ分解する
schema 省略時は PostgreSQL の一般的な既定値として `public` を使う。 |
継承プロパティ
| 名前 | 型 | 説明 | 継承元 |
|---|---|---|---|
protected
$extra
|
array |
ドライバー固有の追加設定置き場 | Adapter |
継承メソッド
| メソッド | 説明 | 継承元 |
|---|---|---|
public
static
configure(): static
|
インスタンスを生成する | Adapter |
public
set(): static
|
任意のプロパティを設定する | Adapter |
public
getOptions(): array
|
PDO オプションを取得する | Adapter |
public
quoteIdentifier(): string
|
識別子(テーブル名・カラム名)を明示的にクオートする | Adapter |
public
profiler(): static
|
クエリプロファイラを設定する | Adapter |
public
getProfiler(): ?QueryProfilerInterface
|
プロファイラのインスタンスを取得する | Adapter |
public
toArray(): array
|
設定を配列へエクスポートする | Adapter |
protected
parseTypeAndSize(): array
|
型文字列からデータ型とサイズを分離する | Adapter |