[Gabriel Kolawole] # _

Recent Posts

Ecto order_by text field

published on
This post demonstrates how to order an ecto query by a text field. by sending the order raw sql query through Ecto.Query.API.fragment/1 Sample table Assuming we want to query a table containing a list of scheduled jobs with known statuses. e.g RUNNING, PENDING, COMPLETED, FAILED id task_ref status last_exec_timestamp 1 2232323 PENDING 1605726253 2 2232324 FAILED 1605726153 4 2232326 RUNNING 1605726233 5 2232326 RUNNING 1605726233 6 2232326 FAILED 1605726233 7 2232326 COMPLETED 1605726233 8 2232326 FAILED 1605726233 Our objective is to: Read More...

Composing dynamic queries with ecto

published on
I was recently working on a project where I needed to compose a dynamic query for filtering a table using ecto. The filter parameters are coming from a graphql resolver. # ~/query.ex #A sample filter input filter_input = %{status: "AVAILABLE", genre: "Comedy", last_update_gte: "2018-10-18 00:00:00", last_update_lte: "2018-10-18 23:59:59" } #The schema I will be querying defmodule Movies do use Ecto.Schema schema "movies" do field(:genre, :string) field(:status, :string) timestamps() end end #My resolver function defmodule MovieFilter do import Ecto. Read More...

Testing with Mocks

published on
The situation was that, I needed to mock multiple external service within my application in order to test my application. These external services are being consumed using HTTPPoison the popular elixir http client. The mock is achieved using the Mock library # ~/multi_mocks.exs Import Mock #Mock multiple functions of the same module test "Test special service that will call other supporting endpoints" do with_mock( HTTPoison, post!: fn endpoint_a, _, _ -> %HTTPoison. Read More...

Categories

Ecto (1)

Elixir (7)

Tags

anonymous (1) bot (1) capture (1) controller (1) copy (1) database (1) ecto (2) elixir (8) fragments (1) genserver (1) graphql (1) libraries (1) mocking (1) operator (1) order_by (1) plug (1) query (1) recursion (1) resource (1) telegram (1) testing (2)