diff --git a/build.gradle.kts b/build.gradle.kts index 8909ff8..213b7e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") // 数据库 diff --git a/gradle.properties b/gradle.properties index d21b1bc..f8bca66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file +postgresql_version=42.7.3 \ No newline at end of file diff --git a/src/main/kotlin/subit/ForumBackend.kt b/src/main/kotlin/subit/ForumBackend.kt index 8b9c39a..1c5783c 100644 --- a/src/main/kotlin/subit/ForumBackend.kt +++ b/src/main/kotlin/subit/ForumBackend.kt @@ -47,7 +47,7 @@ private fun parseCommandLineArgs(args: Array): Pair, 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() // 命令行中输入的自定义配置文件 @@ -70,9 +70,11 @@ fun main(args: Array) 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" @@ -93,10 +95,6 @@ fun main(args: Array) // 生成环境 val environment = commandLineEnvironment(args = resArgs) - { - ForumLogger.getLogger().info("rootPath: ${this.rootPath}") - ForumLogger.getLogger().info("port: ${this.config}") - } // 启动服务器 embeddedServer(Netty, environment).start(wait = true) // 若服务器关闭则终止整个程序 diff --git a/src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt b/src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt index 5d757ba..56d0864 100644 --- a/src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt +++ b/src/main/kotlin/subit/database/sqlImpl/SqlDatabaseImpl.kt @@ -56,13 +56,7 @@ object SqlDatabaseImpl: IDatabase, KoinComponent private lateinit var config: ApplicationConfig private val logger = ForumLogger.getLogger() private val drivers:List = 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(), ) /** diff --git a/src/main/resources/default_config.yaml b/src/main/resources/default_config.yaml index e99838c..1b8ce3f 100644 --- a/src/main/resources/default_config.yaml +++ b/src/main/resources/default_config.yaml @@ -8,13 +8,7 @@ database: sql: # 该配置项仅在 impl 为 sql 时必须, 其余情况下无效 # 支持的数据库: - # - H2 (versions 2.x) - # - MariaDB - # - MySQL - # - Oracle # - Postgres - # - MicrosoftSQLServer - # - SQLite #数据库用户名 user: 'YourSqlUser' @@ -22,27 +16,12 @@ database: 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 \ No newline at end of file + lazyInit: true \ No newline at end of file