1. Go to this page and download the library: Download pbmengine/pbm-stream-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
# via helper
stream('logins')->record(['user' => 1, 'age' => 30]);
# via Facade
\Pbmengine\Stream\Facades\Stream::collection('logins')->record(['user' => 1, 'age' => 30]);
# record event
stream('logins')->record(['user' => 1, 'age' => 30]);
# update event
stream('logins')->updateEvent('<event id>', ['age' => 30]);
# update several events with condition
# field is the condition field with value
# e.g. field is userId and value is 300
# stream('logins')->updateEvents('userId', 300, ['age' => 30]);
# means: update all events where userId is 300 and set age to 30
stream('logins')->updateEvents('field', 'value', ['age' => 30]);
# update events where you have several = conditions
stream('logins')->updateEventsWithConditions([
'event' => 'items.purchased',
'customerId' => 5
], [
'age' => 30,
'itemsPurchased' => true
]);
# delete event
stream('logins')->deleteEvent('<event id>');
# get project information
stream()->project();
# get project collections
stream()->collections();
# get collection informations
stream('logins')->collection();
# validate collection event
stream('logins')->validateEvent(['user' => 2, 'age' => 10]);
# test event to check if it's a valid event for any collection
# you do not need any collection for this request
stream()->testEvent(['user' => 2, 'age' => 10]);
# create collection index
# timestamp and _id are automatically indexed
stream('logins')->createIndex('<field>');
# drop collection index
stream('logins')->dropIndex('<field>');
# query options
$response = stream('logins')
->query()
->select(['_id', 'event', 'itemPrice'])
->where('a', '=', 2)
->whereIn('<column>', ['array', '...'])
->orWhere('b', '>', 6)
->timeFrame('<start date iso 8601>', '<end date iso 8601>')
->timeFrame(TimeFrame::THIS_DAYS, 5)
->timeFrame(TimeFrame::PREVIOUS_DAYS, 6)
->groupBy('<column>') // (['field a', 'field b'])
->orderBy('<column>', 'asc') // second parameter is optional, default is asc
->orderByDesc('<column>') // order desc
->count(); // sum(field) | avg(field) | max(field) | min(field) | countUnique(field) | selectUnique(field)
// get events
$response = stream('pages')
->query()
->where('event', '=', 'page.viewed')
->orWhere('event', '=', 'login.viewed')
->take(10)
->orderByDesc('timestamp')
->get();
// get events with pagination
$response = stream('pages')
->query()
->where('event', '=', 'page.viewed')
->orderByDesc('timestamp')
->paginate(10, 1); // per page 10 events on page 1
# complex queries
# for more complex queries use the aggregate function
stream('pages')
->query()
->aggregate([
['$match' => ['event' => 'pageViewed']]
]);