fix: major bug audit + fixes — honest PLAN.md
Critical bugs fixed: - SELECT now returns actual row data (was returning empty arrays) - WHERE filter evaluation now works (was pass-through stub) - ORDER BY sorting now works (was no-op) - UPDATE execution implemented (was no-op stub) - DELETE uses WHERE filter (was key-match only) - B-Tree point reads return actual row data (was returning count only) - EXPLAIN returns plan string (was computed then discarded) - UNIQUE constraint uses B-Tree index (was memtable scan only) - DEFAULT values work for int/bool/float (was string-only) - HTTP /query returns real JSON rows with columns - Docker healthcheck uses wget (Alpine has no curl) Updated PLAN.md with honest status: - Marked what's truly done vs stub vs not implemented - Honest score: 8/10 (not 9.5/10) - Clear list of what actually works in production All 216 tests pass
This commit is contained in:
@@ -103,18 +103,31 @@ proc handleRequest(server: HttpServer, req: Request) {.async, gcsafe.} =
|
||||
newHttpHeaders([("Content-Type", "application/json")]))
|
||||
return
|
||||
|
||||
let (success, errMsg, affectedRows) = executor.executeQuery(reqCtx, astNode)
|
||||
let result = executor.executeQuery(reqCtx, astNode)
|
||||
|
||||
if success:
|
||||
if result.success:
|
||||
inc server.metrics.selectCount
|
||||
var jsonRows = newJArray()
|
||||
for row in result.rows:
|
||||
var jsonRow = newJObject()
|
||||
for col, val in row:
|
||||
jsonRow[col] = %val
|
||||
jsonRows.add(jsonRow)
|
||||
var jsonCols = newJArray()
|
||||
for c in result.columns:
|
||||
jsonCols.add(%c)
|
||||
var msg: JsonNode = nil
|
||||
if result.message.len > 0:
|
||||
msg = %result.message
|
||||
await req.respond(Http200, $ %* {
|
||||
"rows": newJArray(),
|
||||
"affectedRows": affectedRows,
|
||||
"columns": newJArray()
|
||||
"rows": jsonRows,
|
||||
"affectedRows": result.affectedRows,
|
||||
"columns": jsonCols,
|
||||
"message": if result.message.len > 0: %result.message else: newJNull()
|
||||
}, newHttpHeaders([("Content-Type", "application/json")]))
|
||||
else:
|
||||
inc server.metrics.queryErrors
|
||||
await req.respond(Http400, $jsonError(400, errMsg),
|
||||
await req.respond(Http400, $jsonError(400, result.message),
|
||||
newHttpHeaders([("Content-Type", "application/json")]))
|
||||
|
||||
of "/health":
|
||||
|
||||
@@ -70,21 +70,22 @@ proc executeQuery(db: LSMTree, ctx: ExecutionContext, query: string): (bool, Que
|
||||
if astNode.stmts.len == 0:
|
||||
return (true, QueryResult(), "")
|
||||
|
||||
let stmt = astNode.stmts[0]
|
||||
case stmt.kind
|
||||
of nkSelect, nkInsert, nkUpdate, nkDelete, nkCreateTable, nkDropTable,
|
||||
nkCreateType, nkBeginTxn, nkCommitTxn, nkRollbackTxn, nkExplainStmt:
|
||||
let (success, errMsg, affectedRows) = executor.executeQuery(ctx, astNode)
|
||||
if success:
|
||||
var qr = QueryResult(affectedRows: affectedRows, rowCount: affectedRows)
|
||||
if stmt.kind == nkSelect:
|
||||
qr.columns = @["key", "value"]
|
||||
qr.rows = @[]
|
||||
return (true, qr, "")
|
||||
else:
|
||||
return (false, QueryResult(), errMsg)
|
||||
let result = executor.executeQuery(ctx, astNode)
|
||||
if result.success:
|
||||
var qr = QueryResult(affectedRows: result.affectedRows, rowCount: result.rows.len)
|
||||
qr.columns = result.columns
|
||||
qr.rows = @[]
|
||||
for row in result.rows:
|
||||
var wireRow: seq[WireValue] = @[]
|
||||
for col in result.columns:
|
||||
if col in row:
|
||||
wireRow.add(WireValue(kind: fkString, strVal: row[col]))
|
||||
else:
|
||||
wireRow.add(WireValue(kind: fkString, strVal: ""))
|
||||
qr.rows.add(wireRow)
|
||||
return (true, qr, result.message)
|
||||
else:
|
||||
return (false, QueryResult(), "Unsupported statement type: " & $stmt.kind)
|
||||
return (false, QueryResult(), result.message)
|
||||
except Exception as e:
|
||||
return (false, QueryResult(), e.msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user