MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / create_database

Method create_database

bbot/modules/output/mysql.py:28–55  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

26 protocol = "mysql+aiomysql"
27
28 async def create_database(self):
29 from sqlalchemy import text
30 from sqlalchemy.ext.asyncio import create_async_engine
31
32 # Create the engine for the initial connection to the server
33 initial_engine = create_async_engine(self.connection_string().rsplit("/", 1)[0])
34
35 async with initial_engine.connect() as conn:
36 # Check if the database exists
37 result = await conn.execute(text(f"SHOW DATABASES LIKE '{self.database}'"))
38 database_exists = result.scalar() is not None
39
40 # Create the database if it does not exist
41 if not database_exists:
42 # Use aiomysql directly to create the database
43 import aiomysql
44
45 raw_conn = await aiomysql.connect(
46 user=self.username,
47 password=self.password,
48 host=self.host,
49 port=self.port,
50 )
51 try:
52 async with raw_conn.cursor() as cursor:
53 await cursor.execute(f"CREATE DATABASE {self.database}")
54 finally:
55 await raw_conn.ensure_closed()

Callers

nothing calls this directly

Calls 2

textFunction · 0.85
connection_stringMethod · 0.45

Tested by

no test coverage detected