MCPcopy Create free account
hub / github.com/piccolo-orm/piccolo / __str__

Method __str__

piccolo/querystring.py:136–165  ·  view source on GitHub ↗

The SQL returned by the ``__str__`` method isn't used directly in queries - it's just a usability feature.

(self)

Source from the content-addressed store, hash-verified

134 return self
135
136 def __str__(self):
137 """
138 The SQL returned by the ``__str__`` method isn't used directly in
139 queries - it's just a usability feature.
140 """
141 _, bundled, combined_args = self.bundle(
142 start_index=1, bundled=[], combined_args=[]
143 )
144 template = "".join(
145 fragment.prefix + ("" if fragment.no_arg else "{}")
146 for fragment in bundled
147 )
148
149 # Do some basic type conversion here.
150 converted_args = []
151 for arg in combined_args:
152 _type = type(arg)
153 if _type == str:
154 converted_args.append(f"'{arg}'")
155 elif _type == datetime:
156 dt_string = arg.isoformat()
157 converted_args.append(f"'{dt_string}'")
158 elif _type == UUID or _type == apgUUID:
159 converted_args.append(f"'{arg}'")
160 elif arg is None:
161 converted_args.append("null")
162 else:
163 converted_args.append(arg)
164
165 return template.format(*converted_args)
166
167 def bundle(
168 self,

Callers

nothing calls this directly

Calls 2

bundleMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected