Skip to content

Commit

Permalink
migrate to mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
ufaboy committed Nov 19, 2023
1 parent 278b5ae commit 824c4d0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"name": "ufaboy/library",
"description": "Yii 2 Library API",
"keywords": [
"yii2",
"framework",
Expand Down
35 changes: 23 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,30 @@ services:
- app

db:
image: postgres:15
image: mysql:8
container_name: basic-db
ports:
- "5432:5432"
- "3306:3306"
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}

adminer:
image: adminer
container_name: basic-adminer
ports:
- 8080:8080
depends_on:
- db
# db:
# image: postgres:15
# container_name: basic-db
# ports:
# - "5432:5432"
# environment:
# POSTGRES_USER: ${DB_USERNAME}
# POSTGRES_PASSWORD: ${DB_PASSWORD}
# POSTGRES_DB: ${DB_NAME}
#
# adminer:
# image: adminer
# container_name: basic-adminer
# ports:
# - 8080:8080
# depends_on:
# - db
21 changes: 13 additions & 8 deletions modules/api/models/BookSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,26 @@ public function search($params) {
'desc' => ['series.name' => SORT_DESC, 'book.id' => SORT_DESC],
];
$dataProvider->sort->attributes['rating'] = [
'asc' => [new Expression('rating ASC NULLS FIRST'), 'book.id' => SORT_ASC],
'desc' => [new Expression('rating DESC NULLS LAST'), 'book.id' => SORT_DESC],
'asc' => [new Expression('rating ASC'), 'book.id' => SORT_ASC],
'desc' => [new Expression('rating DESC'), 'book.id' => SORT_DESC],
];
$dataProvider->sort->attributes['updated_at'] = [
'asc' => [new Expression('updated_at ASC NULLS FIRST'), 'book.id' => SORT_ASC],
'desc' => [new Expression('updated_at DESC NULLS LAST'), 'book.id' => SORT_DESC],
'asc' => [new Expression('updated_at ASC'), 'book.id' => SORT_ASC],
'desc' => [new Expression('updated_at DESC'), 'book.id' => SORT_DESC],
];
$dataProvider->sort->attributes['view_count'] = [
'asc' => [new Expression('view_count ASC NULLS FIRST'), 'book.id' => SORT_ASC],
'desc' => [new Expression('view_count DESC NULLS LAST'), 'book.id' => SORT_DESC],
'asc' => [new Expression('view_count ASC'), 'book.id' => SORT_ASC],
'desc' => [new Expression('view_count DESC'), 'book.id' => SORT_DESC],
];
$dataProvider->sort->attributes['last_read'] = [
'asc' => [new Expression('last_read ASC NULLS FIRST'), 'book.id' => SORT_ASC],
'desc' => [new Expression('last_read DESC NULLS LAST'), 'book.id' => SORT_DESC],
'asc' => [new Expression('last_read ASC'), 'book.id' => SORT_ASC],
'desc' => [new Expression('last_read DESC'), 'book.id' => SORT_DESC],
];
return $dataProvider;
}
}

/*$dataProvider->sort->attributes['rating'] = [
'asc' => [new Expression('rating ASC NULLS FIRST'), 'book.id' => SORT_ASC],
'desc' => [new Expression('rating DESC NULLS LAST'), 'book.id' => SORT_DESC],
];*/

0 comments on commit 824c4d0

Please sign in to comment.