diff --git a/fastapi_esql/__init__.py b/fastapi_esql/__init__.py index b75d298..7d0cd54 100644 --- a/fastapi_esql/__init__.py +++ b/fastapi_esql/__init__.py @@ -1,5 +1,6 @@ from logging.config import dictConfig +from tortoise.converters import escape_string from tortoise.queryset import Q from .const import ( @@ -36,6 +37,7 @@ "SQLizer", "Singleton", "convert_dicts", + "escape_string", "timing", ] diff --git a/tests/test_converter.py b/tests/test_converter.py index e6e0eff..ba7ccad 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -2,7 +2,7 @@ from json import loads from unittest import TestCase -from fastapi_esql import convert_dicts +from fastapi_esql import convert_dicts, escape_string class TestConvertDicts(TestCase): @@ -23,3 +23,11 @@ def test_wrong_converter(self): dicts = deepcopy(self.dicts) convert_dicts(dicts, {"value": int}) assert dicts == [{"id": 1, "value": 1}, {"id": 2, "value": '{"k": [true, null]}'}] + + +class TestEscapeString(TestCase): + + def test_normal(self): + assert escape_string("'") == "\\'" + assert escape_string('"') == '\\"' + assert escape_string('\\') == '\\\\'