Module: query.py¶
- Author:
Stefan Eletzhofer
- Date:
2012-05-18
Abstract¶
This module offers functions to query for business objects.
Usage Example¶
Query for documents:
>>> from nexiles.tools.api import get_api
>>> from nexiles.tools.api.query import query
>>> api = get_api(...)
>>> query(api, type="document", name="*.doc", limit=10)
Query for different types – see also Resources:
>>> query(api, type="epmdocument", name="nx*.asm", limit=100)
>>> query(api, type="product", name="offer*")
>>> query(api, type="part", number="1030*45")
>>> query(api, type="organization")
>>> query(api, type="user")
See also Tutorial: Performing Queries in the Tutorial.
Supported Queries¶
- API VERSION:
The since version column specifies the version of the nexiles.tools needed to perform the query.
parameter |
meaning |
since version |
example |
default |
---|---|---|---|---|
number |
query for a object number |
1.0 |
query(api, type=”product”, number=”1234”) |
none |
name |
query for objects named |
1.0 |
query(api, type=”part”, name=”holder_17.prt”) |
none |
cadname |
query for object cadname |
1.1 |
query(api, type=”epmdocument”, cadname=”HOLDER_17.PRT”) |
none |
description |
query for description |
1.0 |
query(api, type=”product”, description=”Wagon Big #1234”) |
none |
state |
query for lifecycle state |
1.1 |
query(api, type=”epmdocument”, state=”RELEASED”) |
none |
limit |
limit the query result set |
1.0 |
query(api, type=”epmdocument”, limit=100) |
none |
latest |
only return the latest objects |
1.0 |
query(api, type=”epmdocument”, latest=False) |
True |
workspace |
specify a workspace name |
1.2dev |
query(api, type=”epmdocument”, workspace=”FOO WS”) |
none |
creator |
specify the creator user name |
1.2dev |
query(api, type=”part”, creator=”orgadmin”) |
none |
modifier |
specify the modifier user name |
1.2dev |
query(api, type=”document”, modifier=”fred”) |
none |
principal |
specify the principal name |
1.2dev |
query(api, type=”workspace”, principal=”fred”) |
none |
Note
the ‘description’ is not available for all business objects.
Note
the ‘cadname’ is only available for EPMDocument types.
Note
the ‘latest’, ‘creator’, ‘modifier’ filters are only allowed for iterable types.
All the above queries may be mixed.
String query notes¶
All queries for strings are done case insensitive.
All queries for strings may contain wild cards.
Module Documentation¶
- nexiles.tools.api.query.query(api, type, ...) result ¶
Perform a query.
- Parameters:
api – The resource – see
nexiles.tools.api.get_api()
type – The resource type string – see Resources
- Returns:
query result
- nexiles.tools.api.query.query_one(api, type, ...) result ¶
Perform a query, return only one result.
This function uses
nexiles.tools.api.query()
internally. It sorts the result set returned by that function using the given function as the key argument for the python sorted() builtin.The default key function used is one that sorts the results by sequence numbers – i.e. the number pert of the OID. Please note that this might be considered as a hack.
Note
The first element of the result set after sorting is returned.
- Parameters:
api – The resource – see
nexiles.tools.api.get_api()
type – The resource type string – see Resources
key_func – The key function to use for the sort.
kw – The query arguments
- Returns:
query result