new CuriousClient(curiousUrlnon-null, request, clientDefaultArgsopt, quietopt, camelCaseopt) → {CuriousClient}
Tool for making a curious query and returning parsed objects
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
curiousUrl |
string | The URL of the Curious server. The query is sent to XXX: For compatability with legacy clients, the |
|
request |
function | A function that makes a Any function that meets the signature, makes a |
|
clientDefaultArgs |
Object |
<optional> |
Default parameters to send to the serever with every query performed by this client--see module:curious.CuriousClient#performQuery for an explanation of what each parameter means. |
quiet |
boolean |
<optional> |
Unless true, log every query to the console. |
camelCase |
boolean |
<optional> |
If true, construct camel-cased versions of the JSON objects returned by the Curious server. |
- Source:
Returns:
A client object with a single performQuery method
- Type
- CuriousClient
Namespaces
Methods
(static) performQuery(qnon-null, relationshipsnon-null, constructorsnullable, paramsopt, nullable, existingObjectsopt) → {Promise.<{objects: Array, trees: Array.<?Object>}>}
Perform a Curious query and return back parsed objects.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
q |
string | The query string | |||||||||||||||||||||||||||||||||
relationships |
Array.<string> | The names of relationships between each joined set of objects | |||||||||||||||||||||||||||||||||
constructors |
Array.<?function(Object)> |
<nullable> |
An array of constructors for any custom classes, or null for the default | ||||||||||||||||||||||||||||||||
params |
Object |
<optional> <nullable> |
Query-specific parameters for the request
Properties
|
||||||||||||||||||||||||||||||||
existingObjects |
Array.<Array.<Object>> |
<optional> |
Objects that already exist to be linked into the results returned by this query |
- Source:
Returns:
A promise that resolves to an object containing the objects requested by the query
and a tree structure that relates IDs for recursive queries
- Type
- Promise.<{objects: Array, trees: Array.<?Object>}>
Example
// Here's a many-to-many example
client.performQuery(
'Document(id__in=[1,2]) ?(Document.entities)',
['documents', 'entities'],
).then(function (results) {
console.log(results.objects.documents);
// Will show an array of documents, as CuriousObject instances:
// [
// CuriousObject({
// __model: 'Document',
// __url: 'http://somewhere/document/1',
// id: 1,
// entities: [
// // entities associated with document 1
// ]
// ... other fields of Document objects ...
// }),
// CuriousObject({
// __model: 'Document',
// __url: 'http://somewhere/document/2',
// id: 2,
// entities: [
// // entities associated with document 2
// ]
// ...
// }),
// ]
console.log(results.objects.entities);
// Will show an array of entities, as CuriousObject instances:
// [
// CuriousObject({
// __model: 'Entity',
// __url: 'http://somewhere/entity/1',
// id: 2348,
// documents: [
// // documents associated with entity 1
// ]
// ... other fields of Entity objects ...
// }),
// CuriousObject({
// __model: 'Entity',
// __url: 'http://somewhere/entity/2',
// id: 2725,
// documents: [
// // documents associated with entity 2
// ]
// ...
// }),
// ]
});