File size: 856 Bytes
c6eb873
fa35579
 
c6eb873
 
 
 
 
fa35579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import aiosqlite

# Check if running on Hugging Face with persistent storage
if os.path.exists("/data"):
    DB_NAME = "/data/agent.db"
else:
    DB_NAME = "agent.db"


async def init_db():

    async with aiosqlite.connect(DB_NAME) as db:

        await db.execute("""

            CREATE TABLE IF NOT EXISTS searches (

                id INTEGER PRIMARY KEY AUTOINCREMENT,

                query TEXT,

                result TEXT

            )

        """)

        await db.commit()


async def save_search(

    query: str,

    result: str

):

    async with aiosqlite.connect(DB_NAME) as db:

        await db.execute(
            """

            INSERT INTO searches

            (query, result)

            VALUES (?, ?)

            """,
            (query, result)
        )

        await db.commit()