SQLSegmenter#

class langchain_community.document_loaders.parsers.language.sql.SQLSegmenter(code: str)[source]#

Code segmenter for SQL. This class uses Tree-sitter to segment SQL code into its constituent statements (e.g., SELECT, CREATE TABLE). It also provides functionality to extract these statements and simplify the code into commented descriptions.

Methods

__init__(code)

extract_functions_classes()

Extract SQL statements from the code.

get_chunk_query()

Return the Tree-sitter query for SQL segmentation.

get_language()

Return the SQL language grammar for Tree-sitter.

get_parser()

is_valid()

make_line_comment(text)

Create a line comment in SQL style.

simplify_code()

Simplify the extracted SQL code into comments.

Parameters:

code (str)

__init__(code: str)#
Parameters:

code (str)

extract_functions_classes() list[str][source]#

Extract SQL statements from the code. Ensures that all SQL statements end with a semicolon for consistency.

Return type:

list[str]

get_chunk_query() str[source]#

Return the Tree-sitter query for SQL segmentation.

Return type:

str

get_language() Language[source]#

Return the SQL language grammar for Tree-sitter.

Return type:

Language

get_parser() Parser#
Return type:

Parser

is_valid() bool#
Return type:

bool

make_line_comment(text: str) str[source]#

Create a line comment in SQL style.

Parameters:

text (str)

Return type:

str

simplify_code() str[source]#

Simplify the extracted SQL code into comments. Converts SQL statements into commented descriptions for easy readability.

Return type:

str