Skip to content

Commit b157b8a

Browse files
committed
♻️ clean: move multiple strip funcs to trim.
1 parent 22d6f4a commit b157b8a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/sqlplate/sqlplate.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import annotations
77

88
from pathlib import Path
9-
from typing import Any, Iterator, Optional
9+
from typing import Any, Iterator, Optional, Callable
1010

1111
from jinja2 import Template
1212

@@ -15,6 +15,9 @@
1515
from .utils import get_env, remove_sql_comment
1616

1717

18+
trim: Callable[[str], str] = lambda x: x.strip().strip('\n')
19+
20+
1821
class SQLPlate:
1922
"""A SQLPlate object for render any SQL template that prepare by Jinja
2023
template.
@@ -100,17 +103,15 @@ def load(self, remove_comment: bool = False, **kwargs) -> str:
100103
"Template object does not create before load, you should use "
101104
"`.template(name=?)`."
102105
)
103-
render: str = (
106+
render: str = trim(
104107
self._template.render(
105108
**(
106109
{"_system": self.name, "_template": self._template_name}
107110
| config().export(self._template_type)
108111
| self._option
109112
| kwargs
110-
)
113+
),
111114
)
112-
.strip()
113-
.strip('\n')
114115
)
115116
if remove_comment:
116117
return remove_sql_comment(render)
@@ -130,10 +131,10 @@ def stream(
130131
statement. Default is ';'.
131132
"""
132133
yield from (
133-
s.strip().strip('\n')
134+
trim(s)
134135
for s in (
135136
self.load(remove_comment=remove_comment, **kwargs)
136137
.split(split_char)
137138
)
138-
if s.strip().strip('\n') != ''
139+
if trim(s) != ''
139140
)

tests/test_databricks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def test_sql_full_dump(template_path):
259259
.option('query', 'SELECT * FROM catalog-name.schema-name.source-name')
260260
.load()
261261
)
262-
print(prepare(statement))
263262
assert prepare(statement) == dedent("""
264263
DELETE FROM catalog-name.schema-name.table-name
265264
WHERE load_src = 'SOURCE_FOO'

0 commit comments

Comments
 (0)