如何解决pg-promise helpers insert在插入时跳过的替代方法是什么?
我正在使用pg-promise通过helpers.insert和helpers.update构建插入和更新。
更新可以按预期进行,但是我一直遇到与此问题类似的问题:pg-promise helpers : optionnal fields in insert and multiple-update
即当输入数据中不存在该属性时,带有postgresql缺省值的可选列会导致helpers.insert引发错误。在更新时,这会触发跳过功能,这很好,但是如文档所示,跳过不适用于插入,因此会出错。
const input = { yup: true };
const query = this.pgp.helpers.insert(
input,new this.pgp.helpers.ColumnSet(
[
{ name: 'yup',skip: (col) => !col.exists },{ name: 'nope',
我想知道为什么在插入时跳过不起作用?还有我找不到的替代方法吗?
使用def似乎有点麻烦,因为我想使用postgresql的默认值而不是覆盖它们。
我到处搜寻网络,甚至发现@ vitaly-t在2016年使用跳过功能回答了相同的问题,该功能随后已从helpers.insert中删除。
所以我被困住了。如何获得与插入相同的跳过功能?
解决方法
这就是我想出的方法,以防有人发现自己处于同一位置:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
#GUI
$gamefrm = New-Object system.Windows.Forms.Form
$gamefrm.ClientSize = New-Object System.Drawing.Point(573,376)
$gamefrm.text = "Deviner le nombre"
$gamefrm.TopMost = $true
$gamefrm.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#bd10e0")
$ruletxt = New-Object system.Windows.Forms.TextBox
$ruletxt.multiline = $false
$ruletxt.width = 262
$ruletxt.height = 20
$ruletxt.location = New-Object System.Drawing.Point(150,39)
$ruletxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$ruletxt.Text = "Deviner le nombre!"
$ruletxt.AutoSize = $true
$ruletxt.ReadOnly = $true
$intxt = New-Object system.Windows.Forms.TextBox
$intxt.multiline = $false
$intxt.width = 263
$intxt.height = 20
$intxt.location = New-Object System.Drawing.Point(149,110)
$intxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$intxt.Text = "1"
$intxt.AutoSize = $true
$intxt.ReadOnly = $true
$outtxt = New-Object system.Windows.Forms.TextBox
$outtxt.multiline = $false
$outtxt.width = 263
$outtxt.height = 20
$outtxt.location = New-Object System.Drawing.Point(149,190)
$outtxt.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
$outtxt.text = ""
$outtxt.AutoSize = $true
$gamefrm.controls.AddRange(@($ruletxt,$intxt,$outtxt,$imagepb,$Button1,))
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "button"
$Button1.width = 60
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(86,89)
$Button1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
#Write your logic code here
[void]$gamefrm.ShowDialog()
[int]$nombre = Get-Random -Minimum 1 -Maximum 101
$essai = 0
$output = $intxt.Text
$input = $outtxt.Text
while ($input -ne $nombre){
if ($input -gt $nombre) {$output = " trop haut "}
if ($input -lt $nombre) {$intxt.Text = " trop bas "}
if ( ( $input -gt 100 ) -or ($input -lt 0 ) ) {$intxt.Text = " entre 1 et 100! "}
$essai++
} $intxt.Text = "Correct! Nombre d'essai: $essai"
export function column(name: string,prop?: string): IColumnConfig {
return {
name: name,prop: prop,skip: (col) => !col.exists,};
}
我不能说这是最优雅的方法。 但这对我想要达到的目标有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。