lau / calecto Goto Github PK
View Code? Open in Web Editor NEWAdapter for the Calendar library in Ecto
License: MIT License
Adapter for the Calendar library in Ecto
License: MIT License
Ecto has integration tests (see https://github.com/elixir-lang/ecto#running-tests ). It would be cool if we had something like that, so when running e.g. MIX_ENV=pg mix test
, a database would be created and we would test the schema, queries etc. That way the integration with both Ecto and the database would be tested.
Hi, I got the following problem when I try to build a release with calecto:
When you include both Ecto and Calecto in your applications list and try to build a release (in my case with distillery) then you get a "Duplicated modules" error because your types have the same names as Ecto's types:
Duplicated modules:
'Elixir.Ecto.DataType.Time' specified in ecto and calecto
'Elixir.Ecto.DataType.NaiveDateTime' specified in ecto and calecto
'Elixir.Ecto.DataType.DateTime' specified in ecto and calecto
'Elixir.Ecto.DataType.Date' specified in ecto and calecto
How do you deal with this?
I'm using
{:phoenix_ecto, "~> 2.0"}
Maybe you can bump up the deps
Calecto fails to convert Calendar.DateTime to Calecto.DateTimeUTC on casting
to reproduce:
Calendar.DateTime.now_utc |> Calecto.DateTimeUTC.cast
Now that Ecto.Model
is no longer used, while Calecto.Model
still works, it should probably be renamed.
Calecto.Schema
?
Hey @lau, I'm trying to use the Calecto.DateTime type and getting the following error when writing a value:
** (ArgumentError) could not encode date/time: {{{2018, 8, 9}, {12, 56, 42, 0}}, -14400, "EST5EDT"}
This error happens when you are by-passing Ecto's Query API by
using either Ecto.Adapters.SQL.query/4 or Ecto fragments. This
makes Ecto unable to properly cast the type. You can fix this by
explicitly telling Ecto which type to use via `type/2` or by
implementing the Ecto.DataType protocol for the given value.
(ecto) lib/ecto/adapters/postgres/datetime.ex:88: Ecto.Adapters.Postgres.Timestamp.encode!/1
(sensetra) lib/ecto/adapters/postgres/datetime.ex:126: Sensetra.PostgresTypes.encode_params/3
(postgrex) lib/postgrex/query.ex:45: DBConnection.Query.Postgrex.Query.encode/3
(db_connection) lib/db_connection.ex:1079: DBConnection.describe_run/5
(db_connection) lib/db_connection.ex:1150: anonymous fn/4 in DBConnection.run_meter/5
(db_connection) lib/db_connection.ex:592: DBConnection.prepare_execute/4
(ecto) lib/ecto/adapters/postgres/connection.ex:86: Ecto.Adapters.Postgres.Connection.execute/4
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
A similar error happens if I try to load a value
Versions:
Elixir 1.7.2
Ecto 2.2.10
Calecto 0.17.0
Hi,
First off, thanks very much for your work on these datetime packages. Super, super useful.
I'm still relatively new to Elixir but I am confused by the instructions in the README:
In your Ecto models, where you have a schema definition with a timestamps line, add
use Kalecto.Model
at the top of the module, below the line that saysuse Ecto.Model
When using both use
lines in an Ecto model definition, compilation seems to raise this warning:
model.ex:1: warning: this clause cannot match because a previous clause at line 1 always matches
...and looking at the macro code itself, it seems to declare use Ecto.Model
for you.
So I guess the question is, am I missing a reason for asking users to specify both lines?
cheers,
Darian
There an issue with Calecto and Ecto 2.0.0-rc4 (elixir-ecto/ecto#1412). I suggest using rc3 until a fix has been issued.
"Because of protocols, they can still be used with the Calendar functions for formatting, timezone shifting etc." this line from the changelog is simply not true. Functions like Calendar.DateTime.diff
are actually defined on data structures from Calendar
.
Furthermore I actually have some of my protocols implemented for Calendar
, now I have to duplicate this code for Calecto
structures.
And just out of curiosity why you decided to change the underlaying data structures?
Hi!
Does Calecto work with Ecto 3.x.y? I want to use custom Calecto.DateTime Ecto type for a project.
If that's the case we could update the ecto dependency
The following code fails because you can't use DateTime struct directly in queries:
def all_users() do
now = Calendar.DateTime.now_utc |> Calecto.DateTimeUTC.cast
from(u in Eager.User,
where: fragment("(?).wall_time > ?", u.start_datetime, ^now),
select: u)
end
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Ecto.Adapters.Postgres.DateTime.encode_timestamp/1
(ecto) lib/ecto/adapters/postgres/datetime.ex:47: Ecto.Adapters.Postgres.DateTime.encode_timestamp(%Calendar.DateTime{abbr: "UTC", day: 3, hour: 23, min: 53, month: 2, sec: 58, std_off: 0, timezone: "Etc/UTC", usec: 687669, utc_off: 0, year: 2016})
(postgrex) lib/postgrex/query.ex:90: DBConnection.Query.Postgrex.Query.do_encode/3
(postgrex) lib/postgrex/query.ex:51: DBConnection.Query.Postgrex.Query.encode/3
(db_connection) lib/db_connection.ex:885: DBConnection.describe_execute/5
(db_connection) lib/db_connection.ex:1009: DBConnection.run_begin/3
(db_connection) lib/db_connection.ex:957: DBConnection.run_meter/3
(db_connection) lib/db_connection.ex:421: DBConnection.query/4
(postgrex) lib/postgrex.ex:105: Postgrex.query/4
(ecto) lib/ecto/adapters/postgres/connection.ex:31: Ecto.Adapters.Postgres.Connection.query/4
(stdlib) timer.erl:197: :timer.tc/3
(ecto) lib/ecto/adapters/sql.ex:262: Ecto.Adapters.SQL.query/7
(ecto) lib/ecto/pool.ex:159: Ecto.Pool.do_run/4
(ecto) lib/ecto/adapters/sql.ex:247: Ecto.Adapters.SQL.query/6
(ecto) lib/ecto/adapters/sql.ex:225: Ecto.Adapters.SQL.query/5
(ecto) lib/ecto/adapters/sql.ex:183: Ecto.Adapters.SQL.query!/5
(ecto) lib/ecto/adapters/sql.ex:481: Ecto.Adapters.SQL.execute/6
(ecto) lib/ecto/repo/queryable.ex:95: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
Getting this error when using a Calendar.DateTime in a where:
Repo.all(from t in Tactic, where: t.account_id == ^account_id and t.updated_at >= ^sinceb, select: t)
** (UndefinedFunctionError) undefined function: Calendar.DateTime.type/0
(ecto) lib/ecto/query/planner.ex:124: Ecto.Query.Planner.prepare/3
(ecto) lib/ecto/query/planner.ex:66: Ecto.Query.Planner.query/4
(ecto) lib/ecto/repo/queryable.ex:91: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:15: Ecto.Repo.Queryable.all/4
Hi,
Great package, thanks a lot.
I have a question regarding making queries around datetime related schema
lets say we have this code
from r in Record,
where: r.start >= ^start and r.finish <= ^finish
what is the type that start
and finish
are supposed to be of? do they have to be the Calecto type that matches the field?
Is dump/1
called on start
/finish
? If so, what do you think about adding another dump/1
that is equivalent to this cast?
so we can write something like below and pass in raw datetime strings
def index(conn, %{
"user_id" => user_id,
"started_at" => started_at,
"finished_at" => finished_at
}) do
records = Repo.all(
from r in Record,
where: r.user_id == ^user_id
- and r.started_at >= ^cast!(started_at)
+ and r.started_at >= ^started_at
- and r.finished_at <= ^cast!(finished_at)
+ and r.finished_at <= ^finished_at
)
render(conn, "index.json", records: records)
end
Upgrading Ecto to 3.5 results in the following error when using the Calecto.DateTime
type on the ecto3
branch...
** (UndefinedFunctionError) function Calecto.DateTime.equal?/2 is undefined or private, but the behaviour Ecto.Type expects it to be present
I've been using Calecto.DateTime
for the past year without issue, but related tests fail upon upgrading to 3.5.
Hi @lau
Could you give this project a bump so it allows calendar 0.17? Maybe remove the .0
in ~> 0.16.0
:)
Thanks
I am a little confused on how to manage dates my phoenix app when my DB is on UTC and most (but not all) my users edit dates in a specific timezone (that is not UTC).
I posted my question to Elixir Forum (https://elixirforum.com/t/confused-with-storing-dates-with-calendar-ecto/2162) and José suggested create a PR for Calecto.DateTimeUTC.cast
to accept a non "etc/utc" timezone and convert it to utc.
What are your thoughts on this?
Thanks in advance.
Hi, what is the license for Calecto? I'm setting license information in ports and this one is missing :)
Compiling calecto produces the following warnings: (Ecto 2.0 & Elixir 1.3)
warning: function Ecto.Type.blank?/1 is undefined or private
lib/calecto/date.ex:18
warning: function Ecto.Type.blank?/1 is undefined or private
lib/calecto/date_time.ex:21
warning: function Ecto.Type.blank?/1 is undefined or private
lib/calecto/date_time_utc.ex:19
warning: function Ecto.Type.blank?/1 is undefined or private
lib/calecto/naive_date_time.ex:19
warning: function Ecto.Type.blank?/1 is undefined or private
lib/calecto/time.ex:19
It looks like Ecto.Type.blank?/1
was removed in Ecto 0.9. I don't know which versions of Ecto you want to support, but if you're open to removing this, I'll send a PR.
The mix helpers in Ecto have changed to support multiple repos being given to a tasks since this commit.
I will try to tackle this issue this week if I find the time.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.