946
edits
(→API) |
|||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 56: | Line 56: | ||
Currently, the store uses transactions internally to add each person (because data is split up over multiple tables), so there is no public API for dealing with database transactions. In the future, we may add this functionality. | Currently, the store uses transactions internally to add each person (because data is split up over multiple tables), so there is no public API for dealing with database transactions. In the future, we may add this functionality. | ||
The object to pass in to <tt>add</tt> and <tt>update</tt> and returned by <tt>find</tt> look like | The object to pass in to <tt>add</tt> and <tt>update</tt> and returned by <tt>find</tt> look like the sample below. Currently, by default, we're storing a single [http://portablecontacts.net/draft-spec.html#schema Portable Contacts object] within the wrapper object. Note that the schema for the 'default' document is contained in the <tt>default</tt> property of <tt>documentSchemas</tt>. Be sure to verify the schema string, as the People store will not enforce adherence to Portable Contacts or any other schema. | ||
<pre> | <pre> | ||
// People object | |||
{ | { | ||
// guid identifies this person, schema describes the wrapper object | |||
guid: "af24d-fe488-ab748-b947f", | guid: "af24d-fe488-ab748-b947f", | ||
schema: "http://mozilla.com/schemas/people/1", | schema: "http://labs.mozilla.com/schemas/people/1", | ||
// we pull out some fields for convenience. | |||
// we only index fields we pull out. | |||
displayName: "the foobinator", | |||
givenName: "foo", | |||
familyName: "bar", | |||
documents: | documents: { | ||
{ | default: { | ||
displayName: "the foobinator", | |||
name{ | |||
givenName: "foo", | |||
familyName: "bar" | |||
}, | |||
emails: [ | emails: [ | ||
{value: "foo@gmail.com"}, | {value: "foo@gmail.com", type: "home"}, | ||
{value: "foo@yahoo.com"}, | {value: "foo@yahoo.com", type: "work"}, | ||
{value: "bar@yahoo.com"} | {value: "bar@yahoo.com", type: "other"} | ||
] | ] | ||
} | } | ||
}, | |||
documentSchemas: { | |||
default: "http://portablecontacts.net/draft-spec.html" | |||
} | |||
} | } | ||
</pre> | </pre> | ||
=== Notifications === | |||
Notifications will be sent for modifications to the people storage such as adding a new person. The subject of the notification is usually the GUID of the item. The following list shows the function and the notification topic sent with the subject data. | |||
<pre> | |||
add: "people-add" (guid) | |||
update: "people-update" (guid) | |||
remove: "people-before-remove" (guid) | |||
remove: "people-remove" (guid) | |||
changeGUID: "people-guid-change" ({ from: from, to: to }) | |||
</pre> | |||
The notification for remove will notify first before removing the item and afterwards, so listeners of people-before-remove can still get the item before it disappears. | |||
If there are multiple items removed from a single remove call, each item will have its own notification. | |||
== Performance == | == Performance == | ||
edits