All Projects → MikaAK → ecto_shorts

MikaAK / ecto_shorts

Licence: MIT license
Shortcuts for ecto

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to ecto shorts

Kronky
Kronky bridges the gap between Ecto and Absinthe GraphQL by listing validation messages in a mutation payload.
Stars: ✭ 112 (+38.27%)
Mutual labels:  ecto
Filtrex
A library for performing and validating complex filters from a client (e.g. smart filters)
Stars: ✭ 157 (+93.83%)
Mutual labels:  ecto
Etso
Ecto 3 adapter allowing use of Ecto schemas held in ETS tables
Stars: ✭ 226 (+179.01%)
Mutual labels:  ecto
Rethinkdb ecto
RethinkDB adapter for Ecto.
Stars: ✭ 112 (+38.27%)
Mutual labels:  ecto
Ecto autoslug field
Automatically create slugs for Ecto schemas.
Stars: ✭ 129 (+59.26%)
Mutual labels:  ecto
Rummage ecto
Search, Sort and Pagination for ecto queries
Stars: ✭ 190 (+134.57%)
Mutual labels:  ecto
Ecto state machine
State machine pattern for Ecto
Stars: ✭ 91 (+12.35%)
Mutual labels:  ecto
fat ecto
Query mechanism for Ecto
Stars: ✭ 20 (-75.31%)
Mutual labels:  ecto
Mipha
Proj Elixir Forum build with phoenix 1.5.
Stars: ✭ 153 (+88.89%)
Mutual labels:  ecto
Ecto mnesia
Ecto adapter for Mnesia Erlang term database.
Stars: ✭ 223 (+175.31%)
Mutual labels:  ecto
Scrivener html
HTML view helpers for Scrivener
Stars: ✭ 112 (+38.27%)
Mutual labels:  ecto
Phoenix live dashboard
Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Stars: ✭ 1,657 (+1945.68%)
Mutual labels:  ecto
Formex
A better form library for Phoenix
Stars: ✭ 206 (+154.32%)
Mutual labels:  ecto
Elixir Cowboy React Spa
Example application that shows how to use Cowboy 2.0 in conjunction with React and Redux to create data driven Single Page Applications
Stars: ✭ 112 (+38.27%)
Mutual labels:  ecto
Params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters.
Stars: ✭ 239 (+195.06%)
Mutual labels:  ecto
Defql
Create elixir functions with SQL as a body.
Stars: ✭ 100 (+23.46%)
Mutual labels:  ecto
Phoenix Ecto Encryption Example
🔐 A detailed example for how to encrypt data in a Phoenix (Elixir) App before inserting into a database using Ecto Types
Stars: ✭ 166 (+104.94%)
Mutual labels:  ecto
absinthe error payload
Bridges the gap between Ecto and Absinthe for mutation payload
Stars: ✭ 102 (+25.93%)
Mutual labels:  ecto
ecto erd
A mix task for generating Entity Relationship Diagram from Ecto schemas available in your project.
Stars: ✭ 173 (+113.58%)
Mutual labels:  ecto
Ex audit
Ecto auditing library that transparently tracks changes and can revert them.
Stars: ✭ 214 (+164.2%)
Mutual labels:  ecto

EctoShorts

Hex version badge

Ecto Shorts is a library focused around making Ecto easier to use in an application and helping to write shorter code

Installation

Documentation can be found at https://hexdocs.pm/ecto_shorts.

def deps do
  [
    {:ecto_shorts, "~> 1.1"}
  ]
end

Usage

There are 4 main modules to EctoShorts. SchemaHelpers, CommonFilters, CommonChanges and Actions

With our Actions.create and related functions we can also define create_changeset(params) on our schema, this usually looks like:

def create_changeset(params \\ %{}), do: changeset(%__MODULE__{}, params)

or some other variation of changeset that runs specifically on creates

Actions

This module takes a schema and filter parameters and runs them through CommonFilters, esentially a wrapper around Repo. All actions can accept an optional argument of a keyword list that can be used to configure which Repo the Action should use.

Options

* `:repo` - A module that uses the Ecto.Repo Module.
* `:replica` - If you don't want to perform any reads against your Primary, you can specify a replica to read from.

For more info on filter options take a look at Common Filters

Common Changes

This module is responsible for determining put/cast assoc as well as creating and updating model relations

Extra Magic

If you pass a list of id's to a many to many relation it will count that as a member_update and remove or add members to the relations list

E.G. User many_to_many Fruit

This would update the user to have only fruits with id 1 and 3

CommonChanges.put_or_cast_assoc(change(user, fruits: [%{id: 1}, %{id: 3}]), :fruits)

Schema Helpers

This module contains helpers to check schema data

Common Filters

This module creates query from filter paramters like

CommonFilters.convert_params_to_filter(User, %{id: 5})

is the same as

from u in User, where: id == 5

This allows for filters to be constructed from data such as

CommonFilters.convert_params_to_filter(User, %{
  favorite_food: "curry",
  age: %{gte: 18, lte: 50},
  name: %{ilike: "steven"},
  preload: [:address],
  last: 5
})

which the equivalent would be

from u in User,
  preload: [:address],
  limit: 5,
  where: u.favorite_food == "curry" and
         u.age >= 18 and u.age <= 50 and
         ilike(u.name, "%steven%")

We are also able to query on the first layer of relations like so:

EctoShorts.Actions.all(User, %{
  roles: ["ADMIN", "SUPERUSER"]
})

which would be equivalent to:

from u in User,
  inner_join: r in assoc(u, :roles), as: :ecto_shorts_roles,
  where: r.code in ["ADMIN", "SUPERUSER"]

Finally we can also query array fields by doing the following

EctoShorts.Actions.all(User, %{
  items: [1, 2],
  cart: 3
})

which for an array field would be the equivalent to:

from u in User,
  where: ^3 in u.cart and u.items == [1, 2]
List of common filters
  • preload - Preloads fields onto the query results
  • start_date - Query for items inserted after this date
  • end_date - Query for items inserted before this date
  • before - Get items with ID's before this value
  • after - Get items with ID's after this value
  • ids - Get items with a list of ids
  • first - Gets the first n items
  • last - Gets the last n items
  • search - Warning: This requires schemas using this to have a &by_search(query, val) function
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].