web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit cce98b74d5ca219d8109e024099316b8579655ed
parent 88923fbdbcac11d4c77d0be302919ab3577eea3a
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Sun,  1 Sep 2024 14:45:39 +0000

client: update iclient db, add `trade_product_location` model

Diffstat:
Mclient/.gitignore | 1+
Mclient/src/capacitor/sql.ts | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/client/.gitignore b/client/.gitignore @@ -31,3 +31,4 @@ _tmp .vscode notes*.txt justfile +git-diff.txt diff --git a/client/src/capacitor/sql.ts b/client/src/capacitor/sql.ts @@ -606,4 +606,55 @@ export class CapacitorClientSQLite { return this.append_logs("*", [], query, ["nostr_note_update", e]); }; }; + + public async get_trade_product_location(): Promise<any[] | IISQLiteServiceMessage> { + const bind_values = undefined; + const query = "SELECT * FROM trade_product_location;"; + try { + const response = await this.select(query, bind_values); + if (typeof response === "string") { + return response; + } else if (response && Array.isArray(response.values)) { + return response.values; + } + return "*-result"; + } catch (e) { + const { error } = err_msg(e, "connect"); + return this.append_logs("*", bind_values, query, ["get_trade_product_location", error]); + }; + }; + + public async set_trade_product_location(opts: { trade_product_id: string; location_gcs_id: string }): Promise<true | IISQLiteServiceMessage> { + const bind_values = [opts.trade_product_id, opts.location_gcs_id]; + const query = "INSERT INTO trade_product_location (tb_tploc_0, tb_tploc_1) VALUES ($1, $2);"; + try { + const response = await this.execute(query, bind_values); + if (typeof response === "string") { + return response; + } else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) { + return true; + } + return "*-result"; + } catch (e) { + const { error } = err_msg(e, "connect"); + return this.append_logs("*", bind_values, query, ["set_trade_product_location", error]); + }; + }; + + public async unset_trade_product_location(opts: { trade_product_id: string; location_gcs_id: string; }): Promise<true | IISQLiteServiceMessage> { + const bind_values = [opts.trade_product_id, opts.location_gcs_id]; + const query = "DELETE FROM trade_product_location WHERE tb_tploc_0 = $1 AND tb_tploc_1 = $2;"; + try { + const response = await this.execute(query, bind_values); + if (typeof response === "string") { + return response; + } else if (typeof response.changes?.changes === "number" && response.changes.changes > 0) { + return true; + } + return "*-result"; + } catch (e) { + const { error } = err_msg(e, "connect"); + return this.append_logs("*", bind_values, query, ["unset_trade_product_location", error]); + }; + }; }; \ No newline at end of file