| @@ 8-113 (lines=106) @@ | ||
| 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 | public function getDailyMilesUpdatedSince(DateTime $datetime) |
|
| 69 | { |
|
| 70 | $query = " |
|
| 71 | SELECT * |
|
| 72 | FROM `jpemeric_stream`.`dailymile` |
|
| 73 | WHERE `updated_at` >= :last_update"; |
|
| 74 | ||
| 75 | $bindings = [ |
|
| 76 | 'last_update' => $datetime->format('Y-m-d H:i:s'), |
|
| 77 | ]; |
|
| 78 | ||
| 79 | return $this |
|
| 80 | ->connections |
|
| 81 | ->getRead() |
|
| 82 | ->fetchAll($query, $bindings); |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * @param integer $entryId |
|
| 87 | * @param string $entryType |
|
| 88 | * @param DateTime $datetime |
|
| 89 | * @param array $metadata |
|
| 90 | * |
|
| 91 | * @return |
|
| 92 | */ |
|
| 93 | public function insertEntry($entryId, $entryType, DateTime $datetime, array $metadata) |
|
| 94 | { |
|
| 95 | $query = " |
|
| 96 | INSERT INTO `jpemeric_stream`.`dailymile` |
|
| 97 | (`entry_id`, `type`, `datetime`, `metadata`) |
|
| 98 | VALUES |
|
| 99 | (:entry_id, :entry_type, :datetime, :metadata)"; |
|
| 100 | ||
| 101 | $bindings = [ |
|
| 102 | 'entry_id' => $entryId, |
|
| 103 | 'entry_type' => $entryType, |
|
| 104 | 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 105 | 'metadata' => json_encode($metadata), |
|
| 106 | ]; |
|
| 107 | ||
| 108 | return $this |
|
| 109 | ->connections |
|
| 110 | ->getWrite() |
|
| 111 | ->perform($query, $bindings); |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||
| @@ 8-100 (lines=93) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTime; |
|
| 7 | ||
| 8 | class MysqlGoodreadRepository implements GoodreadRepositoryInterface |
|
| 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 getReviews($limit = null, $offset = 0) |
|
| 29 | { |
|
| 30 | $query = " |
|
| 31 | SELECT `id`, `permalink`, `datetime` |
|
| 32 | FROM `jpemeric_stream`.`goodread` |
|
| 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 | public function getReviewByPermalink($permalink) |
|
| 46 | { |
|
| 47 | $query = " |
|
| 48 | SELECT * |
|
| 49 | FROM `jpemeric_stream`.`goodread` |
|
| 50 | WHERE `permalink` = :permalink |
|
| 51 | LIMIT 1"; |
|
| 52 | ||
| 53 | $bindings = [ |
|
| 54 | 'permalink' => $permalink, |
|
| 55 | ]; |
|
| 56 | ||
| 57 | return $this |
|
| 58 | ->connections |
|
| 59 | ->getRead() |
|
| 60 | ->fetchOne($query, $bindings); |
|
| 61 | } |
|
| 62 | ||
| 63 | public function getGoodreadsUpdatedSince(DateTime $datetime) |
|
| 64 | { |
|
| 65 | $query = " |
|
| 66 | SELECT * |
|
| 67 | FROM `jpemeric_stream`.`goodread` |
|
| 68 | WHERE `updated_at` >= :last_update"; |
|
| 69 | ||
| 70 | $bindings = [ |
|
| 71 | 'last_update' => $datetime->format('Y-m-d H:i:s'), |
|
| 72 | ]; |
|
| 73 | ||
| 74 | return $this |
|
| 75 | ->connections |
|
| 76 | ->getRead() |
|
| 77 | ->fetchAll($query, $bindings); |
|
| 78 | } |
|
| 79 | ||
| 80 | public function insertReview($permalink, $bookId, DateTime $datetime, array $metadata) |
|
| 81 | { |
|
| 82 | $query = " |
|
| 83 | INSERT INTO `jpemeric_stream`.`goodread` |
|
| 84 | (`permalink`, `book_id`, `datetime`, `metadata`) |
|
| 85 | VALUES |
|
| 86 | (:permalink, :book_id, :datetime, :metadata)"; |
|
| 87 | ||
| 88 | $bindings = [ |
|
| 89 | 'permalink' => $permalink, |
|
| 90 | 'book_id' => $bookId, |
|
| 91 | 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 92 | 'metadata' => json_encode($metadata), |
|
| 93 | ]; |
|
| 94 | ||
| 95 | return $this |
|
| 96 | ->connections |
|
| 97 | ->getWrite() |
|
| 98 | ->perform($query, $bindings); |
|
| 99 | } |
|
| 100 | } |
|
| 101 | ||
| @@ 8-102 (lines=95) @@ | ||
| 5 | use Aura\Sql\ConnectionLocator; |
|
| 6 | use DateTime; |
|
| 7 | ||
| 8 | class MysqlYouTubeRepository implements YouTubeRepositoryInterface |
|
| 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 | public function getYouTubes($limit = null, $offset = 0) |
|
| 23 | { |
|
| 24 | $query = " |
|
| 25 | SELECT `id`, `video_id`, `datetime` |
|
| 26 | FROM `jpemeric_stream`.`youtube` |
|
| 27 | ORDER BY `datetime` DESC"; |
|
| 28 | if (!is_null($limit)) { |
|
| 29 | $query .= " |
|
| 30 | LIMIT {$offset}, {$limit}"; |
|
| 31 | } |
|
| 32 | ||
| 33 | return $this |
|
| 34 | ->connections |
|
| 35 | ->getRead() |
|
| 36 | ->fetchAll($query); |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param integer $id |
|
| 41 | * |
|
| 42 | * @return array|false |
|
| 43 | */ |
|
| 44 | public function getYouTubeById($id) |
|
| 45 | { |
|
| 46 | $query = " |
|
| 47 | SELECT * |
|
| 48 | FROM `jpemeric_stream`.`youtube` |
|
| 49 | WHERE `id` = :id |
|
| 50 | LIMIT 1"; |
|
| 51 | $bindings = [ |
|
| 52 | 'id' => $id, |
|
| 53 | ]; |
|
| 54 | ||
| 55 | return $this |
|
| 56 | ->connections |
|
| 57 | ->getRead() |
|
| 58 | ->fetchOne($query, $bindings); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @param string $title |
|
| 63 | * |
|
| 64 | * @return array|false |
|
| 65 | */ |
|
| 66 | public function getYouTubeByVideoId($videoId) |
|
| 67 | { |
|
| 68 | $query = " |
|
| 69 | SELECT * |
|
| 70 | FROM `jpemeric_stream`.`youtube` |
|
| 71 | WHERE `video_id` = :video_id |
|
| 72 | LIMIT 1"; |
|
| 73 | $bindings = [ |
|
| 74 | 'video_id' => $videoId, |
|
| 75 | ]; |
|
| 76 | ||
| 77 | return $this |
|
| 78 | ->connections |
|
| 79 | ->getRead() |
|
| 80 | ->fetchOne($query, $bindings); |
|
| 81 | } |
|
| 82 | ||
| 83 | public function insertVideo($videoId, DateTime $datetime, array $metadata) |
|
| 84 | { |
|
| 85 | $query = " |
|
| 86 | INSERT INTO `jpemeric_stream`.`youtube` |
|
| 87 | (`video_id`, `datetime`, `metadata`) |
|
| 88 | VALUES |
|
| 89 | (:video_id, :datetime, :metadata)"; |
|
| 90 | ||
| 91 | $bindings = [ |
|
| 92 | 'video_id' => $videoId, |
|
| 93 | 'datetime' => $datetime->format('Y-m-d H:i:s'), |
|
| 94 | 'metadata' => json_encode($metadata), |
|
| 95 | ]; |
|
| 96 | ||
| 97 | return $this |
|
| 98 | ->connections |
|
| 99 | ->getWrite() |
|
| 100 | ->perform($query, $bindings); |
|
| 101 | } |
|
| 102 | } |
|
| 103 | ||