| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -3,3 +3,4 @@ branch = False | |
| source = datajoint | ||
|
|
||
| [report] | ||
| show_missing = True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -193,15 +193,15 @@ def restrict_in_place(self, restriction): | |
|
|
||
| def __and__(self, restriction): | ||
| """ | ||
| Restriction operator | ||
| Restriction operator e.g. q1 & q2. | ||
| :return: a restricted copy of the input argument | ||
| See QueryExpression.restrict for more detail. | ||
| """ | ||
| return self.restrict(restriction) | ||
|
|
||
| def __xor__(self, restriction): | ||
| """ | ||
| Restriction operator ignoring compatibility check. | ||
| Permissive restriction operator ignoring compatibility check e.g. q1 ^ q2. | ||
| """ | ||
| if inspect.isclass(restriction) and issubclass(restriction, QueryExpression): | ||
| restriction = restriction() | ||
| Expand All | @@ -211,22 +211,33 @@ def __xor__(self, restriction): | |
|
|
||
| def __sub__(self, restriction): | ||
| """ | ||
| Inverted restriction | ||
| Inverted restriction e.g. q1 - q2. | ||
| :return: a restricted copy of the input argument | ||
| See QueryExpression.restrict for more detail. | ||
| """ | ||
| return self.restrict(Not(restriction)) | ||
|
|
||
| def __neg__(self): | ||
| """ | ||
| Convert between restriction and inverted restriction e.g. -q1. | ||
| :return: target restriction | ||
| See QueryExpression.restrict for more detail. | ||
| """ | ||
| if isinstance(self, Not): | ||
| return self.restriction | ||
| return Not(self) | ||
|
|
||
| def __mul__(self, other): | ||
| """ join of query expressions `self` and `other` """ | ||
| """ | ||
| join of query expressions `self` and `other` e.g. q1 * q2. | ||
| """ | ||
| return self.join(other) | ||
|
|
||
| def __matmul__(self, other): | ||
| """ | ||
| Permissive join of query expressions `self` and `other` ignoring compatibility check | ||
| e.g. q1 @ q2. | ||
| """ | ||
| if inspect.isclass(other) and issubclass(other, QueryExpression): | ||
| other = other() # instantiate | ||
| return self.join(other, semantic_check=False) | ||
| Expand Down Expand Up | @@ -271,7 +282,7 @@ def join(self, other, semantic_check=True, left=False): | |
| return result | ||
|
|
||
| def __add__(self, other): | ||
| """union""" | ||
| """union e.g. q1 + q2.""" | ||
| return Union.create(self, other) | ||
|
|
||
| def proj(self, *attributes, **named_attributes): | ||
| Expand Down Expand Up | @@ -424,7 +435,7 @@ def tail(self, limit=25, **fetch_kwargs): | |
| return self.fetch(order_by="KEY DESC", limit=limit, **fetch_kwargs)[::-1] | ||
|
|
||
| def __len__(self): | ||
| """ :return: number of elements in the result set """ | ||
| """:return: number of elements in the result set e.g. len(q1).""" | ||
| return self.connection.query( | ||
| 'SELECT count(DISTINCT {fields}) FROM {from_}{where}'.format( | ||
| fields=self.heading.as_sql(self.primary_key, include_aliases=False), | ||
| Expand All | @@ -433,7 +444,8 @@ def __len__(self): | |
|
|
||
| def __bool__(self): | ||
| """ | ||
| :return: True if the result is not empty. Equivalent to len(self) > 0 but often faster. | ||
| :return: True if the result is not empty. Equivalent to len(self) > 0 but often | ||
| faster e.g. bool(q1). | ||
| """ | ||
| return bool(self.connection.query( | ||
| 'SELECT EXISTS(SELECT 1 FROM {from_}{where})'.format( | ||
| Expand All | @@ -442,19 +454,30 @@ def __bool__(self): | |
|
|
||
| def __contains__(self, item): | ||
| """ | ||
| returns True if item is found in the . | ||
| returns True if a restriction results with any records e.g. restriction in q1. | ||
| :param item: any restriction | ||
| (item in query_expression) is equivalent to bool(query_expression & item) but may be | ||
| executed more efficiently. | ||
| """ | ||
| return bool(self & item) # May be optimized e.g. using an EXISTS query | ||
|
|
||
| def __iter__(self): | ||
| """ | ||
| returns an iterator-compatible QueryExpression object e.g. iter(q1). | ||
|
|
||
| :param self: iterator-compatible QueryExpression object | ||
| """ | ||
| self._iter_only_key = all(v.in_key for v in self.heading.attributes.values()) | ||
| self._iter_keys = self.fetch('KEY') | ||
| return self | ||
|
|
||
| def __next__(self): | ||
| """ | ||
| returns the next record on an iterator-compatible QueryExpression object | ||
| e.g. next(q1). | ||
|
|
||
| :param self: fetch1 record | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHere self is a QueryExpression that has been primed with iter to yield dicts containing the primary key values.
Sorry, something went wrong.
All reactions
|
||
| """ | ||
| try: | ||
| key = self._iter_keys.pop(0) | ||
| except AttributeError: | ||
| Expand Down Expand Up | @@ -490,6 +513,11 @@ def cursor(self, offset=0, limit=None, order_by=None, as_dict=False): | |
| return self.connection.query(sql, as_dict=as_dict) | ||
|
|
||
| def __repr__(self): | ||
| """ | ||
| returns the string representation of a QueryExpression object e.g. str(q1). | ||
|
|
||
| :param self: String version of query result | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHere self is a QueryExpression.
Sorry, something went wrong.
All reactions
|
||
| """ | ||
| return super().__repr__() if config['loglevel'].lower() == 'debug' else self.preview() | ||
|
|
||
| def preview(self, limit=None, width=None): | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| __version__ = "0.13.dev7" | ||
| __version__ = "0.13.0" | ||
|
|
||
| assert len(__version__) <= 10 # The log table limits version to the 10 characters |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # with record as a dict specifying the primary and | ||
| # secondary attribute values | ||
| table.update1(record) | ||
|
|
||
| # update value in record with id as primary key | ||
| table.update1({'id': 1, 'value': 3}) | ||
|
|
||
| # reset value to default with id as primary key | ||
| table.update1({'id': 1, 'value': None}) | ||
| ## OR | ||
| table.update1({'id': 1}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # set the query cache path | ||
| dj.config['query_cache'] = os.path.expanduser('~/dj_query_cache') | ||
|
|
||
| # access the active connection object for the tables | ||
| conn = dj.conn() # if queries co-located with tables | ||
| conn = module.schema.connection # if schema co-located with tables | ||
| conn = module.table.connection # most flexible | ||
|
|
||
| # activate query caching for a namespace called 'main' | ||
| conn.set_query_cache(query_cache='main') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # deactivate query caching | ||
| conn.set_query_cache(query_cache=None) | ||
| ## OR | ||
| conn.set_query_cache() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| # purged the cached queries | ||
| conn.purge_query_cache() | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "comm_version": "v0.1" | ||
| "comm_version": "v0.2" | ||
| } |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualitySorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.