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

Support using the “schema” tag to define API Schema #158

Open
kokokuo opened this issue Apr 6, 2023 · 0 comments
Open

Support using the “schema” tag to define API Schema #158

kokokuo opened this issue Apr 6, 2023 · 0 comments

Comments

@kokokuo
Copy link
Contributor

kokokuo commented Apr 6, 2023

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 %}

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant