Giter Site home page Giter Site logo

Comments (5)

stevedomin avatar stevedomin commented on August 25, 2024 1

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.

lau avatar lau commented on August 25, 2024

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.

josevalim avatar josevalim commented on August 25, 2024

@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.

stevedomin avatar stevedomin commented on August 25, 2024

@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)
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.

josevalim avatar josevalim commented on August 25, 2024

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)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


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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.