Skip to content

Commit 059b2a4

Browse files
committed
fix: 处理部分情况下,postgres 数据库的兼容性问题;更新文档
1 parent 7d2baea commit 059b2a4

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

docs/deploy.md

+8
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ CACHE_CONTENT_EXPIRE=3600
219219

220220
# 🗄️ 数据库配置
221221

222+
注意:`SQLite` 数据库是优先支持的数据库(因为开发环境使用的是`SQLite`)。
223+
224+
`MySQL``PostgreSQL` 数据库**不会**优先支持,可能存在兼容性问题。如果遇到此类问题,请提 [issue](https://github.com/CaoMeiYouRen/rss-impact-server/issues)
225+
222226
## 使用 SQLite 数据库
223227

224228
无需特别配置
@@ -246,6 +250,8 @@ DATABASE_DATABASE='rss-impact'
246250
DATABASE_CHARSET='utf8_general_ci'
247251
# MySQL 服务器上配置的时区 (默认:local)
248252
DATABASE_TIMEZONE='local'
253+
# 带有 ssl 参数的对象
254+
DATABASE_SSL=false
249255
```
250256

251257
注意:首次连接时会创建数据表。在 `data/database.lock.json` 文件存在时不会同步数据表结构。
@@ -273,6 +279,8 @@ DATABASE_PASSWORD=postgres
273279
DATABASE_DATABASE=rss-impact
274280
# Postgre Schema 名称,默认是 "public".
275281
DATABASE_SCHEMA='public'
282+
# 带有 ssl 参数的对象
283+
DATABASE_SSL=false
276284
```
277285

278286
注意:首次连接时会创建数据表。在 `data/database.lock.json` 文件存在时不会同步数据表结构。

src/controllers/article/article.controller.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { User } from '@/db/models/user.entity'
99
import { CurrentUser } from '@/decorators/current-user.decorator'
1010
import { DicData } from '@/models/avue.dto'
1111
import { getConditions } from '@/utils/check'
12+
import { DATABASE_TYPE } from '@/app.config'
1213

1314
@UseSession()
1415
@AclCrud({
@@ -46,12 +47,16 @@ export class ArticleController {
4647
@Get('typeDicData')
4748
async typeDicData(@CurrentUser() user: User) {
4849
const conditions = getConditions(user)
50+
let enclosureType = 'enclosureType'
51+
if (DATABASE_TYPE === 'postgres') {
52+
enclosureType = '"enclosureType"'
53+
}
4954
const data = await this.repository
5055
.createQueryBuilder('article')
5156
.where({
5257
...conditions,
5358
})
54-
.select('enclosureType', 'type')// 选择要 distinct 的列
59+
.select(enclosureType, 'type')// 选择要 distinct 的列
5560
.distinct(true) // 启用 distinct
5661
.getRawMany() as { type: string }[]
5762
return data.filter((e) => e.type).map((e) => ({

src/controllers/feed/feed.controller.ts

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class FeedController {
9797
}
9898
const rss = await rssParserURL(url)
9999
const { title, description, image } = rss || {}
100+
// TODO 修复 postgres 数据库插入新数据时,bigserial 类型的 id 返回的是 string 类型
100101
const feed = await this.repository.save(this.repository.create({
101102
title,
102103
description: description || '',

src/db/database.module.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ const SUPPORTED_DATABASE_TYPES = ['sqlite', 'mysql', 'postgres']
4343
// 是否在每次应用程序启动时自动创建数据库架构。
4444
let synchronize: boolean = false
4545
switch (DATABASE_TYPE) {
46-
case 'sqlite':
46+
case 'sqlite': {
4747
options = { database: DATABASE_PATH } as SqliteConnectionOptions // 数据库路径。
4848
synchronize = true // 在数据库为 sqlite 的时候固定同步
4949
break
50-
case 'mysql':
50+
}
51+
case 'mysql': {
5152
options = {
5253
host: DATABASE_HOST,
5354
port: DATABASE_PORT,
@@ -71,7 +72,8 @@ const SUPPORTED_DATABASE_TYPES = ['sqlite', 'mysql', 'postgres']
7172
synchronize = true
7273
}
7374
break
74-
case 'postgres':
75+
}
76+
case 'postgres': {
7577
options = {
7678
host: DATABASE_HOST,
7779
port: DATABASE_PORT,
@@ -92,6 +94,7 @@ const SUPPORTED_DATABASE_TYPES = ['sqlite', 'mysql', 'postgres']
9294
synchronize = true
9395
}
9496
break
97+
}
9598
default:
9699
break
97100
}

0 commit comments

Comments
 (0)