Skip to content

Commit 928bce2

Browse files
committed
search: clarify helper contracts
1 parent feb080a commit 928bce2

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

lib/database.ps1

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if (-not (Get-Command Compare-Version -ErrorAction Ignore)) {
1414
function Get-LatestScoopDBRow {
1515
param(
1616
[Parameter(Mandatory)]
17+
[AllowEmptyCollection()]
1718
[object[]]
1819
$Rows
1920
)
@@ -23,7 +24,8 @@ function Get-LatestScoopDBRow {
2324
}
2425

2526
$latest = $Rows[0]
26-
foreach ($row in ($Rows | Select-Object -Skip 1)) {
27+
for ($i = 1; $i -lt $Rows.Count; $i++) {
28+
$row = $Rows[$i]
2729
if ((Compare-Version -ReferenceVersion $latest.version -DifferenceVersion $row.version) -gt 0) {
2830
$latest = $row
2931
}
@@ -32,6 +34,21 @@ function Get-LatestScoopDBRow {
3234
return $latest
3335
}
3436

37+
<#
38+
.SYNOPSIS
39+
Return the semantically latest row or rows from a Scoop database result set.
40+
.DESCRIPTION
41+
Clones the schema of `Table` and imports the latest row per group when
42+
`GroupBy` is supplied, or the single latest row across the whole table when
43+
it is omitted. Returns an empty cloned table when the source table has no rows.
44+
.PARAMETER Table
45+
The source `System.Data.DataTable` returned from a Scoop database query.
46+
.PARAMETER GroupBy
47+
Optional column names used to group rows before semantic latest-row selection.
48+
.OUTPUTS
49+
System.Data.DataTable
50+
A cloned table containing the latest matching row for each requested scope.
51+
#>
3552
function Select-LatestScoopDBRow {
3653
param(
3754
[Parameter(Mandatory)]
@@ -383,6 +400,8 @@ function Get-ScoopDBItem {
383400
end {
384401
$dbAdapter.Dispose()
385402
$db.Dispose()
403+
# With $Version, the PRIMARY KEY guarantees at most one row; without it, the
404+
# query is already limited to one name+bucket pair, so selecting latest needs no -GroupBy.
386405
if ($Version) {
387406
return $result
388407
}

0 commit comments

Comments
 (0)