0
我在peewee文档how to create custom collations中找到,但我无法找到如何使用the built-in sqlite collating sequences。在peewee查询中使用COLLATE
何我在peewee中创建以下查询(它是上面提到的sqlite文档页面中的最后一个)?
SELECT x FROM t1 ORDER BY c COLLATE NOCASE, x;
我该如何指定一个索引的排序规则?
CREATE INDEX i1 ON t1(f1 COLLATE NOCASE);
编辑
从coleifer答案解决有关查询的问题。
对于索引创建,我使用了以下技巧,在启动时只创建索引一次(如在我的应用程序中)时,这很有效。
表LockedFiles
上两列上的不区分大小写唯一索引可防止重复条目。
class LockedFiles(PeeweeModel):
folder = peewee.CharField(index=True)
file = peewee.CharField(index=True)
@classmethod
def custom_init(cls):
db.execute_sql('create unique index if not exists lockedfiles_unique '
'on lockedfiles(folder collate nocase, file collate nocase)', {})
def create_tables(drop_existing_tables):
for table in [LockedFiles, Model2, Model3]:
if drop_existing_tables:
table.drop_table(True)
table.create_table(True)
try:
table.custom_init()
except:
pass
create_tables(drop_existing_tables=False)
我仍然停留在查询部分。我已经找到索引部分的解决方法。我编辑了这篇文章的细节。 – stenci 2014-11-21 21:53:41