Skip to content

Loading…

Support date type on mysql adapter #42

Merged
merged 1 commit into from

2 participants

@davebcn

Hi guys,

we're facing the case of having date types columns on our mysql schema.

We don't have a date type on boss_db , I guess because on erlang we deal only with datetimes and now-like structure.

Storing dates and query using them is working if you pad them as datetimes ({Date, {0,0,0}}) so no problem here.

The only problem is when you try to read or update an already present element that includes a date type row. We got something like that

[{boss_db_adapter_mysql,pack_value,
[{date,{2012,7,31}}],
[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},
{line,422}]},

I added support for this case so when we recover a date value from mysql db is gracefully translated to their datetime version.

@evanmiller

Explicitly supporting a "date" type would be best so that it works with type-validation, but I guess this is a reasonable hack for now.

@evanmiller evanmiller merged commit e24727e into ErlyORM:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. support for date types on mysql

    Dave Garcia committed
Showing with 2 additions and 0 deletions.
  1. +2 −0 src/db_adapters/boss_db_adapter_mysql.erl
View
2 src/db_adapters/boss_db_adapter_mysql.erl
@@ -429,6 +429,8 @@ pack_value(V) when is_list(V) ->
"'" ++ escape_sql(V) ++ "'";
pack_value({MegaSec, Sec, MicroSec}) when is_integer(MegaSec) andalso is_integer(Sec) andalso is_integer(MicroSec) ->
pack_now({MegaSec, Sec, MicroSec});
+pack_value({date, Date = {_,_,_}}) ->
+ pack_datetime({Date,{0,0,0}});
pack_value({{_, _, _}, {_, _, _}} = Val) ->
pack_datetime(Val);
pack_value(Val) when is_integer(Val) ->
Something went wrong with that request. Please try again.