How to set columns when using helpers in pg-promise

时光总嘲笑我的痴心妄想 提交于 2019-12-06 14:59:05

The following ColumnSet corrects all your problems:

const cs = new pgp.helpers.ColumnSet([
    {name: 'id', prop: 'myid'},
    {name: 'name', prop: 'myname'},
    {name: 'createdate', mod: '^', def: 'CURRENT_TIMESTAMP'}
], {
    table: 'info'
});

See Column for what's available to configure individual columns.

the application of CURRENT_TIMESTAMP is difficult to understand...

{name: 'createdate', mod: '^', def: 'CURRENT_TIMESTAMP'}

It is a column named createdate, with default value CURRENT_TIMESTAMP and formatting modifier ^ (same as :raw), which means raw text (no escaping needed). Other than that, Column type explains it in greater detail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!