mirror of
https://github.com/FlipsideCrypto/livequery-base.git
synced 2026-02-06 11:16:44 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb20f8e47a | ||
|
|
84dc724d7d | ||
|
|
6a45354247 | ||
|
|
732e561c71 | ||
|
|
42c83595f8 |
@ -36,7 +36,7 @@
|
||||
func_type = none
|
||||
) %}
|
||||
CREATE OR REPLACE {{ func_type }} FUNCTION {{ name_ }}(
|
||||
{{- compile_signature(signature) }}
|
||||
{{- livequery_base.compile_signature(signature) }}
|
||||
)
|
||||
COPY GRANTS
|
||||
RETURNS {{ return_type }}
|
||||
@ -45,7 +45,7 @@
|
||||
{% endif %}
|
||||
{%- if api_integration -%}
|
||||
api_integration = {{ api_integration }}
|
||||
AS {{ construct_api_route(sql_) ~ ";" }}
|
||||
AS {{ livequery_base.construct_api_route(sql_) ~ ";" }}
|
||||
{% else -%}
|
||||
AS
|
||||
$$
|
||||
@ -67,7 +67,7 @@
|
||||
{% set func_type = config ["func_type"] %}
|
||||
|
||||
{% if not drop_ -%}
|
||||
{{ create_sql_function(
|
||||
{{ livequery_base.create_sql_function(
|
||||
name_ = name_,
|
||||
signature = signature,
|
||||
return_type = return_type,
|
||||
@ -113,7 +113,7 @@
|
||||
CREATE SCHEMA IF NOT EXISTS {{ schema }};
|
||||
{%- set configs = fromyaml(config_func(blockchain, network)) if network else fromyaml(config_func(schema, blockchain)) -%}
|
||||
{%- for udf in configs -%}
|
||||
{{- create_or_drop_function_from_config(udf, drop_=drop_) -}}
|
||||
{{- livequery_base.create_or_drop_function_from_config(udf, drop_=drop_) -}}
|
||||
{%- endfor -%}
|
||||
{%- endmacro -%}
|
||||
|
||||
@ -147,7 +147,7 @@
|
||||
{% if execute and (var("UPDATE_UDFS_AND_SPS") or var("DROP_UDFS_AND_SPS")) and model.unique_id in selected_resources %}
|
||||
{% set sql %}
|
||||
{% for config in configs %}
|
||||
{{- crud_udfs_by_chain(config, blockchain, network, var("DROP_UDFS_AND_SPS")) -}}
|
||||
{{- livequery_base.crud_udfs_by_chain(config, blockchain, network, var("DROP_UDFS_AND_SPS")) -}}
|
||||
{%- endfor -%}
|
||||
{%- endset -%}
|
||||
{%- if var("DROP_UDFS_AND_SPS") -%}
|
||||
@ -155,7 +155,7 @@
|
||||
{%- else -%}
|
||||
{%- do log("Deploy partner udfs: " ~ this.database ~ "." ~ schema, true) -%}
|
||||
{%- endif -%}
|
||||
{%- do run_query(sql ~ apply_grants_by_schema(schema)) -%}
|
||||
{%- do run_query(sql ~ livequery_base.apply_grants_by_schema(schema)) -%}
|
||||
{%- endif -%}
|
||||
SELECT '{{ model.schema }}' as schema_
|
||||
{%- endmacro -%}
|
||||
|
||||
67
macros/utils/udf_utils/render.sql
Normal file
67
macros/utils/udf_utils/render.sql
Normal file
@ -0,0 +1,67 @@
|
||||
{% macro get_rendered_model(package_name, model_name, schema, blockchain, network) %}
|
||||
{#
|
||||
This macro retrieves and renders a specified model from the graph.
|
||||
|
||||
Args:
|
||||
package_name (str): The name of the package containing the model.
|
||||
model_name (str): The name of the model to be rendered.
|
||||
schema (str): The schema to be used.
|
||||
blockchain (str): The blockchain to be used.
|
||||
network (str): The network to be used.
|
||||
|
||||
Returns:
|
||||
str: The rendered SQL of the specified model.
|
||||
#}
|
||||
{% if execute %}
|
||||
{{ log("=== Starting get_rendered_model ===", info=True) }}
|
||||
{# Use a list to store the node to avoid scope issues #}
|
||||
{%- set nodes = [] -%}
|
||||
{{ log("Looking for node: " ~ package_name ~ "." ~ model_name, info=True) }}
|
||||
{%- for node in graph.nodes.values() -%}
|
||||
{%- if node.package_name == package_name and node.name == model_name -%}
|
||||
{{ log("Found target node: " ~ node.unique_id, info=True) }}
|
||||
{%- do nodes.append(node) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{%- if nodes | length == 0 -%}
|
||||
{{ log("No target node found!", info=True) }}
|
||||
{{ return('') }}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set target_node = nodes[0] -%}
|
||||
{{ log("Processing node: " ~ target_node.unique_id, info=True) }}
|
||||
{{ log("Dependencies:\n\t\t" ~ (target_node.depends_on.nodes | pprint).replace("\n", "\n\t\t"), info=True) }}
|
||||
|
||||
{# First render all dependency CTEs #}
|
||||
{%- set ctes = [] -%}
|
||||
{%- for dep_id in target_node.depends_on.nodes -%}
|
||||
{{ log("Processing dependency: " ~ dep_id, info=True) }}
|
||||
{%- set dep_node = graph.nodes[dep_id] -%}
|
||||
|
||||
{%- set rendered_sql = render(dep_node.raw_code) | trim -%}
|
||||
|
||||
{%- if rendered_sql -%}
|
||||
{%- set cte_sql -%}
|
||||
__dbt__cte__{{ dep_node.name }} AS (
|
||||
{{ rendered_sql }}
|
||||
)
|
||||
{%- endset -%}
|
||||
{%- do ctes.append(cte_sql) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{{ log("Number of CTEs generated: " ~ ctes | length, info=True) }}
|
||||
|
||||
{# Combine CTEs with main query #}
|
||||
{%- set final_sql -%}
|
||||
WITH {{ ctes | join(',\n\n') }}
|
||||
|
||||
{{ render(target_node.raw_code) }}
|
||||
{%- endset -%}
|
||||
|
||||
{{ log("=== End get_rendered_model ===\n\n" , info=True) }}
|
||||
|
||||
{{ return(final_sql) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
Loading…
Reference in New Issue
Block a user