我有一个类似于树的方案,其中的项目可以拥有同一个表中的父项,我需要查询父项被删除的项目
select * from items as c where not exists (select p.id from items as p where c.parent_id == p.id)
我试图实现这个目标:
let child = ItemTable.table.alias("child")
let parent = ItemTable.table.alias("parent")
let parentExists = parent.filter(child[ItemTable.parentId] == parent[ItemTable.id]).exists
let r = child.filter(parentExists)
但是最后一行给出了以下编译错误:
Cannot invoke 'filter' with an argument list of type '(Select<Bool>)'
我可以在sql中编写整个代码并运行查询,但我需要使用SQLite Swift提供的ORM来实现这一点。