File tree Expand file tree Collapse file tree 5 files changed +30
-0
lines changed
lib/ecto/adapters/sqlite3 Expand file tree Collapse file tree 5 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,18 @@ defmodule Ecto.Adapters.SQLite3.DataType do
1414 def column_type ( :bigint , _opts ) , do: "INTEGER"
1515 # TODO: We should make this configurable
1616 def column_type ( :binary_id , _opts ) , do: "TEXT"
17+
18+ def column_type ( :string , opts ) when is_list ( opts ) do
19+ collate = Keyword . get ( opts , :collate )
20+
21+ if collate do
22+ str = collate |> Atom . to_string ( ) |> String . upcase ( )
23+ "TEXT COLLATE #{ str } "
24+ else
25+ "TEXT"
26+ end
27+ end
28+
1729 def column_type ( :string , _opts ) , do: "TEXT"
1830 def column_type ( :float , _opts ) , do: "NUMERIC"
1931 def column_type ( :binary , _opts ) , do: "BLOB"
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ defmodule Ecto.Adapters.SQLite3.DataTypeTest do
2424 assert DataType . column_type ( :string , nil ) == "TEXT"
2525 end
2626
27+ test ":string, collate: :nocase is TEXT COLLATE NOCASE" do
28+ assert DataType . column_type ( :string , collate: :nocase ) == "TEXT COLLATE NOCASE"
29+ end
30+
2731 test ":uuid is TEXT" do
2832 assert DataType . column_type ( :uuid , nil ) == "TEXT"
2933 end
Original file line number Diff line number Diff line change @@ -191,5 +191,17 @@ defmodule Ecto.Integration.CrudTest do
191191 assert [ ] = TestRepo . all from a in Account , where: a . name in [ "404" ]
192192 assert [ _ ] = TestRepo . all from a in Account , where: a . name in [ "hi" ]
193193 end
194+
195+ test "handles case sensitive text" do
196+ TestRepo . insert! ( % Account { name: "hi" } )
197+ assert [ _ ] = TestRepo . all from a in Account , where: a . name == "hi"
198+ assert [ ] = TestRepo . all from a in Account , where: a . name == "HI"
199+ end
200+
201+ test "handles case insensitive text" do
202+ TestRepo . insert! ( % Account { name: "hi" , email: "hi@hi.com" } )
203+ assert [ _ ] = TestRepo . all from a in Account , where: a . email == "hi@hi.com"
204+ assert [ _ ] = TestRepo . all from a in Account , where: a . email == "HI@HI.COM"
205+ end
194206 end
195207end
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ defmodule EctoSQLite3.Integration.Migration do
44 def change do
55 create table ( :accounts ) do
66 add ( :name , :string )
7+ add ( :email , :string , collate: :nocase )
78 timestamps ( )
89 end
910
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ defmodule EctoSQLite3.Integration.Account do
88
99 schema "accounts" do
1010 field ( :name , :string )
11+ field ( :email , :string )
1112
1213 timestamps ( )
1314
You can’t perform that action at this time.
0 commit comments