vulcan-sql
vulcan-sql copied to clipboard
Support using the “schema” tag to define API Schema
What’s the problem you're trying to solve
In the previous, users should define the SQL query file mapped API spec including URL, request parameter, data source profile name, or cache feature, they should define in YAML format, but when YAML content is longer, it is not easy to read and define, so there are a lot of articles share don't use YAML.
Describe the solution you’d like
Otherwise, we also hope to decrease more config files, so we decide to define a tag {% schema set(...) %} and put all API schema config in the set(...) function by js object.
{% schema set({
urlPath: "/artist/:id"
request: [{
fieldName: id
fieldIn: path
description: constituent id
validators: [required]
}],
profiles: ["pg"]
cache: {
product: { sql: "select * from product"},
order: {
sql: "select * from order",
# optional
refreshTime: "5m",
# optional
refreshExpression: {
expression: "MAX(created_at)"
every: "5m"
}
# optional
index: {
idx_a: 'col_a'
idx_b: 'col_b'
}
}
}
}) %}
-- SQL
# The cache scope means the SQL statement will send the query to duckDB cache data source
{% cache %}
select * from order
where type = {{ context.params.type }}
and where exists (
select * from product where price >= {{ context.params.price }}
and order.product_id = product.id
)
{% endcache %}