예제 #1
0
def test_get_indices_description_from_object():
    database = "test.db"
    create_database(database)
    config = {'sqlite3': {'driver': 'sqlite', 'database': database}}
    db = DatabaseManager(config)
    result = _get_indices_description_from_oject(db.get_schema_manager(),
                                                 'tasks')
    assert result == {
        'primary': {
            'is_unique?': True,
            'is_primary?': True,
            'columns': ['id']
        }
    }
    drop_database(database)
예제 #2
0
파일: models.py 프로젝트: rramaa/pynnotate
def get_model_path_info_map(model_path, config_path, **kwargs):
    db = DatabaseManager(get_config_file(config_path, **kwargs))
    schema_manager = db.get_schema_manager()
    file_info_map = OrderedDict()
    for model_path in models(model_path):
        _, model_file = os.path.split(model_path)
        table_name = table_name_from_filename(model_file)
        columns_description = _get_column_description_from_object(
            schema_manager, table_name)
        if not columns_description:
            continue
        indices_description = _get_indices_description_from_oject(
            schema_manager, table_name)
        file_info_map[model_path] = OrderedDict([
            ('columns', columns_description),
            ('indices', indices_description),
            ('table_name', table_name)
        ])
    return file_info_map
예제 #3
0
    def handle(self):

        file = Path("config.yaml")
        if not file.is_file():
            return self.warning("Unable to find a valid config file!")

        config = yaml.load(file.read_text(), Loader=yaml.FullLoader)

        DB = DatabaseManager(config=config.get("databases"))

        if self.option("connection") == "default":
            conn = DB.get_schema_manager().list_table_columns(
                self.argument("table"))
        else:
            conn = (DB.connection(self.option(
                "connection")).get_schema_manager().list_table_columns(
                    self.argument("table")))

        docstring = f'"""Model Docstring\n\n{self.columns(conn)}\n"""'

        print(docstring)
예제 #4
0
def test_get_column_description_from_object():
    database = "test.db"
    create_database(database)
    config = {'sqlite3': {'driver': 'sqlite', 'database': database}}
    db = DatabaseManager(config)
    result = _get_column_description_from_object(db.get_schema_manager(),
                                                 'tasks')
    assert result == {
        'id': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 1,
            'precision': 10,
            'name': 'id',
            'extra': {},
            'scale': 0,
            'type': 'integer',
            'notnull': False,
            'fixed': False
        },
        'status_id': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'status_id',
            'extra': {},
            'scale': 0,
            'type': 'integer',
            'notnull': True,
            'fixed': False
        },
        'project_id': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'project_id',
            'extra': {},
            'scale': 0,
            'type': 'integer',
            'notnull': True,
            'fixed': False
        },
        'name': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'name',
            'extra': {},
            'scale': 0,
            'type': 'text',
            'notnull': True,
            'fixed': False
        },
        'end_date': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'end_date',
            'extra': {},
            'scale': 0,
            'type': 'text',
            'notnull': True,
            'fixed': False
        },
        'priority': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'priority',
            'extra': {},
            'scale': 0,
            'type': 'integer',
            'notnull': False,
            'fixed': False
        },
        'begin_date': {
            'unsigned': False,
            'autoincrement': False,
            'length': None,
            'default': None,
            'pk': 0,
            'precision': 10,
            'name': 'begin_date',
            'extra': {},
            'scale': 0,
            'type': 'text',
            'notnull': True,
            'fixed': False
        }
    }
    drop_database(database)