def test_index_provider_with_extra(self): self.assertEqual([ SQLIndex(table_name='tableName', field_name='siren', type=SQLIndexTypes.HASH), SQLIndex(table_name='tableName', field_name='fieldName', type=SQLIndexTypes.B_TREE) ], list( self.provider.get_indices([ SQLField("tableName", "fieldName", SQLTypes.TEXT), SQLField("tableName", "siren", SQLTypes.TEXT), SQLField("tableName", "other", SQLTypes.TEXT) ])))
def setUp(self): self.provider = QueryProvider() self.field1 = SQLField("table", "field1", SQLTypes.BOOLEAN, comment="comment") self.field2 = SQLField("table", "field2", SQLTypes.NUMERIC) self.index = SQLIndex("table", "field1", SQLIndexTypes.HASH)
def setUp(self): print("SETUP MDB", unix_dialect.__dict__) self.field1 = SQLField("table", "field1", SQLTypes.BOOLEAN, comment="comment") self.field2 = SQLField("table", "field2", SQLTypes.NUMERIC) self.index = SQLIndex("table", "field1", SQLIndexTypes.HASH) self.table = SQLTable("table", [self.field1, self.field2], []) self.query_provider = MariaDBQueryProvider()
def mariadb_context(logger, connection): return ImporterContext( query_executor=MariaDBQueryExecutor(logger, connection, MariaDBQueryProvider()), type_converter=PatchedPostgreSireneTypeToSQLTypeConverter( SQL_TYPE_BY_SIRENE_TYPE), index_provider=SireneSQLIndexProvider( SQLIndex('StockEtablissement', "codePostalEtablissement", SQLIndexTypes.B_TREE)), )
def get_indices(self, fields: Iterable[SQLField]) -> Iterable[SQLIndex]: table_name = next((f.table_name for f in fields), None) for field in fields: if field.field_name[:5] in ( "siren", "siret"): yield SQLIndex(field.table_name, field.field_name, SQLIndexTypes.HASH) for index in self._extra_indices: if index.table_name == table_name: yield index
def test_one_indexed(self): p = SireneSchemaParser("t", [{ NAME: "siren", TYPE: "Texte", LENGTH: "10", RANK: "1", CAPTION: "c" }], self.type_provider, self.index_provider) self.assertEqual("t", p.table_name) self.assertEqual([SQLField('t', 'siren', SQLTypes.TEXT, 1, 'c', 10)], p.get_fields()) self.assertEqual([SQLIndex('t', 'siren', SQLIndexTypes.HASH)], list(p.get_indices()))
def test_long_index_name(self): index = SQLIndex('camel_case_table' * 4, 'camel_case_field' * 4, SQLIndexTypes.HASH) self.assertEqual(("cml_cs_fldcml_cs_fldcml_cs_fldcml_cs_fld_" "cml_cs_tblcml_cs_tblcml_cs_tblcml_cs_tbl_idx"), index.name)
def test_index_name(self): index = SQLIndex('camel_case_table', 'camel_case_field', SQLIndexTypes.HASH) self.assertEqual("camel_case_field_camel_case_table_idx", index.name)
def test_process(self): f = SQLIndex("CamelCaseTable", "camelCaseField", SQLIndexTypes.HASH) self.assertEqual( SQLIndex('camel_case_table', 'camel_case_field', SQLIndexTypes.HASH), f.process(to_snake))
def get_indices(self, fields: Iterable[SQLField]) -> Iterable[SQLIndex]: for field in fields: if field.starts_with("code_"): yield SQLIndex(field.table_name, field.field_name, SQLIndexTypes.HASH)
def test_one_with_index(self): sql_index = SQLIndex("t", "f", SQLIndexTypes.HASH) self.assertEqual(('DROP INDEX IF EXISTS f_t_idx', 'CREATE INDEX f_t_idx ON t USING hash(f)'), self.provider.create_index(SQLTable("t", [], []), sql_index))
def setUp(self): self.provider = SireneSQLIndexProvider( SQLIndex('tableName', 'fieldName', SQLIndexTypes.B_TREE))