Skip to content

Commit

Permalink
refactor: 改为仅支持postgresql, 不再支持其他sql数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
nullaqua committed Sep 11, 2024
1 parent ed34b0b commit 2c90f43
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 68 deletions.
23 changes: 2 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,9 @@ dependencies {
implementation("io.github.smiley4:schema-kenerator-reflection:$schema_kenerator_version")
implementation("com.sun.mail:javax.mail:1.6.2") // 邮件发送

//mysql
val mysql_version: String by project
implementation("mysql:mysql-connector-java:$mysql_version")
//postgresql
val pg_version: String by project
implementation("com.impossibl.pgjdbc-ng:pgjdbc-ng:$pg_version")
implementation("org.postgresql:postgresql:42.7.3")
//h2
val h2_version: String by project
implementation("com.h2database:h2:$h2_version")
//MariaDB
val mariadb_version: String by project
implementation("org.mariadb.jdbc:mariadb-java-client:$mariadb_version")
//Oracle
val oracle_version: String by project
implementation("com.oracle.database.jdbc:ojdbc8:$oracle_version")
//MicrosoftSQLServer
val mssql_version: String by project
implementation("com.microsoft.sqlserver:mssql-jdbc:$mssql_version")
//SQLite
val sqlite_version: String by project
implementation("org.xerial:sqlite-jdbc:$sqlite_version")
val postgresql_version: String by project
implementation("org.postgresql:postgresql:$postgresql_version")

//数据库
implementation("org.jetbrains.exposed:exposed-core:$exposed_version") // 数据库
Expand Down
8 changes: 1 addition & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@ jline_version=3.26.2
swagger_ui_version=3.2.0
schema_kenerator_version=1.1.0
# database
h2_version=2.2.224
mysql_version=8.0.33
pg_version=0.8.9
mariadb_version=3.4.0
oracle_version=23.4.0.24.05
mssql_version=12.6.3.jre11
sqlite_version=3.46.0.0
postgresql_version=42.7.3
14 changes: 6 additions & 8 deletions src/main/kotlin/subit/ForumBackend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private fun parseCommandLineArgs(args: Array<String>): Pair<Array<String>, File>
// 去除命令行中的-config参数, 因为ktor会解析此参数进而不加载打包的application.yaml
// 其余参数还原为字符串数组
val resArgs = argsMap.entries
.filterNot { it.key == "-config" || it.key == "-workDir" || it.key == "-debug" || it.key == "-youthwrite" }
.filterNot { it.key == "-config" || it.key == "-workDir" || it.key == "-debug" }
.map { (k, v) -> "$k=$v" }
.toTypedArray()
// 命令行中输入的自定义配置文件
Expand All @@ -70,9 +70,11 @@ fun main(args: Array<String>)
if (!configFile.exists())
{
configFile.createNewFile()
val defaultConfig =
Loader.getResource("default_config.yaml")?.readAllBytes() ?: error("default_config.yaml not found")
configFile.writeBytes(defaultConfig)
Loader
.getResource("default_config.yaml")
?.readAllBytes()
?.let(configFile::writeBytes)
?: error("default_config.yaml not found")
ForumLogger.getLogger().severe(
"config.yaml not found, the default config has been created, " +
"please modify it and restart the program"
Expand All @@ -93,10 +95,6 @@ fun main(args: Array<String>)

// 生成环境
val environment = commandLineEnvironment(args = resArgs)
{
ForumLogger.getLogger().info("rootPath: ${this.rootPath}")
ForumLogger.getLogger().info("port: ${this.config}")
}
// 启动服务器
embeddedServer(Netty, environment).start(wait = true)
// 若服务器关闭则终止整个程序
Expand Down
8 changes: 1 addition & 7 deletions src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ object SqlDatabaseImpl: IDatabase, KoinComponent
private lateinit var config: ApplicationConfig
private val logger = ForumLogger.getLogger()
private val drivers:List<Driver> = listOf(
org.h2.Driver(),
com.impossibl.postgres.jdbc.PGDriver(),
org.sqlite.JDBC(),
com.mysql.cj.jdbc.Driver(),
oracle.jdbc.OracleDriver(),
com.microsoft.sqlserver.jdbc.SQLServerDriver(),
org.mariadb.jdbc.Driver()
org.postgresql.Driver(),
)

/**
Expand Down
29 changes: 4 additions & 25 deletions src/main/resources/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,20 @@ database:
sql: # 该配置项仅在 impl 为 sql 时必须, 其余情况下无效

# 支持的数据库:
# - H2 (versions 2.x)
# - MariaDB
# - MySQL
# - Oracle
# - Postgres
# - MicrosoftSQLServer
# - SQLite

#数据库用户名
user: 'YourSqlUser'
#数据库密码
password: 'YourSqlPassword'

# 数据库连接地址
url: 'jdbc:mysql://YourSqlHost:YourSqlPort/YourDatabaseName' # mysql
## url: 'jdbc:pgsql://YourSqlHost:YourSqlPort/YourDatabaseName' # postgres
## url: 'jdbc:sqlite:YourDatabaseName' # sqlite
## url: 'jdbc:h2:YourDatabaseName' # h2
## url: 'jdbc:oracle:thin:@YourSqlHost:YourSqlPort:YourDatabaseName' # oracle
## url: 'jdbc:sqlserver://YourSqlHost:YourSqlPort;databaseName=YourDatabaseName' # sqlserver
## url: 'jdbc:mariadb://YourSqlHost:YourSqlPort/YourDatabaseName' # mariadb
url: 'jdbc:postgresql://YourSqlHost:YourSqlPort/YourDatabaseName' # postgres

# 数据库驱动 该项可以不填或填为null以通过url自动识别对应驱动
driver: null
## driver: 'com.mysql.cj.jdbc.Driver' # mysql
## driver: 'com.impossibl.postgres.jdbc.PGDriver' # postgres
## driver: 'org.sqlite.JDBC' # sqlite
## driver: 'org.h2.Driver' # h2
## driver: 'oracle.jdbc.OracleDriver' # oracle
## driver: 'com.microsoft.sqlserver.jdbc.SQLServerDriver' # sqlserver
## driver: 'org.mariadb.jdbc.Driver' # mariadb
# 目前支持的数据库驱动有:
## driver: 'org.postgresql.Driver' # postgres

# 数据库懒惰初始化
lazyInit: true

# jwt登陆验证
#jwt:
# secret: "SUBIT_SECRET" # Your can set your own secret key here, or a random one will be used
lazyInit: true

0 comments on commit 2c90f43

Please sign in to comment.