From 8d32740eb21de9df1456429a4cbf2801a98318f3 Mon Sep 17 00:00:00 2001 From: tan Date: Wed, 15 Nov 2023 11:36:39 +0530 Subject: [PATCH] add docstring for SQLVisitor --- src/utils/sql.jl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/utils/sql.jl b/src/utils/sql.jl index dca638b..43b6c2d 100644 --- a/src/utils/sql.jl +++ b/src/utils/sql.jl @@ -1,5 +1,3 @@ -""" -""" module SQL import ..ASTWalker: Visitor, walk, before, visit, after @@ -52,6 +50,23 @@ const SQL_OP_MAP = Dict{String,String}( const VALID_SQL_OPS = Set(keys(SQL_OP_MAP)) +""" + SQLVisitor + +Visitor that converts an OPA partial compile AST to a SQL condition. + +It requires two dictionaries to be passed in the constructor: +- `schema_map`: maps OPA package names to database schema names +- `table_map`: maps OPA rule names to database table names + +Input to the visitor must be a partial compile result from OPA already converted to a julia representation using `ASTWalker.AST.ASTVisitor`. +Walking the AST using this visitor will result in a SQL condition that can be appended to a SQL query using a `where` clause. +Output, that is returned from the `walk` method, is an `AbstractSQLCondition`. It can be one of: + +- `SQLCondition`: represents a SQL condition. Contains the SQL string that represents the condition that can be used in the query with a "where" clause. +- `UnconditionalInclude`: represents an unconditional include condition. Which means that the SQL query should return all rows. +- `UnconditionalExclude`: represents an unconditional exclude condition. Which means that the SQL query should not return any rows. +""" struct SQLVisitor <: Visitor schema_map::Dict{String, String} table_map::Dict{String, String}