Skip to content

Commit

Permalink
remove snakecase in favour of simpler transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Payne committed Jan 24, 2023
1 parent 1ee4c4a commit d5b2b8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions singer_sdk/sinks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from singer_sdk.connectors import SQLConnector
from singer_sdk.exceptions import ConformedNameClashException
from singer_sdk.helpers._conformers import replace_leading_digit, snakecase
from singer_sdk.helpers._conformers import replace_leading_digit
from singer_sdk.plugin_base import PluginBase
from singer_sdk.sinks.batch import BatchSink

Expand Down Expand Up @@ -150,10 +150,18 @@ def conform_name(self, name: str, object_type: Optional[str] = None) -> str:
Returns:
The name transformed to snake case.
"""
# strip non-alphanumeric characters, keeping - . _ and spaces
# strip non-alphanumeric characters
name = re.sub(r"[^a-zA-Z0-9_\-\.\s]", "", name)
# convert to snakecase
name = snakecase(name)
# strip leading/trailing whitespace,
# transform to lowercase and replace - . and spaces to _
name = (
name.lower()
.lstrip()
.rstrip()
.replace(".", "_")
.replace("-", "_")
.replace(" ", "_")
)
# replace leading digit
return replace_leading_digit(name)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ def test_hostile_to_sqlite(
columns = {res[0] for res in cursor.fetchall()}
assert columns == {
"name_with_spaces",
"name_is_camel_case",
"nameiscamelcase",
"name_with_dashes",
"name_with_dashes_and_mixed_cases",
"gname_starts_with_number",
"fname_starts_with_number",
"hname_starts_with_number",
"name_with_emoji",
"name_with_emoji_",
}

0 comments on commit d5b2b8b

Please sign in to comment.