improve query necessary
This commit is contained in:
16
src/index.ts
16
src/index.ts
@@ -29,19 +29,9 @@ app.get("/api/v1/ext/query_all", (c) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get("/api/v1/ext/query_necessary", (c) => {
|
app.get("/api/v1/ext/query_necessary", (c) => {
|
||||||
// Python code fetches all columns then filters via Pydantic model.
|
const query = db.query("SELECT ID, SAFE FROM extensions");
|
||||||
// We can select just what we need or select all and map.
|
const extensions = query.all() as ExtensionNecessary[];
|
||||||
// Let's select all to be consistent with the 'all()' behavior if logic changes,
|
return c.json(extensions);
|
||||||
// but map to the response shape to respect the 'response_model'.
|
|
||||||
const query = db.query("SELECT * FROM extensions");
|
|
||||||
const extensions = query.all() as ExtensionInDB[];
|
|
||||||
|
|
||||||
const necessary: ExtensionNecessary[] = extensions.map((ext) => ({
|
|
||||||
ID: ext.ID,
|
|
||||||
SAFE: ext.SAFE,
|
|
||||||
}));
|
|
||||||
|
|
||||||
return c.json(necessary);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/api/v1/ext/add_one", async (c) => {
|
app.post("/api/v1/ext/add_one", async (c) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user