Current section

Files

Jump to
arke_postgres lib arke_postgres table.ex
Raw

lib/arke_postgres/table.ex

defmodule ArkePostgres.Table do
import Ecto.Query, only: [from: 2]
def get_all(project, schema, fields, where \\ []) do
query = from(Atom.to_string(schema.id), select: ^fields, where: ^where)
ArkePostgres.Repo.all(query, prefix: project)
end
def get_by(project, schema, fields, where) do
query = from(Atom.to_string(schema.id), select: ^fields, where: ^where)
ArkePostgres.Repo.one(query, prefix: project)
end
def insert(project, schema, data) do
ArkePostgres.Repo.insert_all(Atom.to_string(schema.id), [data], prefix: project)
end
def update(project, schema, data, where \\ []) do
query = from(Atom.to_string(schema.id), where: ^where, update: [set: ^data])
ArkePostgres.Repo.update_all(query, [], prefix: project)
end
def delete(project, schema, where) do
query = from(a in Atom.to_string(schema.id), where: ^where)
{1, _} = ArkePostgres.Repo.delete_all(query, prefix: project)
end
end