| @@ 8-96 (lines=89) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTime; |
|
| 7 | ||
| 8 | class MysqlDailyMileRepository implements DailyMileRepositoryInterface |
|
| 9 | { |
|
| 10 | ||
| 11 | /** @var ConnectionLocator */ |
|
| 12 | protected $connections; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @param ConnectonLocator $connections |
|
| 16 | */ |
|
| 17 | public function __construct(ConnectionLocator $connections) |
|
| 18 | { |
|
| 19 | $this->connections = $connections; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param integer $limit |
|
| 24 | * @param integer $offset |
|
| 25 | * |
|
| 26 | * @return array|false |
|
| 27 | */ |
|
| 28 | public function getEntries($limit = null, $offset = 0) |
|
| 29 | { |
|
| 30 | $query = " |
|
| 31 | SELECT `id`, `entry_id`, `datetime` |
|
| 32 | FROM `jpemeric_stream`.`dailymile` |
|
| 33 | ORDER BY `datetime` DESC"; |
|
| 34 | if (!is_null($limit)) { |
|
| 35 | $query .= " |
|
| 36 | LIMIT {$offset}, {$limit}"; |
|
| 37 | } |
|
| 38 | ||
| 39 | return $this |
|
| 40 | ->connections |
|
| 41 | ->getRead() |
|
| 42 | ->fetchAll($query); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @param integer $entryId |
|
| 47 | * |
|
| 48 | * @return array|false |
|
| 49 | */ |
|
| 50 | public function getEntryByEntryId($entryId) |
|
| 51 | { |
|
| 52 | $query = " |
|
| 53 | SELECT * |
|
| 54 | FROM `jpemeric_stream`.`dailymile` |
|
| 55 | WHERE `entry_id` = :entry_id |
|
| 56 | LIMIT 1"; |
|
| 57 | ||
| 58 | $bindings = [ |
|
| 59 | 'entry_id' => $entryId, |
|
| 60 | ]; |
|
| 61 | ||
| 62 | return $this |
|
| 63 | ->connections |
|
| 64 | ->getRead() |
|
| 65 | ->fetchOne($query, $bindings); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @param integer $entryId |
|
| 70 | * @param string $entryType |
|
| 71 | * @param DateTime $datetime |
|
| 72 | * @param array $metadata |
|
| 73 | * |
|
| 74 | * @return |
|
| 75 | */ |
|
| 76 | public function insertEntry($entryId, $entryType, DateTime $datetime, array $metadata) |
|
| 77 | { |
|
| 78 | $query = " |
|
| 79 | INSERT INTO `jpemeric_stream`.`dailymile` |
|
| 80 | (`entry_id`, `type`, `datetime`, `metadata`) |
|
| 81 | VALUES |
|
| 82 | (:entry_id, :entry_type, :datetime, :metadata)"; |
|
| 83 | ||
| 84 | $bindings = [ |
|
| 85 | 'entry_id' => $entryId, |
|
| 86 | 'entry_type' => $entryType, |
|
| 87 | 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 88 | 'metadata' => json_encode($metadata), |
|
| 89 | ]; |
|
| 90 | ||
| 91 | return $this |
|
| 92 | ->connections |
|
| 93 | ->getWrite() |
|
| 94 | ->perform($query, $bindings); |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||
| @@ 8-96 (lines=89) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTime; |
|
| 7 | ||
| 8 | class MysqlGithubRepository implements GithubRepositoryInterface |
|
| 9 | { |
|
| 10 | ||
| 11 | /** @var ConnectionLocator */ |
|
| 12 | protected $connections; |
|
| 13 | ||
| 14 | /** |
|
| 15 | * @param ConnectonLocator $connections |
|
| 16 | */ |
|
| 17 | public function __construct(ConnectionLocator $connections) |
|
| 18 | { |
|
| 19 | $this->connections = $connections; |
|
| 20 | } |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @param integer $limit |
|
| 24 | * @param integer $offset |
|
| 25 | * |
|
| 26 | * @return array|false |
|
| 27 | */ |
|
| 28 | public function getEvents($limit = null, $offset = 0) |
|
| 29 | { |
|
| 30 | $query = " |
|
| 31 | SELECT `id`, `event_id`, `datetime` |
|
| 32 | FROM `jpemeric_stream`.`github` |
|
| 33 | ORDER BY `datetime` DESC"; |
|
| 34 | if (!is_null($limit)) { |
|
| 35 | $query .= " |
|
| 36 | LIMIT {$offset}, {$limit}"; |
|
| 37 | } |
|
| 38 | ||
| 39 | return $this |
|
| 40 | ->connections |
|
| 41 | ->getRead() |
|
| 42 | ->fetchAll($query); |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @param integer $eventId |
|
| 47 | * |
|
| 48 | * @return array|false |
|
| 49 | */ |
|
| 50 | public function getEventByEventId($eventId) |
|
| 51 | { |
|
| 52 | $query = " |
|
| 53 | SELECT * |
|
| 54 | FROM `jpemeric_stream`.`github` |
|
| 55 | WHERE `event_id` = :event_id |
|
| 56 | LIMIT 1"; |
|
| 57 | ||
| 58 | $bindings = [ |
|
| 59 | 'event_id' => $eventId, |
|
| 60 | ]; |
|
| 61 | ||
| 62 | return $this |
|
| 63 | ->connections |
|
| 64 | ->getRead() |
|
| 65 | ->fetchOne($query, $bindings); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @param integer $eventId |
|
| 70 | * @param string $eventType |
|
| 71 | * @param DateTime $datetime |
|
| 72 | * @param array $metadata |
|
| 73 | * |
|
| 74 | * @return |
|
| 75 | */ |
|
| 76 | public function insertEvent($eventId, $eventType, DateTime $datetime, array $metadata) |
|
| 77 | { |
|
| 78 | $query = " |
|
| 79 | INSERT INTO `jpemeric_stream`.`github` |
|
| 80 | (`event_id`, `type`, `datetime`, `metadata`) |
|
| 81 | VALUES |
|
| 82 | (:event_id, :event_type, :datetime, :metadata)"; |
|
| 83 | ||
| 84 | $bindings = [ |
|
| 85 | 'event_id' => $eventId, |
|
| 86 | 'event_type' => $eventType, |
|
| 87 | 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 88 | 'metadata' => json_encode($metadata), |
|
| 89 | ]; |
|
| 90 | ||
| 91 | return $this |
|
| 92 | ->connections |
|
| 93 | ->getWrite() |
|
| 94 | ->perform($query, $bindings); |
|
| 95 | } |
|
| 96 | } |
|
| 97 | ||