'Save the object\'s metadata into the library database.
:param fields: the fields to be stored. If not specified, all fields
will be.'

def store(self, fields=None):

    if (fields is None):
        fields = self._fields
    self._check_db()
    assignments = []
    subvars = []
    for key in fields:
        if ((key != 'id') and (key in self._dirty)):
            self._dirty.remove(key)
            assignments.append((key + '=?'))
            value = self._type(key).to_sql(self[key])
            subvars.append(value)
    assignments = ','.join(assignments)
    with self._db.transaction() as tx:
        if assignments:
            query = 'UPDATE    {0}    SET    {1}    WHERE    id=?'.format(self._table, assignments)
            subvars.append(self.id)
            tx.mutate(query, subvars)
        for (key, value) in self._values_flex.items():
            if (key in self._dirty):
                self._dirty.remove(key)
                tx.mutate('INSERT    INTO    {0}    (entity_id,    key,    value)    VALUES    (?,    ?,    ?);'.format(self._flex_table), (self.id, key, value))
        for key in self._dirty:
            tx.mutate('DELETE    FROM    {0}    WHERE    entity_id=?    AND    key=?'.format(self._flex_table), (self.id, key))
    self.clear_dirty()
