/
core.ex
42 lines (35 loc) · 952 Bytes
/
core.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
defmodule AyeSQL.Core do
@moduledoc """
This module defines the core functionality for AyeSQL.
"""
alias AyeSQL.AST
alias AyeSQL.AST.Context
alias AyeSQL.Error
alias AyeSQL.Query
@typedoc """
AyeSQL query parameter name.
"""
@type parameter_name :: atom()
@typedoc """
AyeSQL query parameters.
"""
@type parameters :: map() | keyword()
@typedoc """
AyeSQL query options.
"""
@type options :: keyword()
##########################
# Query evaluation helpers
# Evaluates the functions.
@doc false
@spec evaluate([AST.expand_function()], parameters(), Context.t()) ::
{:ok, Query.t()} | {:error, Error.t()}
def evaluate(functions, params, context)
def evaluate([], _params, %Context{} = context) do
Context.to_query(context)
end
def evaluate([fun | funs], params, %Context{} = context) do
new_context = fun.(context, params)
evaluate(funs, params, new_context)
end
end