MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_query

Method test_query

test/ext/test_indexable.py:288–310  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

286 subfield = json_property("other", "field", Text)
287
288 def test_query(self):
289 Json = self.classes.Json
290 s = Session(testing.db)
291
292 s.add_all([Json(), Json(json={"field": 10}), Json(json={"field": 20})])
293 s.commit()
294
295 a1 = (
296 s.query(Json)
297 .filter(Json.json["field"].astext.cast(Integer) == 10)
298 .one()
299 )
300 a2 = s.query(Json).filter(Json.field.astext == "10").one()
301 eq_(a1.id, a2.id)
302 a3 = s.query(Json).filter(Json.field.astext == "20").one()
303 ne_(a1.id, a3.id)
304
305 a4 = s.query(Json).filter(Json.json_field.astext == "10").one()
306 eq_(a2.id, a4.id)
307 a5 = s.query(Json).filter(Json.int_field == 10).one()
308 eq_(a2.id, a5.id)
309 a6 = s.query(Json).filter(Json.text_field == "10").one()
310 eq_(a2.id, a6.id)
311
312 def test_mutable(self):
313 Json = self.classes.Json

Callers

nothing calls this directly

Calls 10

add_allMethod · 0.95
commitMethod · 0.95
queryMethod · 0.95
SessionClass · 0.90
eq_Function · 0.90
ne_Function · 0.90
JsonClass · 0.85
oneMethod · 0.45
filterMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected