Skip to content

Commit

Permalink
feat: make output of to_sql a proper str subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and cpcloud committed Jul 6, 2023
1 parent 673aab3 commit 084bdb9
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions ibis/expr/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,14 @@ def show_sql(
print(to_sql(expr, dialect=dialect), file=file)


class SQLString:
class SQLString(str):
"""Object to hold a formatted SQL string.
Syntax highlights in Jupyter notebooks.
"""

__slots__ = ("sql",)

def __init__(self, sql: str) -> None:
self.sql = sql

def __repr__(self) -> str:
return f"{self.__class__.__name__}(sql={self.sql!r})"

def __str__(self) -> str:
return self.sql
return f"{self.__class__.__name__}({str(self)!r})"

def _repr_markdown_(self) -> str:
return f"```sql\n{self!s}\n```"
Expand Down

0 comments on commit 084bdb9

Please sign in to comment.