Skip to content

Commit 12c7789

Browse files
committed
task: expose Statements through ParsedQuery object
- removed toQueryBuilder from parsedQuery
1 parent 1fa5721 commit 12c7789

File tree

71 files changed

+1940
-423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1940
-423
lines changed

.php-cs-fixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'Flow/Parquet/ThriftModel',
3737
'Flow/CLI/Tests/Integration',
3838
'Flow/ETL/Tests/Unit/Loader',
39-
'Flow/ETL/Tests/Unit/Exception'
39+
'Flow/ETL/Tests/Unit/Exception',
40+
'extension/pg-query-ext/ext',
4041
]);
4142

4243
return (new Config())
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Exception;
6+
7+
final class InvalidStatementException extends \RuntimeException
8+
{
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes;
6+
7+
use Flow\PostgreSql\AST\Nodes\Exception\InvalidStatementException;
8+
9+
/**
10+
* @template-covariant T
11+
*/
12+
interface Statement
13+
{
14+
/**
15+
* @template S of Statement<mixed>
16+
*
17+
* @param class-string<S> $statementClass
18+
*
19+
* @throws InvalidStatementException
20+
*
21+
* @return S
22+
*/
23+
public function assert(string $statementClass) : self;
24+
25+
/**
26+
* @return T
27+
*/
28+
public function raw();
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\{AlterCollationStmt, AlterDatabaseRefreshCollStmt, AlterDatabaseSetStmt, AlterDatabaseStmt, AlterDefaultPrivilegesStmt, AlterDomainStmt, AlterEnumStmt, AlterEventTrigStmt, AlterExtensionContentsStmt, AlterExtensionStmt, AlterFdwStmt, AlterForeignServerStmt, AlterFunctionStmt, AlterObjectDependsStmt, AlterObjectSchemaStmt, AlterOpFamilyStmt, AlterOperatorStmt, AlterOwnerStmt, AlterPolicyStmt, AlterPublicationStmt, AlterRoleSetStmt, AlterRoleStmt, AlterSeqStmt, AlterStatsStmt, AlterSubscriptionStmt, AlterSystemStmt, AlterTableMoveAllStmt, AlterTableSpaceOptionsStmt, AlterTableStmt, AlterTypeStmt, AlterUserMappingStmt, RenameStmt};
9+
10+
/**
11+
* Represents ALTER statements (ALTER TABLE, ALTER INDEX, ALTER ROLE, ALTER DATABASE, etc.).
12+
*
13+
* @implements Statement<AlterCollationStmt|AlterDatabaseRefreshCollStmt|AlterDatabaseSetStmt|AlterDatabaseStmt|AlterDefaultPrivilegesStmt|AlterDomainStmt|AlterEnumStmt|AlterEventTrigStmt|AlterExtensionContentsStmt|AlterExtensionStmt|AlterFdwStmt|AlterForeignServerStmt|AlterFunctionStmt|AlterObjectDependsStmt|AlterObjectSchemaStmt|AlterOperatorStmt|AlterOpFamilyStmt|AlterOwnerStmt|AlterPolicyStmt|AlterPublicationStmt|AlterRoleSetStmt|AlterRoleStmt|AlterSeqStmt|AlterStatsStmt|AlterSubscriptionStmt|AlterSystemStmt|AlterTableMoveAllStmt|AlterTableSpaceOptionsStmt|AlterTableStmt|AlterTypeStmt|AlterUserMappingStmt|RenameStmt>
14+
*/
15+
final readonly class AlterStatement implements Statement
16+
{
17+
use StatementTrait;
18+
19+
public function __construct(
20+
private AlterTableStmt|AlterDomainStmt|AlterFunctionStmt|AlterRoleStmt|AlterRoleSetStmt|AlterDatabaseStmt|AlterDatabaseSetStmt|AlterDatabaseRefreshCollStmt|AlterSeqStmt|AlterOwnerStmt|AlterObjectSchemaStmt|AlterObjectDependsStmt|AlterExtensionStmt|AlterExtensionContentsStmt|AlterFdwStmt|AlterForeignServerStmt|AlterUserMappingStmt|AlterTableSpaceOptionsStmt|AlterTableMoveAllStmt|AlterPolicyStmt|AlterPublicationStmt|AlterSubscriptionStmt|AlterDefaultPrivilegesStmt|AlterCollationStmt|AlterEnumStmt|AlterOperatorStmt|AlterOpFamilyStmt|AlterTypeStmt|AlterSystemStmt|AlterEventTrigStmt|AlterStatsStmt|RenameStmt $stmt,
21+
) {
22+
}
23+
24+
public function raw() : AlterTableStmt|AlterDomainStmt|AlterFunctionStmt|AlterRoleStmt|AlterRoleSetStmt|AlterDatabaseStmt|AlterDatabaseSetStmt|AlterDatabaseRefreshCollStmt|AlterSeqStmt|AlterOwnerStmt|AlterObjectSchemaStmt|AlterObjectDependsStmt|AlterExtensionStmt|AlterExtensionContentsStmt|AlterFdwStmt|AlterForeignServerStmt|AlterUserMappingStmt|AlterTableSpaceOptionsStmt|AlterTableMoveAllStmt|AlterPolicyStmt|AlterPublicationStmt|AlterSubscriptionStmt|AlterDefaultPrivilegesStmt|AlterCollationStmt|AlterEnumStmt|AlterOperatorStmt|AlterOpFamilyStmt|AlterTypeStmt|AlterSystemStmt|AlterEventTrigStmt|AlterStatsStmt|RenameStmt
25+
{
26+
return $this->stmt;
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\VacuumStmt;
9+
10+
/**
11+
* Represents ANALYZE statements.
12+
* Note: ANALYZE is parsed as VacuumStmt in PostgreSQL.
13+
*
14+
* @implements Statement<VacuumStmt>
15+
*/
16+
final readonly class AnalyzeStatement implements Statement
17+
{
18+
use StatementTrait;
19+
20+
public function __construct(
21+
private VacuumStmt $stmt,
22+
) {
23+
}
24+
25+
public function raw() : VacuumStmt
26+
{
27+
return $this->stmt;
28+
}
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\CallStmt;
9+
10+
/**
11+
* @implements Statement<CallStmt>
12+
*/
13+
final readonly class CallStatement implements Statement
14+
{
15+
use StatementTrait;
16+
17+
public function __construct(
18+
private CallStmt $stmt,
19+
) {
20+
}
21+
22+
public function raw() : CallStmt
23+
{
24+
return $this->stmt;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\CheckPointStmt;
9+
10+
/**
11+
* @implements Statement<CheckPointStmt>
12+
*/
13+
final readonly class CheckpointStatement implements Statement
14+
{
15+
use StatementTrait;
16+
17+
public function __construct(
18+
private CheckPointStmt $stmt,
19+
) {
20+
}
21+
22+
public function raw() : CheckPointStmt
23+
{
24+
return $this->stmt;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\ClosePortalStmt;
9+
10+
/**
11+
* @implements Statement<ClosePortalStmt>
12+
*/
13+
final readonly class CloseStatement implements Statement
14+
{
15+
use StatementTrait;
16+
17+
public function __construct(
18+
private ClosePortalStmt $stmt,
19+
) {
20+
}
21+
22+
public function raw() : ClosePortalStmt
23+
{
24+
return $this->stmt;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\ClusterStmt;
9+
10+
/**
11+
* @implements Statement<ClusterStmt>
12+
*/
13+
final readonly class ClusterStatement implements Statement
14+
{
15+
use StatementTrait;
16+
17+
public function __construct(
18+
private ClusterStmt $stmt,
19+
) {
20+
}
21+
22+
public function raw() : ClusterStmt
23+
{
24+
return $this->stmt;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\PostgreSql\AST\Nodes\Statement;
6+
7+
use Flow\PostgreSql\AST\Nodes\{Statement, StatementTrait};
8+
use Flow\PostgreSql\Protobuf\AST\CommentStmt;
9+
10+
/**
11+
* @implements Statement<CommentStmt>
12+
*/
13+
final readonly class CommentStatement implements Statement
14+
{
15+
use StatementTrait;
16+
17+
public function __construct(
18+
private CommentStmt $stmt,
19+
) {
20+
}
21+
22+
public function raw() : CommentStmt
23+
{
24+
return $this->stmt;
25+
}
26+
}

0 commit comments

Comments
 (0)