You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+104-2Lines changed: 104 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,7 @@ If you only want to write events in case a subject (such as `/books/42`) does no
73
73
use Thenativeweb\Eventsourcingdb\IsSubjectPristine;
74
74
75
75
$writtenEvents = $client->writeEvents([
76
-
// ...
76
+
// events
77
77
], [
78
78
new IsSubjectPristine('/books/42'),
79
79
]);
@@ -87,14 +87,30 @@ If you only want to write events in case the last event of a subject (such as `/
87
87
use Thenativeweb\Eventsourcingdb\IsSubjectOnEventId;
88
88
89
89
$writtenEvents = $client->writeEvents([
90
-
// ...
90
+
// events
91
91
], [
92
92
new IsSubjectOnEventId('/books/42', '0'),
93
93
]);
94
94
```
95
95
96
96
*Note that according to the CloudEvents standard, event IDs must be of type string.*
97
97
98
+
#### Using the `isEventQlTrue` precondition
99
+
100
+
If you want to write events depending on an EventQL query, use the `IsEventQlTrue` function to create a precondition:
101
+
102
+
```php
103
+
use Thenativeweb\Eventsourcingdb\IsEventQlTrue;
104
+
105
+
$writtenEvents = $client->writeEvents([
106
+
// events
107
+
], [
108
+
new IsEventQlTrue("FROM e IN events WHERE e.type == 'io.eventsourcingdb.library.book-borrowed' PROJECT INTO COUNT() < 10")
109
+
]);
110
+
```
111
+
112
+
*Note that the query must return a single row with a single value, which is interpreted as a boolean.*
113
+
98
114
### Reading Events
99
115
100
116
To read all events of a subject, call the `readEvents` function with the subject and an options object. Set the `recursive` option to `false`. This ensures that only events of the given subject are returned, not events of nested subjects.
@@ -348,6 +364,92 @@ foreach ($events as $event) {
348
364
}
349
365
```
350
366
367
+
### Registering an Event Schema
368
+
369
+
To register an event schema, call the `registerEventSchema` function and hand over an event type and the desired schema:
To list all subjects, call the `readSubjects` function with `/` as the base subject. The function returns an asynchronous iterator, which you can use e.g. inside a `foreach` loop:
394
+
395
+
```php
396
+
$subjects = $client->readSubjects('/');
397
+
398
+
foreach($subjects as $subject) {
399
+
// ...
400
+
}
401
+
```
402
+
403
+
If you only want to list subjects within a specific branch, provide the desired base subject instead:
404
+
405
+
```php
406
+
$subjects = $client->readSubjects('/books');
407
+
408
+
foreach($subjects as $subject) {
409
+
// ...
410
+
}
411
+
```
412
+
413
+
#### Aborting Listing
414
+
415
+
If you need to abort listing use `abortIn` before or within the `foreach` loop. The `abortIn` method expects the abort time in seconds. However, this only works if there is currently an iteration going on:
416
+
417
+
```php
418
+
$subjects = $client->readSubjects('/');
419
+
420
+
$client->abortIn(0.1);
421
+
foreach($subjects as $subject) {
422
+
// ...
423
+
$client->abortIn(0.1);
424
+
}
425
+
```
426
+
427
+
### Listing Event Types
428
+
429
+
To list all event types, call the `readEventTypes` function. The function returns an asynchronous iterator, which you can use e.g. inside a `foreach` loop:
430
+
431
+
```php
432
+
$eventTypes = $client->readEventTypes();
433
+
434
+
foreach($eventTypes as $eventType) {
435
+
// ...
436
+
}
437
+
```
438
+
439
+
#### Aborting Listing
440
+
441
+
If you need to abort listing use `abortIn` before or within the `foreach` loop. The `abortIn` method expects the abort time in seconds. However, this only works if there is currently an iteration going on:
442
+
443
+
```php
444
+
$eventTypes = $client->readEventTypes();
445
+
446
+
$client->abortIn(0.1);
447
+
foreach($eventTypes as $eventType) {
448
+
// ...
449
+
$client->abortIn(0.1);
450
+
}
451
+
```
452
+
351
453
### Using Testcontainers
352
454
353
455
Import the `Container` class, call the `start` function to run a test container, get a client, run your test code, and finally call the `stop` function to stop the test container:
0 commit comments