DbService

DbService is a PalmService with some handy features:

  • dbKind is a published property of DbService, so "putKind" can omit "id" and "find" can omit "from".
  • Setting the inherited subscribe property also sets watch: true on "find" and "search" requests.

Use DbService like most PalmServices:

{name: "findDoodads", kind: "DbService", dbKind: "com.palm.doodad:1",
  method: "find", onSuccess: "gotDoodads"}

To call the service:

this.$.findDoodads.call({
  query: {
      // notice that 'from' is not needed since 'dbKind' is in the component
      where: [...],
      orderBy: "name",
      limit: 10
  }
});

Grouping DbServices

Rather than declaring a bunch of similar services like this...

{
  name: "findRecentContacts", kind: "DbService",
  dbKind: "com.palm.contact:1", method: "find",
  onSuccess: "handleRecentContacts", onFailure: "genericFailure"
},
{
  name: "putContact", kind: "DbService",
  dbKind: "com.palm.contact:1", method: "put",
  onSuccess: "handlePutContact", onFailure: "genericFailure"
},
{
  name: "mergeContact", kind: "DbService",
  dbKind: "com.palm.contact:1", method: "merge",
  onSuccess: "handleMergeContact", onFailure: "genericFailure"
}

...it's easier to introduce a parent DbService component in the hierarchy to house the boilerplate:

{
  kind: "DbService", dbKind: "com.palm.contact:1", onFailure: "genericFailure",
  components: [
      {name: "findRecentContacts", method: "find",
          onSuccess: "handleRecentContacts"},
      {name: "putContact", method: "put", onSuccess: "handlePutContact"},
      {name: "mergeContact", method: "merge",
          onSuccess: "handleMergeContact"}
  ]
}

This pattern is most useful for multiple related DbService components. The child components inherit the kind, dbKind, onSuccess, and onFailure properties.

Published Properties

Name Default Description
dbkind "" The db8 kind for this store
recallWatches false If true, DbService will refresh a query immediately when its watch fires.
resubscribe true If true, after a service failure, DbService will automatically attempt to resubscribe using the same parameters.

Published Events

Name Default Description
onWatch "" Set a handler for this event if you want to implement custom watch behavior--e.g., onWatch: "myHandler".