@@ -48,6 +48,9 @@ defmodule Ecto.Adapters.SQLite3 do
4848 `:binary_id` columns. See the [section on binary ID types](#module-binary-id-types) for more details.
4949 * `:uuid_type` - Defaults to `:string`. Determines the type of `:uuid` columns. Possible values and
5050 column types are the same as for [binary IDs](#module-binary-id-types).
51+ * `:datetime_type` - Defaults to `:iso8601`. Determines how datetime fields are stored in the database.
52+ The allowed values are `:iso8601` and `:text_datetime`. `:iso8601` corresponds to a string of the form
53+ `YYYY-MM-DDThh:mm:ss` and `:text_datetime` corresponds to a string of the form YYYY-MM-DD hh:mm:ss`
5154
5255 For more information about the options above, see [sqlite documentation][1]
5356
@@ -259,6 +262,8 @@ defmodule Ecto.Adapters.SQLite3 do
259262 ## Loaders
260263 ##
261264
265+ @ default_datetime_type :iso8601
266+
262267 @ impl Ecto.Adapter
263268 def loaders ( :boolean , type ) do
264269 [ & Codec . bool_decode / 1 , type ]
@@ -390,22 +395,26 @@ defmodule Ecto.Adapters.SQLite3 do
390395
391396 @ impl Ecto.Adapter
392397 def dumpers ( :utc_datetime , type ) do
393- [ type , & Codec . utc_datetime_encode / 1 ]
398+ dt_type = Application . get_env ( :ecto_sqlite3 , :datetime_type , @ default_datetime_type )
399+ [ type , & Codec . utc_datetime_encode ( & 1 , dt_type ) ]
394400 end
395401
396402 @ impl Ecto.Adapter
397403 def dumpers ( :utc_datetime_usec , type ) do
398- [ type , & Codec . utc_datetime_encode / 1 ]
404+ dt_type = Application . get_env ( :ecto_sqlite3 , :datetime_type , @ default_datetime_type )
405+ [ type , & Codec . utc_datetime_encode ( & 1 , dt_type ) ]
399406 end
400407
401408 @ impl Ecto.Adapter
402409 def dumpers ( :naive_datetime , type ) do
403- [ type , & Codec . naive_datetime_encode / 1 ]
410+ dt_type = Application . get_env ( :ecto_sqlite3 , :datetime_type , @ default_datetime_type )
411+ [ type , & Codec . naive_datetime_encode ( & 1 , dt_type ) ]
404412 end
405413
406414 @ impl Ecto.Adapter
407415 def dumpers ( :naive_datetime_usec , type ) do
408- [ type , & Codec . naive_datetime_encode / 1 ]
416+ dt_type = Application . get_env ( :ecto_sqlite3 , :datetime_type , @ default_datetime_type )
417+ [ type , & Codec . naive_datetime_encode ( & 1 , dt_type ) ]
409418 end
410419
411420 @ impl Ecto.Adapter
0 commit comments