@@ -16,8 +16,8 @@ function Get-DALLiteDBCreationScript {
16
16
$indexScript = $indexScripts -join " `n "
17
17
$addScripts = $astClasses | Get-DALLiteDBAddScript
18
18
$addScript = $addScripts -join " `n "
19
- $findScripts = $astClasses | Get-DALLiteDBFindScript
20
- $findScript = $findScripts -join " `n "
19
+ $getScripts = $astClasses | Get-DALLiteDBGetScript
20
+ $getScript = $getScripts -join " `n "
21
21
$testScripts = $astClasses | Get-DALLiteDBTestScript
22
22
$testScript = $testScripts -join " `n "
23
23
$updateScripts = $astClasses | Get-DALLiteDBUpdateScript
@@ -26,14 +26,14 @@ function Get-DALLiteDBCreationScript {
26
26
$upsertScript = $upsertScripts -join " `n "
27
27
$removeScripts = $astClasses | Get-DALLiteDBRemoveScript
28
28
$removeScript = $removeScripts -join " `n "
29
- $referenceScripts = $references | Get-DALLiteDBReferenceFindScript
29
+ $referenceScripts = $references | Get-DALLiteDBReferenceGetScript
30
30
$referenceScript = $referenceScripts -join " `n "
31
31
32
32
Get-DALLiteDBBase
33
33
$collectionScript
34
34
$indexScript
35
35
$addScript
36
- $findScript
36
+ $getScript
37
37
$testScript
38
38
$referenceScript
39
39
$updateScript
@@ -135,7 +135,6 @@ function Get-DALLiteDBNewScript {
135
135
}
136
136
}
137
137
138
- # TODO: Controlar que el id no está vacío
139
138
function Get-DALLiteDBAddScript {
140
139
param (
141
140
[Parameter (ValueFromPipeline = $true , Mandatory = $true )]
@@ -151,14 +150,18 @@ function Add-$className {
151
150
<#[$className ]#>`$ $className
152
151
)
153
152
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
+ }
155
158
}
156
159
}"
157
160
$script
158
161
}
159
162
}
160
163
161
- function Get-DALLiteDBFindScript {
164
+ function Get-DALLiteDBGetScript {
162
165
param (
163
166
[Parameter (ValueFromPipeline = $true , Mandatory = $true )]
164
167
[TypeDefinitionAst ] $classAst
@@ -169,34 +172,32 @@ function Get-DALLiteDBFindScript {
169
172
$parameterName = $className + " Id"
170
173
$parameterPlural = $parameterName | Get-Plural
171
174
$script = "
172
- function Find -$className {
175
+ function Get -$className {
173
176
#[OutputType([$className ])]
174
177
param (
175
178
[Parameter(ValueFromPipeline=`$ true, ParameterSetName = 'Id')]
176
179
[Object] `$ InputObject,
177
- [Parameter(ValueFromPipelineByPropertyName=`$ true, ParameterSetName = 'Id', Mandatory = `$ true )][Alias("" Id"" )]
180
+ [Parameter(ValueFromPipelineByPropertyName=`$ true, ParameterSetName = 'Id')][Alias("" Id"" )]
178
181
[String] `$ $parameterName ,
179
182
[Parameter(ParameterSetName = 'Id')]
180
183
[Switch] `$ Merge,
181
184
[Parameter(ParameterSetName = 'Text', Mandatory = `$ true)]
182
- [Object] `$ Text,
183
- [Parameter(ParameterSetName = 'All')]
184
- [Switch] `$ All
185
+ [Object] `$ Text
185
186
)
186
187
process {
187
- if (`$ All) {
188
- Find-LiteDBDocument -Connection `$ Script:DB -Collection $CollectionName -As PSObject | New-$className
189
- }
190
188
if (`$ Text) {
191
189
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
+ }
198
199
} else {
199
- `$ result
200
+ Find-LiteDBDocument -Connection `$ Script:DB -Collection $CollectionName -As PSObject | New- $className
200
201
}
201
202
}
202
203
}
@@ -296,7 +297,7 @@ function Get-DALLiteDBRemoveScript {
296
297
$script = "
297
298
function Remove-$className {
298
299
param (
299
- [Parameter(Mandatory=`$ true)][Alias("" Id"" )]
300
+ [Parameter(Mandatory=`$ true, ValueFromPipelineByPropertyName= `$ true )][Alias("" Id"" )]
300
301
[String] `$ $parameterName
301
302
)
302
303
Remove-LiteDBDocument -Connection `$ Script:DB -Collection $CollectionName -ID `$ $parameterName
@@ -305,7 +306,7 @@ function Remove-$className {
305
306
}
306
307
}
307
308
308
- function Get-DALLiteDBReferenceFindScript {
309
+ function Get-DALLiteDBReferenceGetScript {
309
310
param (
310
311
[Parameter (ValueFromPipeline = $true , Mandatory = $true )]
311
312
[Object ] $Reference
@@ -316,7 +317,7 @@ function Get-DALLiteDBReferenceFindScript {
316
317
$sourceId = $source + " Id"
317
318
$collection = $target | Get-Plural
318
319
$script = "
319
- function Find -$source$collection {
320
+ function Get -$source$collection {
320
321
#[OutputType([$target ])]
321
322
param (
322
323
[Parameter(ValueFromPipeline=`$ true)]
0 commit comments