Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix repositories for pgsql #86

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"yiisoft/assets": "^1.0@dev",
"yiisoft/auth": "^3.0@dev",
"yiisoft/cache": "^3.0@dev",
"yiisoft/cache-file": "^3.0@dev",
"yiisoft/data": "^3.0@dev",
"yiisoft/di": "^3.0@dev",
"yiisoft/event-dispatcher": "^3.0@dev",
Expand Down
2 changes: 1 addition & 1 deletion src/Blog/Archive/ArchiveRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function extractFromDateColumn(string $attr): Fragment
$str = ['year' => '%Y', 'month' => '%m', 'day' => '%d'][$attr];
return new Fragment("strftime('{$str}', post.published_at) {$attr}");
}
return new Fragment("extract({$attr} from post.published_at) {$attr}");
return new Fragment("extract({$attr} from post.published_at) \"{$attr}\"");
yiiliveext marked this conversation as resolved.
Show resolved Hide resolved
}

private function getDriver(): DriverInterface
Expand Down
6 changes: 4 additions & 2 deletions src/Blog/Tag/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getTagMentions(int $limit = 0): DataReaderInterface
->columns(['t.label', 'count(*) count'])
->innerJoin('post', 'p')->on('p.id', 'postTag.post_id')->onWhere(['p.public' => true])
->innerJoin('tag', 't')->on('t.id', 'postTag.tag_id')
->groupBy('tag_id');
->groupBy('t.label, tag_id');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also append a table name to tag_id?


/**
* Case 2 would look like:
Expand All @@ -88,7 +88,7 @@ public function getTagMentions(int $limit = 0): DataReaderInterface
->with('posts')
->buildQuery()
->columns(['label', 'count(*) count'])
->groupBy('tag.id');
->groupBy('tag.label, tag_id');

/**
* Case 3 would look like:
Expand All @@ -105,6 +105,7 @@ public function getTagMentions(int $limit = 0): DataReaderInterface
$case3 = $this
->select()
->groupBy('posts.@.tag_id') // relation posts -> pivot (@) -> column
->groupBy('label')
->buildQuery()
->columns(['label', 'count(*) count']);

Expand All @@ -123,6 +124,7 @@ public function getTagMentions(int $limit = 0): DataReaderInterface
$case4 = $postRepo
->select()
->groupBy('tags.@.tag_id') // relation tags -> pivot (@) -> column
->groupBy('tags.label')
->buildQuery()
->columns(['label', 'count(*) count']);

Expand Down