|
31 | 31 | { value: "16384", name: "16384" },
|
32 | 32 | { value: "32768", name: "32768" },
|
33 | 33 | ];
|
34 |
| - let sqlQuery = `SELECT * FROM tcga_table LIMIT 20';`; |
| 34 | + let sqlQuery = `SELECT * FROM tcga_table LIMIT 20;`; |
| 35 | + let activeTable = ""; |
| 36 | + let selectedColumn = ""; |
| 37 | + let searchValue = ""; |
35 | 38 | // let dbUrl = "https://nishad.github.io/sql.js-httpvfs-playground/db/imdb-titles-100000_1024_indexed.db";
|
36 | 39 | // let dbUrl =
|
37 | 40 | // "https://cnag-biomedical-informatics.github.io/sql.js-httpvfs-playground/db/tcga.db";
|
|
114 | 117 | );
|
115 | 118 | if (tablesData.result.length) {
|
116 | 119 | const table = tablesData.result[0].name;
|
| 120 | + activeTable = table; |
117 | 121 | console.log("Selected table: ", table);
|
118 | 122 |
|
119 | 123 | // Override if this table has a special filter
|
120 | 124 | if (Object.keys(exampleQueries).includes(table)) {
|
121 | 125 | console.log("Using example query for table:", table);
|
122 | 126 | sqlQuery = `SELECT * FROM "${table}" WHERE ${exampleQueries[table]};`;
|
| 127 | + } else { |
| 128 | + sqlQuery = `SELECT * FROM "${table}" LIMIT 20;`; |
123 | 129 | }
|
124 | 130 |
|
125 | 131 | await runQuery(dbUrl, sqlQuery);
|
|
167 | 173 | let totalBytes;
|
168 | 174 | let totalRequests;
|
169 | 175 |
|
| 176 | + function runBuilderQuery() { |
| 177 | + if (!activeTable || !selectedColumn || !searchValue) return; |
| 178 | + const escaped = searchValue.replace(/'/g, "''"); |
| 179 | + sqlQuery = `SELECT * FROM "${activeTable}" WHERE "${selectedColumn}" LIKE '%${escaped}%' LIMIT 20;`; |
| 180 | + runQuery(dbUrl, sqlQuery); |
| 181 | + } |
| 182 | +
|
170 | 183 | async function runQuery(url = dbUrl, query = sqlQuery) {
|
171 | 184 | result = null;
|
172 | 185 | querying = true;
|
|
252 | 265 | <Select class="mt-2" items={pageSizes} bind:value={pageSize} />
|
253 | 266 | </Label>
|
254 | 267 | </div> -->
|
255 |
| - <div class="p-6"> |
256 |
| - <Label class="space-y-2"> |
257 |
| - <span>Edit SQL Query</span> |
258 |
| - <CodeJar bind:value={sqlQuery} syntax="sql" {highlight} /> |
259 |
| - </Label> |
260 |
| - </div> |
261 |
| - <div class="p-6"> |
262 |
| - <Button on:click={() => runQuery()}> |
263 |
| - {#if querying} |
264 |
| - <Spinner class="mr-3" size="4" color="white" /> Querying ... |
265 |
| - {:else} |
266 |
| - Run Query |
267 |
| - {/if} |
268 |
| - </Button> |
| 268 | + <div class="p-6 space-y-4"> |
| 269 | + <div class="space-y-2"> |
| 270 | + <Label class="space-y-2"> |
| 271 | + <span>Column</span> |
| 272 | + <input list="columns" class="border rounded w-full p-2" bind:value={selectedColumn} /> |
| 273 | + <datalist id="columns"> |
| 274 | + {#each ptInstructs as col} |
| 275 | + <option value={col.key} /> |
| 276 | + {/each} |
| 277 | + </datalist> |
| 278 | + </Label> |
| 279 | + <Label class="space-y-2"> |
| 280 | + <span>Search value</span> |
| 281 | + <Input type="text" bind:value={searchValue} /> |
| 282 | + </Label> |
| 283 | + <Button size="sm" on:click={runBuilderQuery}>Search</Button> |
| 284 | + </div> |
| 285 | + <details> |
| 286 | + <summary class="cursor-pointer underline">Expand to show and modify the SQL query</summary> |
| 287 | + <div class="mt-4"> |
| 288 | + <Label class="space-y-2"> |
| 289 | + <span>Edit SQL Query</span> |
| 290 | + <CodeJar bind:value={sqlQuery} syntax="sql" {highlight} /> |
| 291 | + </Label> |
| 292 | + <div class="mt-2"> |
| 293 | + <Button on:click={() => runQuery()}> |
| 294 | + {#if querying} |
| 295 | + <Spinner class="mr-3" size="4" color="white" /> Querying ... |
| 296 | + {:else} |
| 297 | + Run Query |
| 298 | + {/if} |
| 299 | + </Button> |
| 300 | + </div> |
| 301 | + </div> |
| 302 | + </details> |
269 | 303 | </div>
|
270 | 304 |
|
271 | 305 | {#if result}
|
|
0 commit comments