使用SORM通过普通SQL查询获取对象 [英] Fetch object by plain SQL query with SORM

查看:85
本文介绍了使用SORM通过普通SQL查询获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过普通SQL查询而不是使用 SORM 通过DSL构建查询来获取项目?

Is it possible to fetch items by plain SQL query instead of building query by DSL using SORM?

例如,是否存在用于制作类似内容的API

For example is there an API for making something like

val metallica = Db.query[Artist].fromString("SELECT * FROM artist WHERE name = ?", "Metallica").fetchOne() // Option[Artist]

代替

val metallica = Db.query[Artist].whereEqual("name", "Metallica").fetchOne() // Option[Artist]

推荐答案

由于使用集合和其他结构化值填充实体涉及以不可连接的方式从多个表中获取数据,因此直接获取该API的API很可能永远不会公开.但是,目前正在考虑解决该问题的另一种方法.

Since populating an entity with collections and other structured values involves fetching data from multiple tables in an unjoinable way, the API for fetching it directly will most probably never get exposed. However another approach to this problem is currently being considered.

以下是它的实现方式:

val artists : Seq[Artist] 
  = Db.fetchWithSql[Artist]("SELECT id FROM artist WHERE name = ?", "Metallica")

如果此问题在此处获得显着支持,或者甚至在此处得到了更好的支持,则可能会实施在下一个次要版本中.

If this issue gets a notable support either here or, even better, here, it will probably get implemented in the next minor release.

更新

在0.3.1中实现

这篇关于使用SORM通过普通SQL查询获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆