Skip to content

Commit 7705348

Browse files
Change verb Find to Get
1 parent 40e6f4b commit 7705348

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

DALLiteDBTools.ps1

+26-25
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function Get-DALLiteDBCreationScript {
1616
$indexScript = $indexScripts -join "`n"
1717
$addScripts = $astClasses | Get-DALLiteDBAddScript
1818
$addScript = $addScripts -join "`n"
19-
$findScripts = $astClasses | Get-DALLiteDBFindScript
20-
$findScript = $findScripts -join "`n"
19+
$getScripts = $astClasses | Get-DALLiteDBGetScript
20+
$getScript = $getScripts -join "`n"
2121
$testScripts = $astClasses | Get-DALLiteDBTestScript
2222
$testScript = $testScripts -join "`n"
2323
$updateScripts = $astClasses | Get-DALLiteDBUpdateScript
@@ -26,14 +26,14 @@ function Get-DALLiteDBCreationScript {
2626
$upsertScript = $upsertScripts -join "`n"
2727
$removeScripts = $astClasses | Get-DALLiteDBRemoveScript
2828
$removeScript = $removeScripts -join "`n"
29-
$referenceScripts = $references | Get-DALLiteDBReferenceFindScript
29+
$referenceScripts = $references | Get-DALLiteDBReferenceGetScript
3030
$referenceScript = $referenceScripts -join "`n"
3131

3232
Get-DALLiteDBBase
3333
$collectionScript
3434
$indexScript
3535
$addScript
36-
$findScript
36+
$getScript
3737
$testScript
3838
$referenceScript
3939
$updateScript
@@ -135,7 +135,6 @@ function Get-DALLiteDBNewScript {
135135
}
136136
}
137137

138-
# TODO: Controlar que el id no está vacío
139138
function Get-DALLiteDBAddScript {
140139
param (
141140
[Parameter(ValueFromPipeline=$true, Mandatory=$true)]
@@ -151,14 +150,18 @@ function Add-$className {
151150
<#[$className]#>`$$className
152151
)
153152
process {
154-
`$$className | ConvertTo-LiteDbBSON | Add-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -Id `$$($className).Id
153+
if (`$$className.Id -ne $null) {
154+
`$$className | ConvertTo-LiteDbBSON | Add-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -Id `$$($className).Id
155+
} else {
156+
Write-Error ""Empty Id"" -TargetObject `$$className
157+
}
155158
}
156159
}"
157160
$script
158161
}
159162
}
160163

161-
function Get-DALLiteDBFindScript {
164+
function Get-DALLiteDBGetScript {
162165
param (
163166
[Parameter(ValueFromPipeline=$true, Mandatory=$true)]
164167
[TypeDefinitionAst] $classAst
@@ -169,34 +172,32 @@ function Get-DALLiteDBFindScript {
169172
$parameterName = $className + "Id"
170173
$parameterPlural = $parameterName | Get-Plural
171174
$script = "
172-
function Find-$className {
175+
function Get-$className {
173176
#[OutputType([$className])]
174177
param (
175178
[Parameter(ValueFromPipeline=`$true, ParameterSetName = 'Id')]
176179
[Object] `$InputObject,
177-
[Parameter(ValueFromPipelineByPropertyName=`$true, ParameterSetName = 'Id', Mandatory = `$true)][Alias(""Id"")]
180+
[Parameter(ValueFromPipelineByPropertyName=`$true, ParameterSetName = 'Id')][Alias(""Id"")]
178181
[String] `$$parameterName,
179182
[Parameter(ParameterSetName = 'Id')]
180183
[Switch] `$Merge,
181184
[Parameter(ParameterSetName = 'Text', Mandatory = `$true)]
182-
[Object] `$Text,
183-
[Parameter(ParameterSetName = 'All')]
184-
[Switch] `$All
185+
[Object] `$Text
185186
)
186187
process {
187-
if (`$All) {
188-
Find-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -As PSObject | New-$className
189-
}
190188
if (`$Text) {
191189
Find-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -As PSObject | New-$className | Where-Object { `$_.GetFullText().Contains(`$Text) }
192-
}
193-
if (`$$parameterName) {
194-
`$result = Find-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -ID `$$parameterName -As PSObject | New-$className
195-
if (`$Merge -and `$InputObject -ne `$null) {
196-
Add-Member -InputObject `$InputObject -MemberType NoteProperty -Name $className -Value `$result
197-
`$InputObject
190+
} else {
191+
if (`$$parameterName) {
192+
`$result = Find-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -ID `$$parameterName -As PSObject | New-$className
193+
if (`$Merge -and `$InputObject -ne `$null) {
194+
Add-Member -InputObject `$InputObject -MemberType NoteProperty -Name $className -Value `$result
195+
`$InputObject
196+
} else {
197+
`$result
198+
}
198199
} else {
199-
`$result
200+
Find-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -As PSObject | New-$className
200201
}
201202
}
202203
}
@@ -296,7 +297,7 @@ function Get-DALLiteDBRemoveScript {
296297
$script = "
297298
function Remove-$className {
298299
param (
299-
[Parameter(Mandatory=`$true)][Alias(""Id"")]
300+
[Parameter(Mandatory=`$true, ValueFromPipelineByPropertyName=`$true)][Alias(""Id"")]
300301
[String] `$$parameterName
301302
)
302303
Remove-LiteDBDocument -Connection `$Script:DB -Collection $CollectionName -ID `$$parameterName
@@ -305,7 +306,7 @@ function Remove-$className {
305306
}
306307
}
307308

308-
function Get-DALLiteDBReferenceFindScript {
309+
function Get-DALLiteDBReferenceGetScript {
309310
param (
310311
[Parameter(ValueFromPipeline=$true, Mandatory=$true)]
311312
[Object] $Reference
@@ -316,7 +317,7 @@ function Get-DALLiteDBReferenceFindScript {
316317
$sourceId = $source + "Id"
317318
$collection = $target | Get-Plural
318319
$script = "
319-
function Find-$source$collection {
320+
function Get-$source$collection {
320321
#[OutputType([$target])]
321322
param (
322323
[Parameter(ValueFromPipeline=`$true)]

0 commit comments

Comments
 (0)