AK-21/Graphite-Industrial-Intelligence
0
1"use strict";2var __defProp = Object.defineProperty;3var __getOwnPropDesc = Object.getOwnPropertyDescriptor;4var __getOwnPropNames = Object.getOwnPropertyNames;5var __hasOwnProp = Object.prototype.hasOwnProperty;6var __export = (target, all) => {7 for (var name in all)8 __defProp(target, name, { get: all[name], enumerable: true });9};10var __copyProps = (to, from, except, desc) => {11 if (from && typeof from === "object" || typeof from === "function") {12 for (let key of __getOwnPropNames(from))13 if (!__hasOwnProp.call(to, key) && key !== except)14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });15 }16 return to;17};18var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);19var query_exports = {};20__export(query_exports, {21 useLiveQuery: () => useLiveQuery22});23module.exports = __toCommonJS(query_exports);24var import_expo_sqlite = require("expo-sqlite");25var import_react = require("react");26var import_entity = require("../entity.cjs");27var import_sql = require("../sql/sql.cjs");28var import_sqlite_core = require("../sqlite-core/index.cjs");29var import_query = require("../sqlite-core/query-builders/query.cjs");30var import_subquery = require("../subquery.cjs");31const useLiveQuery = (query, deps = []) => {32 const [data, setData] = (0, import_react.useState)(33 (0, import_entity.is)(query, import_query.SQLiteRelationalQuery) && query.mode === "first" ? void 0 : []34 );35 const [error, setError] = (0, import_react.useState)();36 const [updatedAt, setUpdatedAt] = (0, import_react.useState)();37 (0, import_react.useEffect)(() => {38 const entity = (0, import_entity.is)(query, import_query.SQLiteRelationalQuery) ? query.table : query.config.table;39 if ((0, import_entity.is)(entity, import_subquery.Subquery) || (0, import_entity.is)(entity, import_sql.SQL)) {40 setError(new Error("Selecting from subqueries and SQL are not supported in useLiveQuery"));41 return;42 }43 let listener;44 const handleData = (data2) => {45 setData(data2);46 setUpdatedAt(/* @__PURE__ */ new Date());47 };48 query.then(handleData).catch(setError);49 if ((0, import_entity.is)(entity, import_sqlite_core.SQLiteTable) || (0, import_entity.is)(entity, import_sqlite_core.SQLiteView)) {50 const config = (0, import_entity.is)(entity, import_sqlite_core.SQLiteTable) ? (0, import_sqlite_core.getTableConfig)(entity) : (0, import_sqlite_core.getViewConfig)(entity);51 listener = (0, import_expo_sqlite.addDatabaseChangeListener)(({ tableName }) => {52 if (config.name === tableName) {53 query.then(handleData).catch(setError);54 }55 });56 }57 return () => {58 listener?.remove();59 };60 }, deps);61 return {62 data,63 error,64 updatedAt65 };66};67// Annotate the CommonJS export names for ESM import in node:680 && (module.exports = {69 useLiveQuery70});71//# sourceMappingURL=query.cjs.map