def test_get_array_fields(self): mapping = { 'db': { 'col': { 'field1': {'type': '_ARRAY'} } } } got = utils.get_array_fields(mapping, 'db', 'col', {}) self.assertEqual(got, []) doc = {'field1': [{}]} got = utils.get_array_fields(mapping, 'db', 'col', doc) self.assertEqual(got, ['field1'])
def _upsert_array_fields(self, collection, cursor, db, document, mapped_document, namespace, timestamp): for arrayField in get_array_fields(self.mappings, db, collection, document): dest = self.mappings[db][collection][arrayField]['dest'] fk = self.mappings[db][collection][arrayField]['fk'] dest_namespace = u"{0}.{1}".format(db, dest) for arrayItem in document[arrayField]: arrayItem[fk] = mapped_document[get_primary_key(self.mappings, namespace)] self._upsert(dest_namespace, arrayItem, cursor, timestamp)
def insert_document_arrays(collection, cursor, db, document, mapped_document, mappings, primary_key): for arrayField in get_array_fields(mappings, db, collection, document): dest = mappings[db][collection][arrayField]['dest'] fk = mappings[db][collection][arrayField]['fk'] linked_documents = get_nested_field_from_document(document, arrayField) for linked_document in linked_documents: linked_document[fk] = mapped_document[primary_key] sql_bulk_insert(cursor, mappings, "{0}.{1}".format(db, dest), linked_documents)
def _upsert_array_fields(self, collection, cursor, db, document, mapped_document, namespace, timestamp): for arrayField in get_array_fields(self.mappings, db, collection, document): dest = self.mappings[db][collection][arrayField]['dest'] fk = self.mappings[db][collection][arrayField]['fk'] dest_namespace = u"{0}.{1}".format(db, dest) linked_documents = get_nested_field_from_document(document, arrayField) for linked_document in linked_documents: linked_document[fk] = mapped_document[get_primary_key(self.mappings, namespace)] self._upsert(dest_namespace, linked_document, cursor, timestamp)
def insert_document_arrays(collection, query, db, document, mapped_document, mappings, primary_key): pk = mapped_document.get( primary_key, ForeignKey('{0}.{1}'.format(collection, primary_key))) for arrayField in get_array_fields(mappings, db, collection, document): dest = mappings[db][collection][arrayField]['dest'] fk = mappings[db][collection][arrayField]['fk'] linked_documents = get_nested_field_from_document(document, arrayField) for linked_document in linked_documents: linked_document[fk] = pk _sql_bulk_insert(query, mappings, "{0}.{1}".format(db, dest), linked_documents)
def _upsert_array_fields(self, collection, cursor, db, document, mapped_document, namespace, timestamp): for arrayField in get_array_fields(self.mappings, db, collection, document): dest = self.mappings[db][collection][arrayField]['dest'] fk = self.mappings[db][collection][arrayField]['fk'] dest_namespace = u"{0}.{1}".format(db, dest) linked_documents = get_nested_field_from_document( document, arrayField) for linked_document in linked_documents: linked_document[fk] = mapped_document[get_primary_key( self.mappings, namespace)] self._upsert(dest_namespace, linked_document, cursor, timestamp)