Skip to content

Commit

Permalink
implement generation of EdgeQL queries modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nsidnev committed Feb 25, 2024
1 parent ffe21a1 commit 3cd967d
Show file tree
Hide file tree
Showing 787 changed files with 25,336 additions and 319 deletions.
10 changes: 8 additions & 2 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
excluded: [
~r"/_build/",
~r"/deps/",
~r"/node_modules/",
~r"/test/codegen/queries/",
~r"/test/support/scripts/"
]
},
#
# Load and configure plugins here:
Expand Down Expand Up @@ -131,7 +137,7 @@
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.Nesting, [max_nesting: 3]},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

Expand Down
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
line_length: 120,
inputs: ["{mix,.formatter,.credo}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ jobs:
run: |
EDGEDB_VERSION=${EDGEDB_VERSION%%.*}
rm -r "priv/edgedb/schema/migrations/"
rm -r "test/support/schema/migrations/"
for module_file in `ls priv/edgedb/schema/`
for module_file in `ls test/support/schema/`
do
module_version=${module_file%.esdl}
module_version=${module_version#v}
module_version=${module_version%_*}
if test ${EDGEDB_VERSION} -lt ${module_version}
then
module_path="priv/edgedb/schema/${module_file}"
module_path="test/support/schema/${module_file}"
echo "removing ${module_path}"
rm ${module_path}
fi
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ edgedb-*.tar
# dialyzer
priv/plts/

examples/
test/codegen/queries/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `EdgeDB.Object.id/1` to fetch ID from an `EdgeDB.Object` if it was returned from the query.
- `EdgeDB.ConfigMemory.new/1` to create a new instance of `t:EdgeDB.ConfigMemory.t/0`.
- support for `Elixir v1.16`.
- support for generating Elixir modules from EdgeQL queries via `mix edgedb.generate`.
- abitility to pass atoms as valid arguments for enums.

### Changed

- `t:EdgeDB.Object.t/0` to be `opaque`.
- `jason` to be required library, but still configurable.
- `EdgeDB.NamedTuple.to_map/2` to include indexes as keys into result map.

### Fixed

- client state handling in `EdgeDB.with_config/2`/`EdgeDB.without_config/2`,
`EdgeDB.with_globals/2`/`EdgeDB.without_globals/2` and
`EdgeDB.with_module_aliases/2`/`EdgeDB.without_module_aliases/2`.
Expand Down
7 changes: 7 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import Config

import_config("#{Mix.env()}.exs")

config :edgedb,
generation: [
queries_path: "test/support/codegen/edgeql/",
output_path: "test/codegen/queries/",
module_prefix: Tests.Codegen.Queries
]
2 changes: 1 addition & 1 deletion edgedb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
server-version = "4.0"

[project]
schema-dir = "./priv/edgedb/schema"
schema-dir = "./test/support/schema"
37 changes: 22 additions & 15 deletions lib/edgedb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ defmodule EdgeDB do
"""
@type result() :: EdgeDB.Set.t() | term()

@typedoc """
Parameter types acceptable by `EdgeDB.query*/4` functions.
"""
@type params() :: map() | list() | Keyword.t()

@doc """
Creates a pool of EdgeDB connections linked to the current process.
Expand Down Expand Up @@ -307,7 +312,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query(client(), String.t(), list() | Keyword.t(), list(query_option())) ::
@spec query(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query(client, statement, params \\ [], opts \\ []) do
Expand All @@ -317,7 +322,8 @@ defmodule EdgeDB do
output_format: Keyword.get(opts, :output_format, :binary),
required: Keyword.get(opts, :required, false),
is_script: Keyword.get(opts, :script, false),
params: params
params: params,
__file__: opts[:__file__]
}

parse_execute_query(client, q, q.params, opts)
Expand All @@ -332,7 +338,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query!(client(), String.t(), list(), list(query_option())) :: result()
@spec query!(client(), String.t(), params(), list(query_option())) :: result()
def query!(client, statement, params \\ [], opts \\ []) do
client
|> query(statement, params, opts)
Expand All @@ -347,7 +353,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_single(client(), String.t(), list(), list(query_option())) ::
@spec query_single(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query_single(client, statement, params \\ [], opts \\ []) do
Expand All @@ -363,7 +369,8 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_single!(client(), String.t(), list(), list(query_option())) :: result()
@spec query_single!(client(), String.t(), params(), list(query_option())) ::
result()
def query_single!(client, statement, params \\ [], opts \\ []) do
client
|> query_single(statement, params, opts)
Expand All @@ -378,7 +385,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_required_single(client(), String.t(), list(), list(query_option())) ::
@spec query_required_single(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query_required_single(client, statement, params \\ [], opts \\ []) do
Expand All @@ -394,7 +401,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_required_single!(client(), String.t(), list(), list(query_option())) :: result()
@spec query_required_single!(client(), String.t(), params(), list(query_option())) :: result()
def query_required_single!(client, statement, params \\ [], opts \\ []) do
client
|> query_required_single(statement, params, opts)
Expand All @@ -409,7 +416,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_json(client(), String.t(), list(), list(query_option())) ::
@spec query_json(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query_json(client, statement, params \\ [], opts \\ []) do
Expand All @@ -425,7 +432,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_json!(client(), String.t(), list(), list(query_option())) :: result()
@spec query_json!(client(), String.t(), params(), list(query_option())) :: result()
def query_json!(client, statement, params \\ [], opts \\ []) do
client
|> query_json(statement, params, opts)
Expand All @@ -440,7 +447,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_single_json(client(), String.t(), list(), list(query_option())) ::
@spec query_single_json(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query_single_json(client, statement, params \\ [], opts \\ []) do
Expand All @@ -456,7 +463,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_single_json!(client(), String.t(), list(), list(query_option())) :: result()
@spec query_single_json!(client(), String.t(), params(), list(query_option())) :: result()
def query_single_json!(client, statement, params \\ [], opts \\ []) do
client
|> query_single_json(statement, params, opts)
Expand All @@ -471,7 +478,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_required_single_json(client(), String.t(), list(), list(query_option())) ::
@spec query_required_single_json(client(), String.t(), params(), list(query_option())) ::
{:ok, result()}
| {:error, Exception.t()}
def query_required_single_json(client, statement, params \\ [], opts \\ []) do
Expand All @@ -487,7 +494,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec query_required_single_json!(client(), String.t(), list(), list(query_option())) ::
@spec query_required_single_json!(client(), String.t(), params(), list(query_option())) ::
result()
def query_required_single_json!(client, statement, params \\ [], opts \\ []) do
client
Expand All @@ -500,7 +507,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec execute(client(), String.t(), list(), list(query_option())) ::
@spec execute(client(), String.t(), params(), list(query_option())) ::
:ok | {:error, Exception.t()}
def execute(client, statement, params \\ [], opts \\ []) do
opts = Keyword.merge(opts, output_format: :none, script: true, raw: true)
Expand All @@ -521,7 +528,7 @@ defmodule EdgeDB do
See `t:EdgeDB.query_option/0` for supported options.
"""
@spec execute!(client(), String.t(), list(), list(query_option())) :: :ok
@spec execute!(client(), String.t(), params(), list(query_option())) :: :ok
def execute!(client, statement, params \\ [], opts \\ []) do
opts = Keyword.merge(opts, output_format: :none, script: true, raw: true)
query!(client, statement, params, opts)
Expand Down
Loading

0 comments on commit 3cd967d

Please sign in to comment.