Skip to content

Commit ffba6eb

Browse files
use lazyLock
1 parent e4bb946 commit ffba6eb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/pg_treesitter_queries/src/queries/relations.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::sync::LazyLock;
2+
13
use crate::{Query, QueryResult};
24

35
use super::QueryTryFrom;
46

5-
static QUERY: &'static str = r#"
7+
static TS_QUERY: LazyLock<tree_sitter::Query> = LazyLock::new(|| {
8+
static QUERY_STR: &'static str = r#"
69
(relation
710
(object_reference
811
.
@@ -12,6 +15,8 @@ static QUERY: &'static str = r#"
1215
)+
1316
)
1417
"#;
18+
tree_sitter::Query::new(tree_sitter_sql::language(), &QUERY_STR).expect("Invalid TS Query")
19+
});
1520

1621
#[derive(Debug)]
1722
pub struct RelationMatch<'a> {
@@ -57,12 +62,9 @@ impl<'a> QueryTryFrom<'a> for RelationMatch<'a> {
5762

5863
impl<'a> Query<'a> for RelationMatch<'a> {
5964
fn execute(root_node: tree_sitter::Node<'a>, stmt: &'a str) -> Vec<crate::QueryResult<'a>> {
60-
let query =
61-
tree_sitter::Query::new(tree_sitter_sql::language(), &QUERY).expect("Invalid Query.");
62-
6365
let mut cursor = tree_sitter::QueryCursor::new();
6466

65-
let matches = cursor.matches(&query, root_node, stmt.as_bytes());
67+
let matches = cursor.matches(&TS_QUERY, root_node, stmt.as_bytes());
6668

6769
let mut to_return = vec![];
6870

0 commit comments

Comments
 (0)