2015-12-02 75 views

回答

0

the documentation

We can create custom collating sequences by calling createCollation on a database connection.

try db.createCollation("NODIACRITIC") { lhs, rhs in 
    return lhs.compare(rhs, options: .DiacriticInsensitiveSearch) 
} 

We can reference a custom collation using the Custom member of the Collation enumeration.

restaurants.order(collate(.Custom("NODIACRITIC"), name)) 
// SELECT * FROM "restaurants" ORDER BY "name" COLLATE "NODIACRITIC" 

在你的情況,你可以執行事後以下查詢:

SELECT * FROM users WHERE name COLLATE NODIACRITIC LIKE 'thu%' 
+1

我已添加您的代碼和執行查詢但沒有工作。 我必須在建立數據庫連接後立即將此代碼? – TomSawyer

+0

我用你的語法嘗試了其他查詢,但得到了這個錯誤:'使用未解析的標識符collat​​e'' – TomSawyer

+0

你有一個例子,我怎麼能得到它的作品?我在這一天遇到了這個麻煩。 – TomSawyer