Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdgeQL to Elixir generation #170

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 @@ -64,15 +64,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/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[Compare with 0.7.0](https://github.com/edgedb/edgedb-elixir/compare/v0.7.0...HEAD)

### Added

- support for generating Elixir modules from EdgeQL queries via `mix edgedb.generate`.
- abitility to pass atoms as valid arguments for enums.

### Changed

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

## [0.7.0] - 2024-05-05

[Compare with 0.6.1](https://github.com/edgedb/edgedb-elixir/compare/v0.6.1...v0.7.0)
Expand All @@ -30,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- the behavior of injecting an implicit `:id` field into objects so that this no longer happens.

### 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
8 changes: 8 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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,
atomize_enums: true
]
4 changes: 2 additions & 2 deletions edgedb.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[edgedb]
server-version = "5.2"
server-version = "5.4"

[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 @@ -178,6 +178,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 @@ -308,7 +313,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 @@ -318,7 +323,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 @@ -333,7 +339,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 @@ -348,7 +354,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 @@ -364,7 +370,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 @@ -379,7 +386,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 @@ -395,7 +402,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 @@ -410,7 +417,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 @@ -426,7 +433,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 @@ -441,7 +448,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 @@ -457,7 +464,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 @@ -472,7 +479,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 @@ -488,7 +495,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 @@ -501,7 +508,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 @@ -522,7 +529,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
Loading