Skip to content

Commit

Permalink
add docstring for SQLVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaykm committed Nov 15, 2023
1 parent 9c4f3c7 commit 8d32740
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/utils/sql.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""
"""
module SQL

import ..ASTWalker: Visitor, walk, before, visit, after
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 8d32740

Please sign in to comment.