0

I have log data that I wish to manage with js-data (http://www.js-data.io/docs/dsdefaults#idattribute) that has no primary key.

Do I need to generate a key or can js-data be configured to allow access to the data without a pk?

Can I get js-data to generate a pk? I have no need to persist this data, just wanted to use the js-data capabilities to query it.

Example:

  $provide.factory('syslog', ['DS', function(DS) {
    return DS.defineResource({
      name: 'log'
    });
  }]);

  $provide.factory('LoggingServices', ['$q', '$filter', '$log', 'syslog', function($q, $filter, $log, syslog) {

    function injectMockLogs () {
      syslog.inject({
        'messages': [
          {
            'time':'2016-03-29 09:32:43',
            'severity':'INFO',
            'user':'carolyn',
            'auth_type':'RADIUS',
            'method':'UI',
            'event_id':1107,
            'message':'In make_radius_request: Making radius request for user carolyn',
            'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In continue_radius_auth: Starting RADIUS authentication for user carolyn @ 10.217.22.20'
          },{
            'time':'2016-03-29 09:32:44',
            'severity':'INFO',
            'user':'carolyn',
            'auth_type':'RADIUS',
            'method':'UI',
            'event_id':1107,
            'message':'In make_radius_request: Making radius request for user carolyn',
            'full_message':'2016-03-29 09:32:44 "info" ns [1107]: RADIUS auth:In make_radius_request: Making radius request for user carolyn'
          },{...
tarik
  • 312
  • 1
  • 9
  • My current work around is that I'm generating an id before injecting the data. But I don't actually care about or need an id. – tarik Mar 30 '16 at 23:52

1 Answers1

2

In order for data to be injected into the store (which is an Identity Map), the data needs to have some sort of unique identifier. It's okay if you yourself don't need the items to have a primary key, but it is necessary for JSData.

As of 2.9.0, passing the temporary: true option to inject will cause an id to be generated for each of the items being injected, though your current workaround is a fine approach.

jdobry
  • 1,041
  • 6
  • 17
  • The `temporary: true` is exactly the sort of thing I am looking for.. it reduces looping through the data by one pass. I understand why keys are necessary, but processing log data is not uncommon, so having this feature is handy. I am using js-data to manage the data and perform queries. It requires a little less hand coding and is nice to use. Thanks! – tarik Apr 05 '16 at 18:02
  • As a follow up, it turns out the aggregators we are using to send me the log data do apply keys to the data. – tarik May 27 '16 at 17:53