加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

database – 是否会简化使用自动生成的主键插入表格的过程?

发布时间:2020-12-16 08:48:38 所属栏目:安全 来源:网络整理
导读:在Slick 1.x中,使用自动生成的主键插入表格有点复杂:您必须手动创建一个表格投影,为了插入目的而省略了pk.看起来像Slick 2.x将解决这个问题: Soft inserts are now the default,i.e. AutoInc columns are automatically skipped when inserting with +=,++
在Slick 1.x中,使用自动生成的主键插入表格有点复杂:您必须手动创建一个表格投影,为了插入目的而省略了pk.看起来像Slick 2.x将解决这个问题:

Soft inserts are now the default,i.e. AutoInc columns are automatically skipped when inserting with +=,++=,insert and insertAll. This means that you no longer need separate projections (without the primary key) for inserts.

但是,不得更新2.x文档:

While some database systems allow inserting proper values into AutoInc columns or inserting None to get a created value,most databases forbid this behaviour,so you have to make sure to omit these columns. Slick does not yet have a feature to do this automatically but it is planned for a future release. For now,you have to use a query with a custom projection which does not include the AutoInc column

有没有人知道使用AutoInc插入表中的新2.0语法并获取生成的密钥?

解决方法

insert的语法与1.0中的相同,只是现在autoinc列会被自动忽略.因此.insert的内容会发生语义变化.如果您想要旧行为(包括它们),则必须调用.forceInsert.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读