@@ -441,6 +441,47 @@ extension PostgresConnection {
441441 }
442442 }
443443
444+ /// Run a simple text-only query on the Postgres server the connection is connected to.
445+ /// WARNING: This function is not yet API and is incomplete.
446+ /// The return type will change to another stream.
447+ ///
448+ /// - Parameters:
449+ /// - query: The simple query to run
450+ /// - logger: The `Logger` to log into for the query
451+ /// - file: The file, the query was started in. Used for better error reporting.
452+ /// - line: The line, the query was started in. Used for better error reporting.
453+ /// - Returns: A ``PostgresRowSequence`` containing the rows the server sent as the query result.
454+ /// The sequence be discarded.
455+ @discardableResult
456+ public func __simpleQuery(
457+ _ query: String ,
458+ logger: Logger ,
459+ file: String = #fileID,
460+ line: Int = #line
461+ ) async throws -> PostgresRowSequence {
462+ var logger = logger
463+ logger [ postgresMetadataKey: . connectionID] = " \( self . id) "
464+
465+ let promise = self . channel. eventLoop. makePromise ( of: PSQLRowStream . self)
466+ let context = SimpleQueryContext (
467+ query: query,
468+ logger: logger,
469+ promise: promise
470+ )
471+
472+ self . channel. write ( HandlerTask . simpleQuery ( context) , promise: nil )
473+
474+ do {
475+ return try await promise. futureResult. map ( { $0. asyncSequence ( ) } ) . get ( )
476+ } catch var error as PSQLError {
477+ error. file = file
478+ error. line = line
479+ // FIXME: just pass the string as a simple query, instead of acting like this is a PostgresQuery.
480+ error. query = PostgresQuery ( unsafeSQL: query)
481+ throw error // rethrow with more metadata
482+ }
483+ }
484+
444485 /// Start listening for a channel
445486 public func listen( _ channel: String ) async throws -> PostgresNotificationSequence {
446487 let id = self . internalListenID. loadThenWrappingIncrement ( ordering: . relaxed)
0 commit comments