Commit inicial - upload de todos os arquivos da pasta

This commit is contained in:
2025-08-11 17:06:12 -03:00
commit 1c7f160a68
13 changed files with 2040 additions and 0 deletions

29
main.py Normal file
View File

@@ -0,0 +1,29 @@
import sqlite3
import threading
from fastapi import FastAPI
class SQLiteManager:
def __init__(self, db_path: str):
self.db_path = db_path
self.connection = sqlite3.connect(db_path, check_same_thread=False)
self.connection.row_factory = sqlite3.Row
self.connection.execute("PRAGMA journal_mode=WAL")
self.lock = threading.RLock()
def query(self, sql: str, params: tuple = ()):
with self.lock:
cursor = self.connection.cursor()
cursor.execute(sql, params)
return cursor.fetchone()
db_manager = SQLiteManager("db.sqlite3")
app = FastAPI()
@app.get("/cnes/{cnes_code}")
async def get_cnes(cnes_code: str):
result = db_manager.query(
"SELECT * FROM cnes_estabelecimentos WHERE CO_CNES = ? LIMIT 1",
(cnes_code,)
)
return dict(result) if result else None