@@ -2,6 +2,7 @@ import AsyncKit
22import struct NIO. TimeAmount
33import FluentKit
44import MySQLKit
5+ import Logging
56
67extension DatabaseConfigurationFactory {
78 /// Create a database configuration factory for connecting to a server through a UNIX domain socket.
@@ -24,7 +25,8 @@ extension DatabaseConfigurationFactory {
2425 maxConnectionsPerEventLoop: Int = 1 ,
2526 connectionPoolTimeout: NIO . TimeAmount = . seconds( 10 ) ,
2627 encoder: MySQLDataEncoder = . init( ) ,
27- decoder: MySQLDataDecoder = . init( )
28+ decoder: MySQLDataDecoder = . init( ) ,
29+ sqlLogLevel: Logger . Level ? = . debug
2830 ) throws -> Self {
2931 let configuration = MySQLConfiguration (
3032 unixDomainSocketPath: unixDomainSocketPath,
@@ -37,7 +39,8 @@ extension DatabaseConfigurationFactory {
3739 maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
3840 connectionPoolTimeout: connectionPoolTimeout,
3941 encoder: encoder,
40- decoder: decoder
42+ decoder: decoder,
43+ sqlLogLevel: sqlLogLevel
4144 )
4245 }
4346
@@ -56,17 +59,19 @@ extension DatabaseConfigurationFactory {
5659 maxConnectionsPerEventLoop: Int = 1 ,
5760 connectionPoolTimeout: NIO . TimeAmount = . seconds( 10 ) ,
5861 encoder: MySQLDataEncoder = . init( ) ,
59- decoder: MySQLDataDecoder = . init( )
62+ decoder: MySQLDataDecoder = . init( ) ,
63+ sqlLogLevel: Logger . Level ? = . debug
6064 ) throws -> Self {
6165 guard let url = URL ( string: urlString) else {
6266 throw FluentMySQLError . invalidURL ( urlString)
6367 }
64- return try self . mysql (
68+ return try . mysql(
6569 url: url,
6670 maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
6771 connectionPoolTimeout: connectionPoolTimeout,
6872 encoder: encoder,
69- decoder: decoder
73+ decoder: decoder,
74+ sqlLogLevel: sqlLogLevel
7075 )
7176 }
7277
@@ -85,7 +90,8 @@ extension DatabaseConfigurationFactory {
8590 maxConnectionsPerEventLoop: Int = 1 ,
8691 connectionPoolTimeout: NIO . TimeAmount = . seconds( 10 ) ,
8792 encoder: MySQLDataEncoder = . init( ) ,
88- decoder: MySQLDataDecoder = . init( )
93+ decoder: MySQLDataDecoder = . init( ) ,
94+ sqlLogLevel: Logger . Level ? = . debug
8995 ) throws -> Self {
9096 guard let configuration = MySQLConfiguration ( url: url) else {
9197 throw FluentMySQLError . invalidURL ( url. absoluteString)
@@ -95,7 +101,8 @@ extension DatabaseConfigurationFactory {
95101 maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
96102 connectionPoolTimeout: connectionPoolTimeout,
97103 encoder: encoder,
98- decoder: decoder
104+ decoder: decoder,
105+ sqlLogLevel: sqlLogLevel
99106 )
100107 }
101108
@@ -123,7 +130,8 @@ extension DatabaseConfigurationFactory {
123130 maxConnectionsPerEventLoop: Int = 1 ,
124131 connectionPoolTimeout: NIO . TimeAmount = . seconds( 10 ) ,
125132 encoder: MySQLDataEncoder = . init( ) ,
126- decoder: MySQLDataDecoder = . init( )
133+ decoder: MySQLDataDecoder = . init( ) ,
134+ sqlLogLevel: Logger . Level ? = . debug
127135 ) -> Self {
128136 . mysql(
129137 configuration: . init(
@@ -137,7 +145,8 @@ extension DatabaseConfigurationFactory {
137145 maxConnectionsPerEventLoop: maxConnectionsPerEventLoop,
138146 connectionPoolTimeout: connectionPoolTimeout,
139147 encoder: encoder,
140- decoder: decoder
148+ decoder: decoder,
149+ sqlLogLevel: sqlLogLevel
141150 )
142151 }
143152
@@ -155,7 +164,8 @@ extension DatabaseConfigurationFactory {
155164 maxConnectionsPerEventLoop: Int = 1 ,
156165 connectionPoolTimeout: NIO . TimeAmount = . seconds( 10 ) ,
157166 encoder: MySQLDataEncoder = . init( ) ,
158- decoder: MySQLDataDecoder = . init( )
167+ decoder: MySQLDataDecoder = . init( ) ,
168+ sqlLogLevel: Logger . Level ? = . debug
159169 ) -> Self {
160170 Self {
161171 FluentMySQLConfiguration (
@@ -164,6 +174,7 @@ extension DatabaseConfigurationFactory {
164174 connectionPoolTimeout: connectionPoolTimeout,
165175 encoder: encoder,
166176 decoder: decoder,
177+ sqlLogLevel: sqlLogLevel,
167178 middleware: [ ]
168179 )
169180 }
@@ -187,6 +198,9 @@ struct FluentMySQLConfiguration: DatabaseConfiguration {
187198 /// A `MySQLDataDecoder` used to translate `MySQLData` values into output values in `SQLRow`s.
188199 let decoder : MySQLDataDecoder
189200
201+ /// A logging level used for logging queries.
202+ let sqlLogLevel : Logger . Level ?
203+
190204 // See `DatabaseConfiguration.middleware`.
191205 var middleware : [ any AnyModelMiddleware ]
192206
@@ -201,10 +215,11 @@ struct FluentMySQLConfiguration: DatabaseConfiguration {
201215 requestTimeout: self . connectionPoolTimeout,
202216 on: databases. eventLoopGroup
203217 )
204- return _FluentMySQLDriver (
218+ return FluentMySQLDriver (
205219 pool: pool,
206220 encoder: self . encoder,
207- decoder: self . decoder
221+ decoder: self . decoder,
222+ sqlLogLevel: self . sqlLogLevel
208223 )
209224 }
210225}
0 commit comments