code: def create(self, cls, record, user='undefined'):
          
          self.validate_record(cls, record)
          record[CREATION_DATE] = record[UPDATE_DATE] = self.nowstr()
          record[CREATOR] = record[UPDATER] = user
          try:
              return self.db.insert(cls, record)
          except (psycopg2.IntegrityError, psycopg2.ProgrammingError,
                  psycopg2.DataError) as error:
              logging.warning("{} {}: {}".format(
                  error.__class__.__name__,
                  psycopg2.errorcodes.lookup(error.pgcode), error.pgerror))
              if error.pgcode == psycopg2.errorcodes.UNIQUE_VIOLATION:
                  raise KeyError('There is already a record for {}/{}'.format(
                      cls, record[ID]))
              elif error.pgcode == psycopg2.errorcodes.UNDEFINED_COLUMN:
                  raise ValueError('Undefined field')
              else:
                  raise ValueError('Bad record ({})'.format(
                      psycopg2.errorcodes.lookup(error.pgcode)))
docs: Persist new record
  
          >>> s = teststore()
          >>> s.create('tstoretest', {'id': '1', 'name': 'Toto'})
          >>> s.create('tstoretest', {'id': '2', 'name': 'Tata'}, user='jane')
          >>> r = s.get('tstoretest', '2')
          >>> r[CREATOR]
          'jane'
          >>> s.create('badcls', {'id': '1', 'name': 'Toto'})
          Traceback (most recent call last):
              ...
          ValueError: Unsupported record type "badcls"
          >>> s.create('tstoretest', {'id': '1', 'name': 'Joe'})
          Traceback (most recent call last):
              ...
          KeyError: 'There is already a record for tstoretest/1'
          >>> s.create('tstoretest', {'id': '2', 'badfield': 'Joe'})
          Traceback (most recent call last):
              ...
          ValueError: Undefined field
          >>> s.create('tstoretest', {'id': '2', 'age': 'bad'})
          Traceback (most recent call last):
              ...
          ValueError: Bad record (INVALID_TEXT_REPRESENTATION)