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

Actually support query logging #225

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.8.0"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.9.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.4"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.8.0"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.9.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentMySQLDriver/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/mysqlkit/images/vapor-fluentmysqldriver-logo.svg" }
"icons": { "technology": "/fluentmysqldriver/images/vapor-fluentmysqldriver-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
Expand Down
39 changes: 27 additions & 12 deletions Sources/FluentMySQLDriver/FluentMySQLConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AsyncKit
import struct NIO.TimeAmount
import FluentKit
import MySQLKit
import Logging

extension DatabaseConfigurationFactory {
/// Create a database configuration factory for connecting to a server through a UNIX domain socket.
Expand All @@ -24,7 +25,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: Int = 1,
connectionPoolTimeout: NIO.TimeAmount = .seconds(10),
encoder: MySQLDataEncoder = .init(),
decoder: MySQLDataDecoder = .init()
decoder: MySQLDataDecoder = .init(),
sqlLogLevel: Logger.Level? = .debug
) throws -> Self {
let configuration = MySQLConfiguration(
unixDomainSocketPath: unixDomainSocketPath,
Expand All @@ -37,7 +39,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encoder: encoder,
decoder: decoder
decoder: decoder,
sqlLogLevel: sqlLogLevel
)
}

Expand All @@ -56,17 +59,19 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: Int = 1,
connectionPoolTimeout: NIO.TimeAmount = .seconds(10),
encoder: MySQLDataEncoder = .init(),
decoder: MySQLDataDecoder = .init()
decoder: MySQLDataDecoder = .init(),
sqlLogLevel: Logger.Level? = .debug
) throws -> Self {
guard let url = URL(string: urlString) else {
throw FluentMySQLError.invalidURL(urlString)
}
return try self.mysql(
return try .mysql(
url: url,
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encoder: encoder,
decoder: decoder
decoder: decoder,
sqlLogLevel: sqlLogLevel
)
}

Expand All @@ -85,7 +90,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: Int = 1,
connectionPoolTimeout: NIO.TimeAmount = .seconds(10),
encoder: MySQLDataEncoder = .init(),
decoder: MySQLDataDecoder = .init()
decoder: MySQLDataDecoder = .init(),
sqlLogLevel: Logger.Level? = .debug
) throws -> Self {
guard let configuration = MySQLConfiguration(url: url) else {
throw FluentMySQLError.invalidURL(url.absoluteString)
Expand All @@ -95,7 +101,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encoder: encoder,
decoder: decoder
decoder: decoder,
sqlLogLevel: sqlLogLevel
)
}

Expand Down Expand Up @@ -123,7 +130,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: Int = 1,
connectionPoolTimeout: NIO.TimeAmount = .seconds(10),
encoder: MySQLDataEncoder = .init(),
decoder: MySQLDataDecoder = .init()
decoder: MySQLDataDecoder = .init(),
sqlLogLevel: Logger.Level? = .debug
) -> Self {
.mysql(
configuration: .init(
Expand All @@ -137,7 +145,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
connectionPoolTimeout: connectionPoolTimeout,
encoder: encoder,
decoder: decoder
decoder: decoder,
sqlLogLevel: sqlLogLevel
)
}

Expand All @@ -155,7 +164,8 @@ extension DatabaseConfigurationFactory {
maxConnectionsPerEventLoop: Int = 1,
connectionPoolTimeout: NIO.TimeAmount = .seconds(10),
encoder: MySQLDataEncoder = .init(),
decoder: MySQLDataDecoder = .init()
decoder: MySQLDataDecoder = .init(),
sqlLogLevel: Logger.Level? = .debug
) -> Self {
Self {
FluentMySQLConfiguration(
Expand All @@ -164,6 +174,7 @@ extension DatabaseConfigurationFactory {
connectionPoolTimeout: connectionPoolTimeout,
encoder: encoder,
decoder: decoder,
sqlLogLevel: sqlLogLevel,
middleware: []
)
}
Expand All @@ -187,6 +198,9 @@ struct FluentMySQLConfiguration: DatabaseConfiguration {
/// A `MySQLDataDecoder` used to translate `MySQLData` values into output values in `SQLRow`s.
let decoder: MySQLDataDecoder

/// A logging level used for logging queries.
let sqlLogLevel: Logger.Level?

// See `DatabaseConfiguration.middleware`.
var middleware: [any AnyModelMiddleware]

Expand All @@ -201,10 +215,11 @@ struct FluentMySQLConfiguration: DatabaseConfiguration {
requestTimeout: self.connectionPoolTimeout,
on: databases.eventLoopGroup
)
return _FluentMySQLDriver(
return FluentMySQLDriver(
pool: pool,
encoder: self.encoder,
decoder: self.decoder
decoder: self.decoder,
sqlLogLevel: self.sqlLogLevel
)
}
}
Loading
Loading