Skip to content

Instantly share code, notes, and snippets.

@rhiroyuki
Last active April 3, 2021 18:45
Show Gist options
  • Save rhiroyuki/5abbe94ec1b72b4acfbc54ed166cfad2 to your computer and use it in GitHub Desktop.
Save rhiroyuki/5abbe94ec1b72b4acfbc54ed166cfad2 to your computer and use it in GitHub Desktop.

Revisions

  1. rhiroyuki revised this gist Apr 3, 2021. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -49,3 +49,17 @@ iex -S mix phx.server
    ```
    # recompile
    ```


    ### Scaffold

    ```
    $ mix phx.gen.context Todos Todo todos title:string done:boolean
    * creating lib/live_view_todos/todos/todo.ex
    * creating priv/repo/migrations/20210403184352_create_todos.exs
    * creating lib/live_view_todos/todos.ex
    * injecting lib/live_view_todos/todos.ex
    * creating test/live_view_todos/todos_test.exs
    * injecting test/live_view_todos/todos_test.exs
    ```
  2. rhiroyuki revised this gist Apr 2, 2021. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -43,3 +43,9 @@ Run the server with the following command:
    ```
    iex -S mix phx.server
    ```

    ### Reloading

    ```
    # recompile
    ```
  3. rhiroyuki revised this gist Mar 25, 2020. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,12 @@ User.last
    Repo.one(from x in Model, order_by: [desc: x.id], limit: 1)
    ```

    ## Querying
    ```
    Repo.all(from x in SomeModel, where: x.greeted == true)
    ```


    ## Prying
    ```
    require IEx; IEx.pry
  4. rhiroyuki revised this gist Mar 24, 2020. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -28,3 +28,12 @@ User.last
    Repo.one(from x in Model, order_by: [desc: x.id], limit: 1)
    ```

    ## Prying
    ```
    require IEx; IEx.pry
    ```

    Run the server with the following command:
    ```
    iex -S mix phx.server
    ```
  5. rhiroyuki revised this gist Feb 20, 2020. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -16,12 +16,15 @@ Repo.one(from x in Model, limit: 1)
    ```

    Getting the last record

    ### ActiveRecord
    ```
    # ActiveRecord
    User.last
    ```


    ### Ecto
    ```
    # Ecto
    Repo.one(from x in Model, order_by: [desc: x.id], limit: 1)
    ```
    ```

  6. rhiroyuki revised this gist Feb 20, 2020. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,17 @@
    ## Ecto

    Getting the first record

    ### In ActiveRecord
    ```
    # ActiveRecord
    User.first
    ```

    ### In Ecto
    ```
    # Ecto
    Repo.one(from x in Model, order_by: [asc: x.id], limit: 1)
    # You can hide the order_by since it is ascending by default
    Repo.one(from x in Model, limit: 1)
    ```

  7. rhiroyuki created this gist Feb 20, 2020.
    23 changes: 23 additions & 0 deletions elixir_cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    ## Ecto

    Getting the first record
    ```
    # ActiveRecord
    User.first
    ```
    ```
    # Ecto
    Repo.one(from x in Model, order_by: [asc: x.id], limit: 1)
    Repo.one(from x in Model, limit: 1)
    ```

    Getting the last record
    ```
    # ActiveRecord
    User.last
    ```

    ```
    # Ecto
    Repo.one(from x in Model, order_by: [desc: x.id], limit: 1)
    ```