src/Invoke-Query.psm1

using namespace Dapper
using namespace System.Data
using module ./Mapping/ConvertFrom-Record.psm1

<#
.SYNOPSIS
    Executes a parameterized SQL query and returns a sequence of objects whose properties correspond to the columns.
.PARAMETER Connection
    The connection to the data source.
.PARAMETER Command
    The SQL query to be executed.
.PARAMETER Parameters
    The parameters of the SQL query.
.OUTPUTS
    The sequence of objects whose properties correspond to the returned columns.
#>

function Invoke-Query {
    [CmdletBinding()]
    [OutputType([psobject[]])]
    param (
        [Parameter(Mandatory, Position = 0)]
        [IDbConnection] $Connection,

        [Parameter(Mandatory, Position = 1)]
        [string] $Command,

        [Parameter(Position = 2)]
        [ValidateNotNull()]
        [hashtable] $Parameters = @{}
    )

    $dynamicParameters = [DynamicParameters]::new()
    foreach ($key in $Parameters.Keys) { $dynamicParameters.Add($key, $Parameters.$key) }
    [SqlMapper]::Query($Connection, $Command, $dynamicParameters) | ConvertFrom-Record
}