Peewee 3 - Python - 排名查询结果

Peewee 3 - Python - Rank query results

我有一个 self-referencing 数据库 table,其中包含注释(id、标题、parent)。
[注:table的self-referencing属性与问题无关]
我想按标题的字母顺序对它们进行排序,并通过 id 找到特定注释的排名(=顺序)。我正在使用 Peewee 3 作为 ORM。

数据库模型:

class Note(Model):
    title = CharField()
    parent = ForeignKeyField('self', backref='children', null = True)

代码:

noteAlias = Note.alias()
subquery = (noteAlias.select(noteAlias.id, fn.RANK().over(partition_by=[noteAlias.title], order_by=[noteAlias.title]).alias('rank')).where(noteAlias.parent.is_null()).alias('subq'))
query = (Note.select(subquery.c.id, subquery.c.rank).from_(subquery).where(subquery.c.id == 5))
print("Rank of element is: " + str(query.rank))

此代码出现以下错误:

cursor.execute(sql, params or ())
sqlite3.OperationalError: near "(": syntax error

SQLite 测试
如果我直接 运行 这个 sqlite 代码直接针对我的数据库:

SELECT (title, ROW_NUMBER() OVER (ORDER BY title) AS placement) FROM note

我收到错误:near ",": syntax error:

您的 SQLite 版本可能不支持 window 函数,因为我相信这是最近在 3.25 中添加的。