def insert(self, data_list, return_id=False): opts = self.query.get_meta() unindexed_fields = get_model_indexes(self.query.model)['unindexed'] unindexed_cols = [opts.get_field(name).column for name in unindexed_fields] entity_list = [] for data in data_list: properties = {} kwds = {'unindexed_properties': unindexed_cols} for column, value in data.items(): # The value will already be a db.Key, but the Entity # constructor takes a name or id of the key, and will # automatically create a new key if neither is given. if column == opts.pk.column: if value is not None: kwds['id'] = value.id() kwds['name'] = value.name() # GAE does not store empty lists (and even does not allow # passing empty lists to Entity.update) so skip them. elif isinstance(value, (tuple, list)) and not len(value): continue # Use column names as property names. else: properties[column] = value entity = Entity(opts.db_table, **kwds) entity.update(properties) entity_list.append(entity) keys = Put(entity_list) return keys[0] if isinstance(keys, list) else keys
def insert(self, data, return_id=False): gae_data = {} opts = self.query.get_meta() indexes = get_indexes().get(self.query.model, {}) unindexed_fields = indexes.get('unindexed', ()) unindexed_cols = [ opts.get_field(name).column for name in unindexed_fields ] kwds = {'unindexed_properties': unindexed_cols} for column, value in data.items(): if column == opts.pk.column: if isinstance(value, basestring): kwds['name'] = value else: kwds['id'] = value elif isinstance(value, (tuple, list)) and not len(value): # gae does not store emty lists (and even does not allow passing empty # lists to Entity.update) so skip them continue else: gae_data[column] = value entity = Entity(self.query.get_meta().db_table, **kwds) entity.update(gae_data) key = Put(entity) return key.id_or_name()
def insert(self, data_list, return_id=False): opts = self.query.get_meta() unindexed_fields = get_model_indexes(self.query.model)['unindexed'] unindexed_cols = [ opts.get_field(name).column for name in unindexed_fields ] entity_list = [] for data in data_list: properties = {} kwds = {'unindexed_properties': unindexed_cols} for column, value in data.items(): # The value will already be a db.Key, but the Entity # constructor takes a name or id of the key, and will # automatically create a new key if neither is given. if column == opts.pk.column: if value is not None: kwds['id'] = value.id() kwds['name'] = value.name() # GAE does not store empty lists (and even does not allow # passing empty lists to Entity.update) so skip them. elif isinstance(value, (tuple, list)) and not len(value): continue # Use column names as property names. else: properties[column] = value entity = Entity(opts.db_table, **kwds) entity.update(properties) entity_list.append(entity) keys = Put(entity_list) return keys[0] if isinstance(keys, list) else keys
def insert(self, data, return_id=False): gae_data = {} opts = self.query.get_meta() indexes = get_indexes().get(self.query.model, {}) unindexed_fields = indexes.get('unindexed', ()) unindexed_cols = [opts.get_field(name).column for name in unindexed_fields] kwds = {'unindexed_properties': unindexed_cols} for column, value in data.items(): if column == opts.pk.column: if isinstance(value, basestring): kwds['name'] = value else: kwds['id'] = value elif isinstance(value, (tuple, list)) and not len(value): # gae does not store emty lists (and even does not allow passing empty # lists to Entity.update) so skip them continue else: gae_data[column] = value entity = Entity(self.query.get_meta().db_table, **kwds) entity.update(gae_data) key = Put(entity) return key.id_or_name()
def insert(self, data, return_id=False): opts = self.query.get_meta() unindexed_fields = get_model_indexes(self.query.model)['unindexed'] kwds = {'unindexed_properties': []} properties = {} for field, value in data.iteritems(): # The value will already be a db.Key, but the Entity # constructor takes a name or id of the key, and will # automatically create a new key if neither is given. if field.primary_key: if value is not None: kwds['id'] = value.id() kwds['name'] = value.name() # GAE does not store empty lists (and even does not allow # passing empty lists to Entity.update) so skip them. elif isinstance(value, (tuple, list)) and not len(value): continue # Use column names as property names. else: properties[field.column] = value if field in unindexed_fields: kwds['unindexed_properties'].append(field.column) entity = Entity(opts.db_table, **kwds) entity.update(properties) return Put(entity)
def insert(self, data, return_id=False): kwds = {} gae_data = {} for column, value in data.items(): if column == self.query.get_meta().pk.column: if isinstance(value, basestring): kwds['name'] = value else: kwds['id'] = value elif isinstance(value, (tuple, list)) and not len(value): # gae does not store emty lists (and even does not allow passing empty # lists to Entity.update) so skip them continue else: gae_data[column] = value entity = Entity(self.query.get_meta().db_table, **kwds) entity.update(gae_data) key = Put(entity) return key.id_or_name()
def insert(self, data, return_id=False): gae_data = {} opts = self.query.get_meta() unindexed_fields = get_model_indexes(self.query.model)['unindexed'] unindexed_cols = [opts.get_field(name).column for name in unindexed_fields] kwds = {'unindexed_properties': unindexed_cols} for column, value in data.items(): if column == opts.pk.column: if isinstance(value, GAEKey): if value.parent_key() and value.parent_key().has_real_key(): kwds['parent'] = value.parent_key().real_key() if isinstance(value.id_or_name(), basestring): kwds['name'] = value.id_or_name() elif value.id_or_name() is not None: kwds['id'] = value.id_or_name() elif isinstance(value, Key): kwds['parent'] = value.parent() if value.name(): kwds['name'] = value.name() elif value.id(): kwds['id'] = value.id() elif isinstance(value, basestring): kwds['name'] = value else: kwds['id'] = value elif isinstance(value, (tuple, list)) and not len(value): # gae does not store empty lists (and even does not allow passing empty # lists to Entity.update) so skip them continue else: gae_data[column] = value entity = Entity(opts.db_table, **kwds) entity.update(gae_data) key = Put(entity) if not isinstance(opts.pk, GAEKeyField): key = key.id_or_name() return key