コード例 #1
0
 def __init__(self):
     with shelve.open(os.path.join(db_api.DB_ROOT, "DB.db"),
                      writeback=True) as db:
         for key in db:
             db_table = DBTable(key, db[key][0], db[key][1])
             db_table.list_index = db[key][2]
             DataBase.__dict_tables__[str(key)] = db_table
コード例 #2
0
    def create_table(self, table_name: str, fields: List[DBField],
                     key_field_name: str) -> DBTable:

        if DataBase.__dict_tables__.get(table_name):
            return DataBase.__dict_tables__[table_name]
        flag = 0
        for field in fields:
            if key_field_name == field.name:
                flag = 1
        if flag == 0:
            raise ValueError
        data_table = shelve.open(os.path.join(db_api.DB_ROOT,
                                              table_name + ".db"),
                                 writeback=True)
        data_table.close()
        db_table = DBTable(table_name, fields, key_field_name)
        db_table.list_index = []
        DataBase.__dict_tables__[table_name] = db_table
        with shelve.open(os.path.join(db_api.DB_ROOT, "DB.db"),
                         writeback=True) as db:
            db[table_name] = [fields, key_field_name, list()]
        return db_table