This commit is contained in:
Rizky 2024-06-12 22:26:07 +07:00
parent 073a8cc557
commit 722b8ccea8
1 changed files with 46 additions and 28 deletions

View File

@ -2,6 +2,12 @@ import hash_sum from "hash-sum";
import pako from "pako"; import pako from "pako";
import { fetchViaProxy } from "../proxy"; import { fetchViaProxy } from "../proxy";
const schema_promise = {
tables: {} as Record<string, any>,
columns: {} as Record<string, any>,
rels: {} as Record<string, any>,
}
export const dbProxy = (dburl: string) => { export const dbProxy = (dburl: string) => {
const name = ""; const name = "";
return new Proxy( return new Proxy(
@ -37,37 +43,49 @@ export const dbProxy = (dburl: string) => {
if (table === "_schema") { if (table === "_schema") {
return { return {
tables: async () => { tables: async () => {
return fetchSendDb( if (!schema_promise.tables[dburl]) {
{ schema_promise.tables[dburl] = fetchSendDb(
name, {
action: "schema_tables", name,
table: "", action: "schema_tables",
params: [], table: "",
}, params: [],
dburl },
); dburl
);
}
return await schema_promise.tables[dburl]
}, },
columns: async (table: string) => { columns: async (table: string) => {
return fetchSendDb( if (!schema_promise.columns[dburl + '_' + table]) {
{ schema_promise.columns[dburl + '_' + table] = fetchSendDb(
name, {
action: "schema_columns", name,
table, action: "schema_columns",
params: [], table,
}, params: [],
dburl },
); dburl
);
}
return await schema_promise.columns[dburl + '_' + table]
}, },
rels: async (table: string) => { rels: async (table: string) => {
return fetchSendDb( if (!schema_promise.rels[dburl + '_' + table]) {
{ schema_promise.rels[dburl + '_' + table] = fetchSendDb(
name, {
action: "schema_rels", name,
table, action: "schema_rels",
params: [], table,
}, params: [],
dburl },
); dburl
);
}
return await schema_promise.rels[dburl + '_' + table]
}, },
}; };
} }
@ -156,5 +174,5 @@ export const fetchSendDb = async (params: any, dburl: string) => {
} }
return await cached.promise; return await cached.promise;
} catch (e) {} } catch (e) { }
}; };