Hi all, – running debian —
hoping can get some guidance on this… I am new to Sanic, but very impressed so far ! Very easy to get it installed and configured and running… Any guidance would be VERY greatly appreciated !
So I thought I would install Sqlite (done pip install aiosqlite aiologger
) and just insert some rows , just to make sure that I can do that . The idea is - use mayim (installed via pip install sanic-ext
) - and store the sql statements in separate files. …
I tried to follow the doc, and other examples, but have few problems with my structure:
from sanic import Sanic
from sanic.log import logger
from sanic.response import text
from mayim import Mayim, SQLiteExecutor, sql
app = Sanic("erg_back")
# Initialize the database
Mayim(db_path="./user_Agent_log.db")
db = Mayim.db
# Create the table
with db as conn:
conn.execute(sql("create_table.sql"))
@app.route("/")
async def index(request):
# Get the client agent details
ip_address = request.remote_addr
user_agent = request.headers.get("User-Agent")
# Insert the client agent details into the database
with db as conn:
conn.execute(sql("insert_data.sql"), (ip_address, user_agent))
# Return the response
return text("Hello, world!")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)