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
18 changes: 9 additions & 9 deletions documentation/components/libs/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,9 @@ class ColumnCounter implements NodeVisitor
{
public int $count = 0;

public static function nodeClass(): string
public static function nodeClasses(): array
{
return ColumnRef::class;
return [ColumnRef::class];
}

public function enter(object $node): ?int
Expand Down Expand Up @@ -629,15 +629,15 @@ interface NodeVisitor
public const DONT_TRAVERSE_CHILDREN = 1;
public const STOP_TRAVERSAL = 2;

/** @return class-string */
public static function nodeClass(): string;
/** @return list<class-string> */
public static function nodeClasses(): array;

public function enter(object $node): ?int;
public function leave(object $node): ?int;
}
```

Visitors declare which node type they handle via `nodeClass()`. Return values:
Visitors declare which node types they handle via `nodeClasses()` (one or many). Return values:

- `null` - continue traversal
- `DONT_TRAVERSE_CHILDREN` - skip children (from `enter()` only)
Expand All @@ -663,9 +663,9 @@ use function Flow\PostgreSql\DSL\{sql_parse, sql_deparse};

final readonly class AddDistinctModifier implements NodeModifier
{
public static function nodeClass(): string
public static function nodeClasses(): array
{
return SelectStmt::class;
return [SelectStmt::class];
}

public function modify(object $node, ModificationContext $context): int|object|null
Expand All @@ -690,8 +690,8 @@ echo sql_deparse($query); // SELECT DISTINCT id, name FROM users
```php
interface NodeModifier
{
/** @return class-string */
public static function nodeClass(): string;
/** @return list<class-string> */
public static function nodeClasses(): array;

public function modify(object $node, ModificationContext $context): int|object|null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function get() : Catalog
),
schema_column_text('body', nullable: false),
schema_column_text('headers', nullable: false),
schema_column_varchar('queue_name', 190, nullable: false),
schema_column_varchar('queue_name', 190, nullable: false, default: 'default'),
schema_column_timestamp_tz('created_at', nullable: false),
schema_column_timestamp_tz('available_at', nullable: false),
schema_column_timestamp_tz('delivered_at', nullable: true),
],
primaryKey: schema_primary_key(['id']),
indexes: [
schema_index($this->tableName . '_queue_name_idx', ['queue_name']),
schema_index($this->tableName . '_available_at_idx', ['available_at']),
schema_index($this->tableName . '_delivered_at_idx', ['delivered_at']),
schema_index('idx_' . $this->tableName . '_queue_name', ['queue_name']),
schema_index('idx_' . $this->tableName . '_available_at', ['available_at']),
schema_index('idx_' . $this->tableName . '_delivered_at', ['delivered_at']),
],
schema: $this->schemaName,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ public function test_index_names_use_custom_table_name_prefix() : void
$provider->get()->get('public')->tables[0]->indexes,
);

self::assertContains('my_queue_queue_name_idx', $indexNames);
self::assertContains('my_queue_available_at_idx', $indexNames);
self::assertContains('my_queue_delivered_at_idx', $indexNames);
self::assertContains('idx_my_queue_queue_name', $indexNames);
self::assertContains('idx_my_queue_available_at', $indexNames);
self::assertContains('idx_my_queue_delivered_at', $indexNames);
}

public function test_queue_name_has_default_value() : void
{
$provider = new MessengerCatalogProvider();
$queueNameColumn = $provider->get()->get('public')->tables[0]->column('queue_name');

self::assertSame("'default'", $queueNameColumn->default);
}

public function test_table_has_custom_name_and_schema() : void
Expand Down
13 changes: 9 additions & 4 deletions src/lib/postgresql/src/Flow/PostgreSql/AST/NodeModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Flow\PostgreSql\AST;

use Google\Protobuf\Internal\Message;

/**
* Interface for AST node modifiers.
*
Expand All @@ -23,11 +25,14 @@ interface NodeModifier
public const STOP_TRAVERSAL = 2;

/**
* Returns the fully qualified class name of the node type this modifier handles.
* Returns the fully qualified class names of the node types this modifier handles.
*
* A modifier may handle more than one node type; the traverser will dispatch it
* for every type listed here.
*
* @return class-string The node class this modifier is registered for
* @return list<class-string<Message>> The node classes this modifier is registered for
*/
public static function nodeClass() : string;
public static function nodeClasses() : array;

/**
* Called to modify a node of the registered type.
Expand All @@ -38,7 +43,7 @@ public static function nodeClass() : string;
* - Return STOP_TRAVERSAL to stop the entire traversal
* - Return a new node to replace the current node (used for wrapping operations)
*
* @param object $node The node instance to modify (type depends on nodeClass())
* @param object $node The node instance to modify (one of the types listed in nodeClasses())
* @param ModificationContext $context Context providing parent information
*
* @return null|int|object
Expand Down
17 changes: 11 additions & 6 deletions src/lib/postgresql/src/Flow/PostgreSql/AST/NodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Flow\PostgreSql\AST;

use Google\Protobuf\Internal\Message;

/**
* Interface for AST node visitors.
*
* Visitors are registered for specific node types and only receive nodes of that type.
* Use the static nodeClass() method to declare which node type this visitor handles.
* Use the static nodeClasses() method to declare which node types this visitor handles.
*/
interface NodeVisitor
{
Expand All @@ -28,16 +30,19 @@ interface NodeVisitor
public const STOP_TRAVERSAL = 2;

/**
* Returns the fully qualified class name of the node type this visitor handles.
* Returns the fully qualified class names of the node types this visitor handles.
*
* A visitor may handle more than one node type; the traverser will dispatch it
* for every type listed here.
*
* @return class-string The node class this visitor is registered for
* @return list<class-string<Message>> The node classes this visitor is registered for
*/
public static function nodeClass() : string;
public static function nodeClasses() : array;

/**
* Called when entering a node of the registered type.
*
* @param object $node The node instance (type depends on nodeClass())
* @param object $node The node instance (one of the types listed in nodeClasses())
*
* @return null|int Return value determines traversal behavior:
* - null: Continue traversal
Expand All @@ -49,7 +54,7 @@ public function enter(object $node) : ?int;
/**
* Called when leaving a node of the registered type.
*
* @param object $node The node instance (type depends on nodeClass())
* @param object $node The node instance (one of the types listed in nodeClasses())
*
* @return null|int Return value determines traversal behavior:
* - null: Continue traversal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
*/
final readonly class CountModifier implements NodeModifier
{
public static function nodeClass() : string
public static function nodeClasses() : array
{
return SelectStmt::class;
return [SelectStmt::class];
}

/** @phpstan-ignore return.unusedType (interface requires full signature) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public function __construct(
) {
}

public static function nodeClass() : string
public static function nodeClasses() : array
{
return SelectStmt::class;
return [SelectStmt::class];
}

public function modify(object $node, ModificationContext $context) : ?object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function __construct(
) {
}

public static function nodeClass() : string
public static function nodeClasses() : array
{
return SelectStmt::class;
return [SelectStmt::class];
}

/** @phpstan-ignore return.unusedType (interface requires full signature) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function __construct(
) {
}

public static function nodeClass() : string
public static function nodeClasses() : array
{
return SelectStmt::class;
return [SelectStmt::class];
}

public function modify(object $node, ModificationContext $context) : int|object|null
Expand Down
Loading
Loading