-
-
Notifications
You must be signed in to change notification settings - Fork 154
support: Sqlite returning clause on Insert
& insertOrUpdate
#427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support: Sqlite returning clause on Insert
& insertOrUpdate
#427
Conversation
mysql test 报错? |
Insert
& insertOrUpdate
这个功能之前就能做了,但是用 executeUpdate 的方法一直提示不能有返回值。大概意思就是有了 returning 之后,不管是 delete还是 insert 还是 update 语法,统统都变成了查询语句,都得用 query 方法 |
现在只有新增操作写了 returning,修改和删除要不要也支持一下 |
谢谢,我先找时间看看你的代码 |
我想了一下,这个 returning 的操作感觉可以做成直接返回全部列。 那么新增操作可以使用 returning 返回自增主键,删除操作返回被删除的行然后映射成对象。 |
* returning id | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since 3.6.0
* returning id, job | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* returning id, job, salary | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
table = table.asExpression(), | ||
assignments = builder.assignments, | ||
returningColumns = returning.map { it.asExpression() } | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style:
val expression = AliasRemover.visit(
BulkInsertExpression(
table = table.asExpression(),
assignments = builder.assignments,
returningColumns = returning.map { it.asExpression() }
)
)
* returning id | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since 3.6.0
* returning id, job | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* returning id, job, salary | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* returning id | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* returning id, job | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
* returning id, job, salary | ||
* ``` | ||
* | ||
* @since 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
代码合并了,整体没有什么问题
这个是 OK 的,不同数据库驱动的实现方式不一样,我们的写法不同也是正常的
AliasRemover 确实存在一些问题,不止 SQLite,其他方言模块也是一样,这个我会在 3.6.0 版本统一优化
returning 的主要用途是插入后返回数据库自动生成的值,比如主键,修改和删除对这个的需求很低,暂时不需要支持
理由同上,returning 的主要用途是返回主键,既然是 insert 操作,其他字段的值用户已经有了,返回还有什么意义呢 |
主要针对 50459d9
对于 executeUpdateAndRetrieveKeys 改为调用 executeQuery 可能需要讨论
对于 buildBulkInsertOrUpdateExpression 方法 给返回值加上 AliasRemover 可能需要讨论