Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI
on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Start services
run: docker compose up -d

- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
id: setup-elixir
with:
version-type: strict
version-file: .tool-versions

- name: Restore the cache
uses: actions/cache@v3
with:
path: |
deps
_build
dialyzer
key: |
${{ runner.os }}-${{ steps.setup-elixir.outputs.elixir-version }}-${{ steps.setup-elixir.outputs.otp-version }}-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-elixir.outputs.elixir-version }}-${{ steps.setup-elixir.outputs.otp-version }}-mixlockhash-

- name: Run CI
run: |
mix ci
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
erlang 27.2
elixir 1.18.0-otp-27
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
postgres:
image: postgres:17-alpine
environment:
POSTGRES_USER: guest
POSTGRES_PASSWORD: guest
POSTGRES_DB: query_test
ports:
- "5432:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U guest" ]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped
36 changes: 18 additions & 18 deletions lib/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ defmodule Query do
@type options :: [option()]

@app_config Application.get_all_env(:query)
@opts_schema %{
page_default: [default: 1, type: :integer],
page_param: [default: "page", type: :binary],
limit_default: [default: 20, type: :integer],
limit_max: [default: 50, type: :integer],
limit_param: [default: "limit", type: :binary],
sort_default: [default: "id", type: :binary],
sort_param: [default: "sort_by", type: :binary],
sort_permitted: [default: [], type: {:list, :binary}],
dir_default: [default: "asc", type: :binary],
dir_param: [default: "dir", type: :binary],
count: [default: true, type: :boolean],
count_limit: [default: :infinite, type: [:atom, :integer]],
count_column: [default: :id, type: :atom],
scope: [required: false, type: [{:tuple, {:atom, :atom}}]],
scope_permitted: [default: [], type: {:list, :binary}],
preloads: [default: [], typee: {:list, :atom}]
}
@opts_schema KeywordValidator.schema!(
page_default: [default: 1, is: :integer],
page_param: [default: "page", is: :binary],
limit_default: [default: 20, is: :integer],
limit_max: [default: 50, is: :integer],
limit_param: [default: "limit", is: :binary],
sort_default: [default: "id", is: :binary],
sort_param: [default: "sort_by", is: :binary],
sort_permitted: [default: [], is: {:list, :binary}],
dir_default: [default: "asc", is: :binary],
dir_param: [default: "dir", is: :binary],
count: [default: true, is: :boolean],
count_limit: [default: :infinite, is: {:one_of, [:atom, :integer]}],
count_column: [default: :id, is: :atom],
scope: [required: false, is: {:tuple, {:atom, :atom}}],
scope_permitted: [default: [], is: {:list, :binary}],
preloads: [default: [], is: {:list, :atom}]
)

@doc """
Fetches data from the given repository based on the params and options given.
Expand Down
39 changes: 34 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
defmodule Query.Mixfile do
use Mix.Project

@version "0.5.1"
@version "0.6.0"

def project do
[
app: :query,
version: @version,
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
aliases: aliases(),
preferred_cli_env: preferred_cli_env(),
description: description(),
package: package(),
start_permanent: Mix.env() == :prod,
Expand All @@ -23,6 +25,33 @@ defmodule Query.Mixfile do
]
end

# Aliases are shortcuts or tasks specific to the current project.
defp aliases do
[
setup: [
"local.hex --if-missing --force",
"local.rebar --if-missing --force",
"deps.get"
],
ci: [
"setup",
"compile --warnings-as-errors",
"format --check-formatted",
"ecto.drop -r Query.Ecto.Repo",
"ecto.create -r Query.Ecto.Repo",
"ecto.migrate -r Query.Ecto.Repo",
"test"
]
]
end

# Specifies the preferred env for mix commands.
defp preferred_cli_env do
[
ci: :test
]
end

defp description do
"""
Query adds simple tools to aid the use of Ecto in web settings.
Expand All @@ -47,10 +76,10 @@ defmodule Query.Mixfile do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ecto, "~> 3.0"},
{:keyword_validator, "~> 1.0"},
{:ecto_sql, "~> 3.0", only: :test},
{:postgrex, "~> 0.14.1", only: :test},
{:ecto, "~> 3.13"},
{:ecto_sql, "~> 3.13", only: :test},
{:keyword_validator, "~> 2.0"},
{:postgrex, "~> 0.19", only: :test},
{:ex_doc, "~> 0.20", only: :dev, runtime: false}
]
end
Expand Down
26 changes: 13 additions & 13 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
%{
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"db_connection": {:hex, :db_connection, "2.0.6", "bde2f85d047969c5b5800cb8f4b3ed6316c8cb11487afedac4aa5f93fd39abfa", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.1.3", "b3c2ef40b742fa76e2cc1c2fa46965e445d1ea8fd92330d64e0ae84114f53bcf", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.1.1", "af2458e7a467d75a6389e1d4ebfb57c328ccc684d6ee52145f7b34e94efb5fc4", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"keyword_validator": {:hex, :keyword_validator, "1.0.0", "a1421d0ae47ff3638b45b695427a00302ca278b869b9d9f9f22d4da5e0f4d660", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
"db_connection": {:hex, :db_connection, "2.8.1", "9abdc1e68c34c6163f6fb96a96532272d13ad7ca45262156ae8b7ec6d9dc4bec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a61a3d489b239d76f326e03b98794fb8e45168396c925ef25feb405ed09da8fd"},
"decimal": {:hex, :decimal, "2.3.0", "3ad6255aa77b4a3c4f818171b12d237500e63525c2fd056699967a3e7ea20f62", [:mix], [], "hexpm", "a4d66355cb29cb47c3cf30e71329e58361cfcb37c34235ef3bf1d7bf3773aeac"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
"ecto": {:hex, :ecto, "3.13.3", "6a983f0917f8bdc7a89e96f2bf013f220503a0da5d8623224ba987515b3f0d80", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1927db768f53a88843ff25b6ba7946599a8ca8a055f69ad8058a1432a399af94"},
"ecto_sql": {:hex, :ecto_sql, "3.13.2", "a07d2461d84107b3d037097c822ffdd36ed69d1cf7c0f70e12a3d1decf04e2e1", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "539274ab0ecf1a0078a6a72ef3465629e4d6018a3028095dc90f60a19c371717"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},
"keyword_validator": {:hex, :keyword_validator, "2.1.0", "03dea179912e9ef280f4784affbfecd12957ef578d88b7aea4bbef68b7db3882", [:mix], [], "hexpm", "9c8cff861cadea92d9b9469983ba58bc35d03a2ceb38c39665e401e8668e324f"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5fbc8e549aa9afeea2847c0769e3970537ed302f93a23ac612602e805d9d1e7f"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "adf0218695e22caeda2820eaba703fa46c91820d53813a2223413da3ef4ba515"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm", "5c040b8469c1ff1b10093d3186e2e10dbe483cd73d79ec017993fb3985b8a9b3"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.2", "6680591bbce28d92f043249205e8b01b36cab9ef2a7911abc43649242e1a3b78", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.21.1", "2c5cc830ec11e7a0067dd4d623c049b3ef807e9507a424985b8dcf921224cd88", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "27d8d21c103c3cc68851b533ff99eef353e6a0ff98dc444ea751de43eb48bdac"},
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
}
4 changes: 2 additions & 2 deletions test/support/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule Query.Ecto.Repo do
database: "query_test",
hostname: "localhost",
port: 5432,
username: "postgres",
password: ""
username: "guest",
password: "guest"
)

{:ok, config}
Expand Down