ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - bitgamma/crudex: CRUD utilities for Phoenix and Ecto
CRUD utilities for Phoenix and Ecto. Contribute to bitgamma/crudex development by creating an account on GitHub.
Visit Site

GitHub - bitgamma/crudex: CRUD utilities for Phoenix and Ecto

GitHub - bitgamma/crudex: CRUD utilities for Phoenix and Ecto

Crudex

A glue keeping Phoenix and Ecto together. It has the following features:

  • JSON-encoding/decoding of Ecto models
  • Dynamic virtual fields for models
  • Simplifies creation of CRUD controllers
  • User controller for login.

Crudex.Model

By using the Crudex.Model module, like this:

defmodule MyModel do
  use Crudex.Model
end

You make your model JSON-encodable using Poison. You should also use Ecto.UUID, Crudex.JSONBinary, Ecto.DateTime instead of :uuid, :binary, and :datetime in your model respectively.

The Crudex.Model also provides the following macros:

  • crudex_schema => is like schema from Ecto.Model but defines ID/foreign keys to be UUID and creates timestamps. You should use this if you want to use the CRUD controller functionalities. It also allows using the two macros below
  • hidden_field => creates a regular field which will be excluded when encoding

Example

defmodule Example.User do
  use Crudex.Model

  crudex_schema "users" do 
    field :name, :string   
    field :surname, :string   
    field :email, :string
    hidden_field :salt, Crudex.JSONBinary
    hidden_field :password, Crudex.JSONBinary
    field :role, :string
  end
    
  ...
end

Crudex.CrudController

Allows automatic creation of complete or partial CRUD controllers. It even supports user scoping, assuming your model has a user_id field.

It has two macros

  • crud_for => creates CRUD actions for the given model. Optionally you can specify which actions should be created.
  • defcrud => defines a single CRUD action for the given model.

Example

defmodule BookController do
  use Crudex.CrudController

  plug PlugAuth.Authentication.Token, [source: :params, param: "auth_token"]
  plug :action

  @ecto_repo MyRepo
  @user_scoped true
  crud_for(Book)
end

Assuming you have a Book model, you will get the :index, :create, :show, :update, :delete actions created for you. Since @user_scoped is set to true, all actions will only be applicable for the user currently logged in. This works best in conjunction with plug_auth.

Crudex.UserController

Provides a macro, user_controller to define a simple user controller. Access control should happen in the controller invoking this macro, using for example plug_auth. It is not very flexible for now, and is more there to show you how to do a complex controller with Crudex.

TODO

There is a lot to do, pagination and filtering is one of the first things. Tests are missing although I have tests in the projects where I use this. Documentation in the code is also missing for now.

LICENSE

Copyright (c) 2014, Michele Balistreri [email protected]

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory