41 from copy import copy |
41 from copy import copy |
42 from contextlib import contextmanager |
42 from contextlib import contextmanager |
43 |
43 |
44 from six import PY2, text_type |
44 from six import PY2, text_type |
45 |
45 |
46 from logilab.common.deprecation import deprecated |
|
47 from logilab.common.decorators import cached, clear_cache |
46 from logilab.common.decorators import cached, clear_cache |
48 |
47 |
49 from yams.buildobjs import EntityType |
48 from yams.buildobjs import EntityType |
50 from yams.constraints import SizeConstraint |
49 from yams.constraints import SizeConstraint |
51 from yams.schema import RelationDefinitionSchema |
50 from yams.schema import RelationDefinitionSchema |
1383 |
1382 |
1384 def cmd_find(self, etype, **kwargs): |
1383 def cmd_find(self, etype, **kwargs): |
1385 """find entities of the given type and attribute values""" |
1384 """find entities of the given type and attribute values""" |
1386 return self.cnx.find(etype, **kwargs) |
1385 return self.cnx.find(etype, **kwargs) |
1387 |
1386 |
1388 @deprecated("[3.19] use find(*args, **kwargs).entities() instead") |
|
1389 def cmd_find_entities(self, etype, **kwargs): |
|
1390 """find entities of the given type and attribute values""" |
|
1391 return self.cnx.find(etype, **kwargs).entities() |
|
1392 |
|
1393 @deprecated("[3.19] use find(*args, **kwargs).one() instead") |
|
1394 def cmd_find_one_entity(self, etype, **kwargs): |
|
1395 """find one entity of the given type and attribute values. |
|
1396 |
|
1397 raise :exc:`cubicweb.req.FindEntityError` if can not return one and only |
|
1398 one entity. |
|
1399 """ |
|
1400 return self.cnx.find(etype, **kwargs).one() |
|
1401 |
|
1402 def cmd_update_etype_fti_weight(self, etype, weight): |
1387 def cmd_update_etype_fti_weight(self, etype, weight): |
1403 if self.repo.system_source.dbdriver == 'postgres': |
1388 if self.repo.system_source.dbdriver == 'postgres': |
1404 self.sqlexec('UPDATE appears SET weight=%(weight)s ' |
1389 self.sqlexec('UPDATE appears SET weight=%(weight)s ' |
1405 'FROM entities as X ' |
1390 'FROM entities as X ' |
1406 'WHERE X.eid=appears.uid AND X.type=%(type)s', |
1391 'WHERE X.eid=appears.uid AND X.type=%(type)s', |
1546 for sql in rschema2sql(self.repo.schema.rschema(rtype)): |
1531 for sql in rschema2sql(self.repo.schema.rschema(rtype)): |
1547 self.sqlexec(sql) |
1532 self.sqlexec(sql) |
1548 if commit: |
1533 if commit: |
1549 self.commit() |
1534 self.commit() |
1550 |
1535 |
1551 @deprecated("[3.15] use rename_relation_type(oldname, newname)") |
|
1552 def cmd_rename_relation(self, oldname, newname, commit=True): |
|
1553 self.cmd_rename_relation_type(oldname, newname, commit) |
|
1554 |
|
1555 |
1536 |
1556 class ForRqlIterator: |
1537 class ForRqlIterator: |
1557 """specific rql iterator to make the loop skipable""" |
1538 """specific rql iterator to make the loop skipable""" |
1558 def __init__(self, helper, rql, kwargs, ask_confirm): |
1539 def __init__(self, helper, rql, kwargs, ask_confirm): |
1559 self._h = helper |
1540 self._h = helper |