Beispiel #1
0
 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)
                          ])))
Beispiel #2
0
 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)
Beispiel #3
0
 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()
Beispiel #4
0
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)),
    )
Beispiel #5
0
    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
Beispiel #6
0
 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()))
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #11
0
 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))
Beispiel #12
0
 def setUp(self):
     self.provider = SireneSQLIndexProvider(
         SQLIndex('tableName', 'fieldName', SQLIndexTypes.B_TREE))