Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
1.3 kB · 53 lines
PHP
at dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?php
namespace SocialDept\AtpSignals\Storage;
use Illuminate\Database\Query\Builder;use Illuminate\Support\Facades\DB;use SocialDept\AtpSignals\Contracts\CursorStore;
class DatabaseCursorStore implements CursorStore{ protected string $table; protected ?string $connection;
public function __construct() { $this->table = config('signal.cursor_config.database.table', 'signal_cursors'); $this->connection = config('signal.cursor_config.database.connection'); }
public function get(): ?int { $cursor = $this->query() ->where('key', 'jetstream') ->value('cursor');
return $cursor ? (int) $cursor : null; }
public function set(int $cursor): void { $this->query() ->updateOrInsert( ['key' => 'jetstream'], [ 'cursor' => $cursor, 'updated_at' => now(), ] ); }
public function clear(): void { $this->query() ->where('key', 'jetstream') ->delete(); }
protected function query(): Builder { return DB::connection($this->connection) ->table($this->table); }}