Пример #1
0
    def init_database(self):
        self.local_database = "/tmp/orator_test_database.db"

        if os.path.exists(self.local_database):
            os.remove(self.local_database)

        self.manager = DatabaseManager({
            "default": "sqlite",
            "sqlite": {
                "driver": "sqlite",
                "database": self.local_database
            },
        })

        with self.manager.transaction():
            try:
                self.manager.statement(
                    "CREATE TABLE `users` ("
                    "id INTEGER PRIMARY KEY NOT NULL, "
                    "name CHAR(50) NOT NULL, "
                    "created_at DATETIME DEFAULT CURRENT_TIMESTAMP, "
                    "updated_at DATETIME DEFAULT CURRENT_TIMESTAMP"
                    ")")
            except Exception:
                pass

        Model.set_connection_resolver(self.manager)

        self.manager.disconnect()
Пример #2
0
 def connection(self):
     return Model.get_connection_resolver().connection()
Пример #3
0
 def tearDownClass(cls):
     Model.unset_connection_resolver()
Пример #4
0
 def setUpClass(cls):
     Model.set_connection_resolver(DatabaseConnectionResolver())
Пример #5
0
 def connection(self):
     return Model.get_connection_resolver().connection()
Пример #6
0
 def tearDownClass(cls):
     Model.unset_connection_resolver()
Пример #7
0
 def setUpClass(cls):
     Model.set_connection_resolver(DatabaseConnectionResolver())