Code Monkey home page Code Monkey logo

fat_ecto's Issues

Error while using `$where` with DateTime values

Hi! First, let me thank you for all the effort in this library ๐ŸŽ‰

I'm opening this issue because there's seems to be an error when applying eq operations with DateTime values (potentially with other date-time structs too).

The one bellow works correctly:

opts = %{
  "child_table" => %{
    "$where" => %{
      "inserted_at" => %{
        "$gt" => ~U[2020-01-01 00:00:00Z],
        "$lt" => ~U[2022-01-01 00:00:00Z]
      },
      "value" => 3000
    }
  }
}

build!(MyApp.Model, %{"include" => opts})

But the following example doesn't seem to work ๐Ÿ˜ž. Is there's something wrong with the options and trying to apply in this case?

opts = %{
  "child_table" => %{
    "$where" => %{
      "inserted_at" => ~U[2022-01-01 00:00:00Z],
      "value" => 3000
    }
  }
}

build!(MyApp.Model, %{"include" => opts})

Here's the stack trace of the error:

[error] ** (Protocol.UndefinedError) protocol Enumerable not implemented for ~U[2020-01-01 00:00:00Z] of type DateTime (a struct)
    (elixir 1.11.2) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.11.2) lib/enum.ex:141: Enumerable.reduce/3
    (elixir 1.11.2) lib/enum.ex:3461: Enum.reduce/3
    (stdlib 3.14) maps.erl:233: :maps.fold_1/3
    (fat_ecto 0.5.0) lib/fat_ecto/query/where.ex:741: FatEcto.FatQuery.FatWhere.build_where/4
    (fat_ecto 0.5.0) lib/fat_ecto/query/include.ex:113: anonymous fn/4 in FatEcto.FatQuery.FatInclude.build_include/4
    (stdlib 3.14) maps.erl:233: :maps.fold_1/3

FatEcto.FatContext generates a lot of warnings upon compilation

Upon compiling fat_ecto for the first time, I get the following warnings:

==> fat_ecto
Compiling 25 files (.ex)
warning: function nil.all/1 is undefined (module nil is not available)
Found at 2 locations:
  lib/fat_ecto/context.ex:68
  lib/fat_ecto/paginator.ex:66

warning: function nil.all/2 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:140

warning: function nil.delete/1 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:116

warning: function nil.delete_all/1 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:122

warning: function nil.get/2 is undefined (module nil is not available)
Found at 2 locations:
  lib/fat_ecto/context.ex:76
  lib/fat_ecto/context.ex:85

warning: function nil.get!/2 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:72

warning: function nil.get_by/2 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:96

warning: function nil.insert/1 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:104

warning: function nil.one/1 is undefined (module nil is not available)
Found at 6 locations:
  lib/fat_ecto/context.ex:24
  lib/fat_ecto/context.ex:43
  lib/fat_ecto/context.ex:49
  lib/fat_ecto/context.ex:56
  lib/fat_ecto/paginator.ex:76
  lib/fat_ecto/query.ex:158

warning: function nil.preload/2 is undefined (module nil is not available)
Found at 5 locations:
  lib/fat_ecto/context.ex:68
  lib/fat_ecto/context.ex:78
  lib/fat_ecto/context.ex:86
  lib/fat_ecto/context.ex:97
  lib/fat_ecto/context.ex:141

warning: function nil.update/1 is undefined (module nil is not available)
  lib/fat_ecto/context.ex:111

I see that one can use this module by use FatEcto.FatContext, repo: MyRepo, but I'm not doing this as I don't need this module so it generates a lot of useless warnings. Any ideas?

How to create "or" statements in the same table/field

Hi again ๐Ÿ‘‹

I was wondering how could we create the following query?

select parent.* 
left join child on child.parent_id = parent.id 
where ((child.field > 5 and child.field < 2) or (child.field IS NULL))

I know that there's the "$or" key at the moment but it doesn't seem to do what we need ๐Ÿ˜ข.

Thanks in advance again for the help!

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.