All Projects → tanweerdev → fat_ecto

tanweerdev / fat_ecto

Licence: other
Query mechanism for Ecto

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to fat ecto

ecto autoslug field
Automatically create slugs for Ecto schemas.
Stars: ✭ 138 (+590%)
Mutual labels:  ecto, elixir-library
elixir-revisionair ecto
A Revisionair adapter based on Ecto. Allows you to persist and keep track of revisions of your data structures in any of Ecto's supported databases.
Stars: ✭ 18 (-10%)
Mutual labels:  ecto, elixir-library
Pine Utils
Code Snippets + Tricks & Tips to help Pine Script developers
Stars: ✭ 149 (+645%)
Mutual labels:  utils
Pandora
潘多拉的魔盒了解一下。
Stars: ✭ 248 (+1140%)
Mutual labels:  utils
Goutil
💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等
Stars: ✭ 205 (+925%)
Mutual labels:  utils
Auto Green
自动保持 GitHub 提交状态常绿 a commit every day, keep your girlfriend far away.
Stars: ✭ 164 (+720%)
Mutual labels:  utils
Bbo
bbo is a utility library of zero dependencies for javascript. 🍖🌭🍔
Stars: ✭ 227 (+1035%)
Mutual labels:  utils
Rxtool
Android开发人员不得不收集的工具类集合 | 支付宝支付 | 微信支付(统一下单) | 微信分享 | Zip4j压缩(支持分卷压缩与加密) | 一键集成UCrop选择圆形头像 | 一键集成二维码和条形码的扫描与生成 | 常用Dialog | WebView的封装可播放视频 | 仿斗鱼滑动验证码 | Toast封装 | 震动 | GPS | Location定位 | 图片缩放 | Exif 图片添加地理位置信息(经纬度) | 蛛网等级 | 颜色选择器 | ArcGis | VTPK | 编译运行一下说不定会找到惊喜
Stars: ✭ 11,567 (+57735%)
Mutual labels:  utils
lancet
A comprehensive, efficient, and reusable util function library of go.
Stars: ✭ 2,228 (+11040%)
Mutual labels:  utils
Jsonapi Utils
Build JSON API-compliant APIs on Rails with no (or less) learning curve.
Stars: ✭ 191 (+855%)
Mutual labels:  utils
Just
A library of dependency-free JavaScript functions that do just do one thing.
Stars: ✭ 3,837 (+19085%)
Mutual labels:  utils
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (+810%)
Mutual labels:  utils
Fastandrutils
android快速开发工具类
Stars: ✭ 165 (+725%)
Mutual labels:  utils
Flutter commonapp
打造一款通用的AppUI结构,包括登录、注册等通用 UI 界面及各工具类和公共部分。
Stars: ✭ 227 (+1035%)
Mutual labels:  utils
React Children Utilities
Extended utils for ⚛️ React.Children data structure that adds recursive filter, map and more methods to iterate nested children.
Stars: ✭ 154 (+670%)
Mutual labels:  utils
dt-utils
前端常用工具函数
Stars: ✭ 23 (+15%)
Mutual labels:  utils
Rambdax
Extended version of Rambda
Stars: ✭ 148 (+640%)
Mutual labels:  utils
Vtils
一个面向业务的 JavaScript/TypeScript 实用程序库。支持在浏览器、Node.js、小程序、Taro、Deno 下使用。
Stars: ✭ 177 (+785%)
Mutual labels:  utils
Stdlib
✨ Standard library for JavaScript and Node.js. ✨
Stars: ✭ 2,749 (+13645%)
Mutual labels:  utils
BaseToolsLibrary
Android通用适配器和常用的工具类
Stars: ✭ 24 (+20%)
Mutual labels:  utils

FatEcto

Description

FAT provides methods for dynamically building queries depending on the parameters it receive.

Currently it's supporting following query functions:

  • where
  • select
  • joins
  • order_by
  • include
  • group_by

Installation

you can get latest from github or published version from hex

{:fat_ecto, github: "tanweerdev/fat_ecto"}
or
{:fat_ecto, "~> 0.1"}

Please do not pass custom $join type for associations which are related via has_many or many_to_many eg

# Please dont pass join like below to avoid un-expected/duplicated records
"$include": %{"doctors" => %{"$join" => "left"}}
# correct way
"$include": %{"doctors" => %{}}

Config

config :my_app, :fat_ecto,
  repo: ExApi.Repo,
  default_limit: 10,
  max_limit: 100

Usage

Once installed you can use FatEcto.FatQuery inside your module and use the build method. Which is the entry method for building every query. And also the main method for the FatEcto.FatQuery.

build(schema_name, params)

Example

defmodule MyApp.Query do
  use FatEcto.FatQuery, otp_app: :my_app, max_limit: 103, default_limit: 34
end

import MyApp.Query
query_opts = %{
      "$select" => %{
        "$fields" => ["name", "location", "rating"],
        "fat_rooms" => ["beds", "capacity"]
      },
      "$order" => %{"id" => "$desc"},
      "$where" => %{"rating" => 4},
      "$group" => ["total_staff", "rating"],
      "$include" => %{
        "fat_doctors" => %{
          "$include" => ["fat_patients"],
          "$where" => %{"name" => "ham"},
          "$order" => %{"id" => "$desc"},
          "$join" => "$right"
        }
      },
      "$right_join" => %{
        "fat_rooms" => %{
          "$on_field" => "id",
          "$on_table_field" => "hospital_id",
          "$select" => ["beds", "capacity", "level"],
          "$where" => %{"incharge" => "John"},
          "$order" => %{"level" => "$asc"}
        }
      }
    }
iex> build(FatEcto.FatHospital, query_opts)
iex> #Ecto.Query<from f0 in FatEcto.FatHospital, right_join: f1 in "fat_rooms",
     on: f0.id == f1.hospital_id, right_join: f2 in assoc(f0, :fat_doctors),
     where: f0.rating == ^4 and ^true, where: f1.incharge == ^"John" and ^true,
     group_by: [f0.total_staff], group_by: [f0.rating], order_by: [asc: f1.level],
     order_by: [desc: f0.id],
     select: merge(map(f0, [:name, :location, :rating, :id, {:fat_rooms, [:beds, :capacity]}]),
     %{^:fat_rooms => map(f1, [:beds, :capacity, :level])}),
     preload: [fat_doctors: #Ecto.Query<from f0 in FatEcto.FatDoctor,
     left_join: f1 in assoc(f0, :fat_patients),
     where: f0.name == ^"ham" and ^true, order_by: [desc: f0.id],
     limit: ^10, offset: ^0, preload: [:fat_patients]>]>
Options:

These are the options supported

Option Description
$include Include the assoication model doctors
$include: :fat_patients Include the assoication patients. Which has association with doctors
$select Select the fields from hospital and rooms
$where Added the where attribute in the query
$group Added the group_by attribute in the query as a list
$order Sort the result based on the order attribute
$right_join Specify the type of join
$on_field Specify the field for join
$on_table_field Specify the field for join in the joining table

see Docs for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].