Commit 7b6edba2 authored by Chunchi Che's avatar Chunchi Che

update sqlite middleware

parent c37bc844
Pipeline #19734 passed with stages
in 5 minutes and 38 seconds
...@@ -5,7 +5,7 @@ export interface CardMeta { ...@@ -5,7 +5,7 @@ export interface CardMeta {
data: { data: {
ot?: number; ot?: number;
setcode?: number; setcode?: number;
type_?: number; type?: number;
atk?: number; atk?: number;
def?: number; def?: number;
level?: number; level?: number;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* */ * */
import initSqlJs, { Database } from "sql.js"; import initSqlJs, { Database } from "sql.js";
import { CardMeta } from "../api/cards";
export enum sqliteCmd { export enum sqliteCmd {
// 初始化 // 初始化
...@@ -44,8 +45,14 @@ export default async function (action: sqliteAction) { ...@@ -44,8 +45,14 @@ export default async function (action: sqliteAction) {
break; break;
} }
case sqliteCmd.SELECT: { case sqliteCmd.SELECT: {
if (YGODB) { if (YGODB && action.payload) {
// TDOO const code = action.payload;
const dataStmt = YGODB.prepare("SELECT * from datas WHERE ID = $id");
const dataResult = dataStmt.getAsObject({ $id: code });
const textStmt = YGODB.prepare("SELECT * from texts WHERE ID = $id");
const textResult = textStmt.getAsObject({ $id: code });
return constructCardMeta(code, dataResult, textResult);
} else { } else {
console.warn("ygo db not init!"); console.warn("ygo db not init!");
} }
...@@ -59,3 +66,15 @@ export default async function (action: sqliteAction) { ...@@ -59,3 +66,15 @@ export default async function (action: sqliteAction) {
} }
} }
} }
function constructCardMeta(
id: number,
data: initSqlJs.ParamsObject,
text: initSqlJs.ParamsObject
): CardMeta {
return {
id,
data,
text,
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment