Skip to content

Instantly share code, notes, and snippets.

View abadongutierrez's full-sized avatar
💻
working

Rafael Gutiérrez abadongutierrez

💻
working
View GitHub Profile
Repo.all(from d in "department", select: [d.department_id, d.name])
SELECT department_id, name FROM department
Repo.all(from d in "department")
Repo.insert_all("department", [[name: "Human Resources"]])
Repo.insert_all("employee", [[first_name: "Steve", last_name: "Jobs", hire_date: {1976, 1, 4}, department_id: 1]])
Repo.insert_all("employee", [[first_name: "Steve", last_name: "Wozniak", hire_date: {1976, 1, 4}, department_id: 1]])
Repo.insert_all("employee", [[first_name: "Ronald", last_name: "Wayne", hire_date: {1976, 1, 4}, department_id: 1]])
Repo.insert_all("department", [[name: "R&D"]])
Repo.update_all(from(e in "employee",
where: e.first_name == "Steve"),
set: [department_id: 2])
Repo.all(from e in "employee",
join: d in "department", on: e.department_id == d.department_id,
where: d.department_id == 2,
select: [e.first_name, e.last_name, d.name])
Repo.delete_all(from e in "employee",
where: e.last_name == "Wayne")
Repo.all(from e in "employee",
select: [e.employee_id, e.first_name, e.last_name])
@abadongutierrez
abadongutierrez / department_table.exs
Last active June 9, 2017 03:31
Ecto migration file to create a table department
defmodule Ecto101MigrationsSchemas.Repo.Migrations.DepartmentTable do
use Ecto.Migration
def change do
create table(:department) do
add :name, :text, null: false
timestamps()
end
end