Comments (5)
The following code is working:
def upcoming_events(group) do
{:ok, now} = Calendar.DateTime.now_utc |> Calecto.DateTimeUTC.cast
from(g in Eager.Group,
join: e in assoc(g, :events),
where: e.group_id == ^group.id,
where: fragment("(?).wall_time > ?", e.start_datetime, type(^now, :datetime)),
select: e)
end
which I simplified to:
def upcoming_events(group) do
now = Calendar.DateTime.now_utc
from(g in Eager.Group,
join: e in assoc(g, :events),
where: e.group_id == ^group.id,
where: fragment("(?).wall_time > ?", e.start_datetime, type(^now, :datetime)),
select: e)
end
from calecto.
It looks like changes are needed in Ecto. Because it is a composite type. Calendar structs should work directly with the other field types.
Until Ecto is changed, it is necessary to convert the DateTime structs to "micro_erl" tupples with DateTime.micro_erl e.g. DateTime.now_utc |> DateTime.to_micro_erl
from calecto.
@stevedomin can you please try the following:
where: fragment("(?).wall_time > ?", type(u.start_datetime, :datetime), type(^now, :datetime))
If it doesn't work, please try Ecto.DateTime
instead of :datetime
.
from calecto.
def upcoming_events(group) do
now = Calendar.DateTime.now_utc |> Calecto.DateTimeUTC.cast
#now = Calendar.DateTime.now_utc |> Calendar.DateTime.to_micro_erl
from(g in Eager.Group,
join: e in assoc(g, :events),
where: e.group_id == ^group.id,
where: fragment("(?).wall_time > ?", type(e.start_datetime, :datetime), type(^now, :datetime)),
#where: fragment("(?).wall_time > ?", e.start_datetime, ^now),
select: e)
end
# error
** (Ecto.Query.CompileError) `type(e.start_datetime(), :datetime)` is not a valid query expression.
* If you intended to call a database function, please check the documentation
for Ecto.Query to see the supported database expressions
* If you intended to call an Elixir function or introduce a value,
you need to explicitly interpolate it with ^
Same error with Ecto.DateTime
from calecto.
Sorry, you should use type only on the last value, the one you interpolate
on.
On Friday, February 19, 2016, Steve Domin [email protected] wrote:
@josevalim https://github.com/josevalim
def upcoming_events(group) do
now = Calendar.DateTime.now_utc |> Calecto.DateTimeUTC.cast #now = Calendar.DateTime.now_utc |> Calendar.DateTime.to_micro_erl
from(g in Eager.Group,
join: e in assoc(g, :events),
where: e.group_id == ^group.id,
where: fragment("(?).wall_time > ?", type(e.start_datetime, :datetime), type(^now, :datetime)), #where: fragment("(?).wall_time > ?", e.start_datetime, ^now),
select: e)enderror** (Ecto.Query.CompileError)
type(e.start_datetime(), :datetime)
is not a valid query expression.
- If you intended to call a database function, please check the documentation
for Ecto.Query to see the supported database expressions- If you intended to call an Elixir function or introduce a value,
you need to explicitly interpolate it with ^Same error with Ecto.DateTime
—
Reply to this email directly or view it on GitHub
#18 (comment).
José Valimwww.plataformatec.com.br
http://www.plataformatec.com.br/Founder and Director of R&D
from calecto.
Related Issues (20)
- Ecto cannot cast DateTime in query HOT 4
- 0.4.0 breaks my build HOT 10
- Mix task for adding Postgres type is broken HOT 3
- Rename Calecto.Model HOT 3
- Integration tests HOT 1
- Hex dependency resolution failed HOT 4
- how to query HOT 5
- Issue with Ecto 2.0.0-rc4
- How to use timezone with timestamps(inserted_at, updated_at) columns? HOT 1
- Compile warnings HOT 2
- Update the hex package HOT 3
- Converting non-UTC timezones to UTC during cast HOT 4
- Duplicated modules HOT 15
- Casting from Calendar.DateTime to DateTimeUTC is not working at all HOT 5
- Unlock calendar
- Loading / Encoding issues. HOT 3
- Ecto 3.x.y dependency question HOT 5
- ecto3 branch: Calecto.DateTime does not conform to Ecto 3.5 Ecto.Type behavior HOT 4
- Quick licensing question HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from calecto.